wip
This commit is contained in:
parent
d67b7a7c01
commit
4da70e21b3
3 changed files with 59 additions and 13 deletions
|
|
@ -2,7 +2,7 @@
|
|||
use crate::board::{Board, CheckerMove};
|
||||
use crate::dice::Dice;
|
||||
use crate::game_rules_moves::MoveRules;
|
||||
use crate::game_rules_points::{PointsRules, PossibleJans};
|
||||
use crate::game_rules_points::{PointsRules, PossibleJans, PossibleJansMethods};
|
||||
use crate::player::{Color, Player, PlayerId};
|
||||
use log::{debug, error};
|
||||
|
||||
|
|
@ -146,19 +146,31 @@ impl GameState {
|
|||
pub fn mirror(&self) -> GameState {
|
||||
let mirrored_active_player = if self.active_player_id == 1 { 0 } else { 1 };
|
||||
let mut mirrored_players = HashMap::new();
|
||||
mirrored_players.insert(1, self.players.get(&2).unwrap().mirror());
|
||||
mirrored_players.insert(2, self.players.get(&1).unwrap().mirror());
|
||||
if let Some(p2) = self.players.get(&2) {
|
||||
mirrored_players.insert(1, p2.mirror());
|
||||
}
|
||||
if let Some(p1) = self.players.get(&1) {
|
||||
mirrored_players.insert(2, p1.mirror());
|
||||
}
|
||||
let mirrored_history = self
|
||||
.history
|
||||
.clone()
|
||||
.iter()
|
||||
.map(|evt| evt.get_mirror())
|
||||
.collect();
|
||||
|
||||
let (move1, move2) = self.dice_moves;
|
||||
GameState {
|
||||
stage: self.stage,
|
||||
turn_stage: self.turn_stage,
|
||||
board: self.board.mirror(),
|
||||
active_player_id: mirrored_active_player,
|
||||
players: mirrored_players,
|
||||
history: Vec::new(),
|
||||
history: mirrored_history,
|
||||
dice: self.dice,
|
||||
dice_points: self.dice_points,
|
||||
dice_moves: (CheckerMove::default(), CheckerMove::default()),
|
||||
dice_jans: PossibleJans::default(),
|
||||
dice_moves: (move1.mirror(), move2.mirror()),
|
||||
dice_jans: self.dice_jans.mirror(),
|
||||
roll_first: self.roll_first,
|
||||
schools_enabled: self.schools_enabled,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,10 +69,26 @@ pub type PossibleJans = HashMap<Jan, Vec<(CheckerMove, CheckerMove)>>;
|
|||
pub trait PossibleJansMethods {
|
||||
fn push(&mut self, jan: Jan, cmoves: (CheckerMove, CheckerMove));
|
||||
fn merge(&mut self, other: Self);
|
||||
fn mirror(&self) -> Self;
|
||||
// fn get_points(&self) -> u8;
|
||||
}
|
||||
|
||||
impl PossibleJansMethods for PossibleJans {
|
||||
fn mirror(&self) -> Self {
|
||||
self.clone()
|
||||
.into_iter()
|
||||
.map(|(jan, moves)| {
|
||||
(
|
||||
jan,
|
||||
moves
|
||||
.into_iter()
|
||||
.map(|(m1, m2)| (m1.mirror(), m2.mirror()))
|
||||
.collect(),
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn push(&mut self, jan: Jan, cmoves: (CheckerMove, CheckerMove)) {
|
||||
if let Some(ways) = self.get_mut(&jan) {
|
||||
if !ways.contains(&cmoves) {
|
||||
|
|
|
|||
|
|
@ -50,9 +50,13 @@ impl TricTrac {
|
|||
self.game_state.active_player_id - 1
|
||||
}
|
||||
|
||||
fn get_legal_actions(&self, player_id: u64) -> Vec<usize> {
|
||||
if player_id == self.current_player_idx() {
|
||||
get_valid_action_indices(&self.game_state)
|
||||
fn get_legal_actions(&self, player_idx: u64) -> Vec<usize> {
|
||||
if player_idx == self.current_player_idx() {
|
||||
if player_idx == 0 {
|
||||
get_valid_action_indices(&self.game_state)
|
||||
} else {
|
||||
get_valid_action_indices(&self.game_state.mirror())
|
||||
}
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
|
|
@ -84,6 +88,12 @@ impl TricTrac {
|
|||
TrictracAction::from_action_index(action_idx).and_then(|a| a.to_event(&self.game_state))
|
||||
{
|
||||
println!("get event {:?}", event);
|
||||
|
||||
let event = if self.game_state.active_player_id == 2 {
|
||||
event.get_mirror()
|
||||
} else {
|
||||
event
|
||||
};
|
||||
if self.game_state.validate(&event) {
|
||||
println!("valid event");
|
||||
self.game_state.consume(&event);
|
||||
|
|
@ -113,12 +123,20 @@ impl TricTrac {
|
|||
[self.get_score(1), self.get_score(2)]
|
||||
}
|
||||
|
||||
fn get_tensor(&self, player: PlayerId) -> Vec<i8> {
|
||||
self.game_state.to_vec()
|
||||
fn get_tensor(&self, player_idx: u64) -> Vec<i8> {
|
||||
if player_idx == 0 {
|
||||
self.game_state.to_vec()
|
||||
} else {
|
||||
self.game_state.mirror().to_vec()
|
||||
}
|
||||
}
|
||||
|
||||
fn get_observation_string(&self, player: PlayerId) -> String {
|
||||
self.__str__()
|
||||
fn get_observation_string(&self, player_idx: u64) -> String {
|
||||
if player_idx == 0 {
|
||||
format!("{}", self.game_state)
|
||||
} else {
|
||||
format!("{}", self.game_state.mirror())
|
||||
}
|
||||
}
|
||||
|
||||
/// Afficher l'état du jeu (pour le débogage)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue