debug
This commit is contained in:
parent
d6df7af4fe
commit
223777346a
4 changed files with 21 additions and 8 deletions
|
|
@ -144,7 +144,7 @@ impl GameState {
|
|||
}
|
||||
|
||||
pub fn mirror(&self) -> GameState {
|
||||
// let mirrored_active_player = if self.active_player_id == 1 { 2 } else { 1 };
|
||||
let mirrored_active_player = if self.active_player_id == 1 { 2 } else { 1 };
|
||||
let mut mirrored_players = HashMap::new();
|
||||
if let Some(p2) = self.players.get(&2) {
|
||||
mirrored_players.insert(1, p2.mirror());
|
||||
|
|
@ -164,7 +164,8 @@ impl GameState {
|
|||
stage: self.stage,
|
||||
turn_stage: self.turn_stage,
|
||||
board: self.board.mirror(),
|
||||
active_player_id: self.active_player_id,
|
||||
active_player_id: mirrored_active_player,
|
||||
//active_player_id: self.active_player_id,
|
||||
players: mirrored_players,
|
||||
history: mirrored_history,
|
||||
dice: self.dice,
|
||||
|
|
@ -571,6 +572,7 @@ impl GameState {
|
|||
*moves
|
||||
};
|
||||
if !rules.moves_follow_rules(&moves) {
|
||||
println!(">>> rules not followed ");
|
||||
error!("rules not followed ");
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ impl MoveRules {
|
|||
|
||||
fn get_board_from_color(color: &Color, board: &Board) -> Board {
|
||||
if *color == Color::Black {
|
||||
println!("get_board_from_color -> mirror of {}", board);
|
||||
board.mirror()
|
||||
} else {
|
||||
board.clone()
|
||||
|
|
@ -74,6 +75,7 @@ impl MoveRules {
|
|||
moves: &(CheckerMove, CheckerMove),
|
||||
// ignored_rules: Vec<TricTracRule>,
|
||||
) -> bool {
|
||||
println!("in moves_follow_rules");
|
||||
// Check moves possibles on the board
|
||||
// Check moves conforms to the dice
|
||||
// Check move is allowed by the rules (to desactivate when playing with schools)
|
||||
|
|
@ -81,7 +83,8 @@ impl MoveRules {
|
|||
let is_allowed = self.moves_allowed(moves);
|
||||
// let is_allowed = self.moves_allowed(moves, ignored_rules);
|
||||
if is_allowed.is_err() {
|
||||
info!("Move not allowed : {:?}", is_allowed.unwrap_err());
|
||||
println!("Move not allowed : {:?}", is_allowed.unwrap_err());
|
||||
// info!("Move not allowed : {:?}", is_allowed.unwrap_err());
|
||||
false
|
||||
} else {
|
||||
true
|
||||
|
|
@ -99,6 +102,7 @@ impl MoveRules {
|
|||
if let Ok((field_count, Some(field_color))) = self.board.get_field_checkers(move0_from)
|
||||
{
|
||||
if color != field_color || field_count < 2 {
|
||||
println!("Move not physically possible 1");
|
||||
info!("Move not physically possible");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -110,6 +114,7 @@ impl MoveRules {
|
|||
if !self.board.passage_possible(color, &moves.0)
|
||||
|| !self.board.move_possible(color, &chained_move)
|
||||
{
|
||||
println!("Tout d'une : Move not physically possible");
|
||||
info!("Tout d'une : Move not physically possible");
|
||||
return false;
|
||||
}
|
||||
|
|
@ -117,6 +122,11 @@ impl MoveRules {
|
|||
|| !self.board.move_possible(color, &moves.1)
|
||||
{
|
||||
// Move is not physically possible
|
||||
println!("Move not physically possible 2");
|
||||
println!(
|
||||
"board: {}, color: {:?} move: {:?}",
|
||||
self.board, color, moves
|
||||
);
|
||||
info!("Move not physically possible");
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -58,8 +58,8 @@ impl TricTrac {
|
|||
get_valid_action_indices(&self.game_state)
|
||||
} else {
|
||||
let mirror = self.game_state.mirror();
|
||||
println!("get validd actions for mirror");
|
||||
println!("{}", mirror);
|
||||
println!("get valid actions for mirror");
|
||||
println!("/////{}", mirror);
|
||||
get_valid_action_indices(&mirror)
|
||||
}
|
||||
} else {
|
||||
|
|
@ -92,14 +92,13 @@ impl TricTrac {
|
|||
if let Some(event) =
|
||||
TrictracAction::from_action_index(action_idx).and_then(|a| a.to_event(&self.game_state))
|
||||
{
|
||||
println!(">get event {:?}", event);
|
||||
|
||||
println!("apply action on {:?} ", event);
|
||||
let event = if self.game_state.active_player_id == 2 {
|
||||
event.get_mirror(true)
|
||||
} else {
|
||||
event
|
||||
};
|
||||
println!("validating event {:?}", event);
|
||||
println!("validating event {:?} on state {}", event, self.game_state);
|
||||
if self.game_state.validate(&event) {
|
||||
println!("valid event");
|
||||
self.game_state.consume(&event);
|
||||
|
|
|
|||
|
|
@ -196,6 +196,7 @@ pub fn get_valid_actions(game_state: &GameState) -> Vec<TrictracAction> {
|
|||
let player_color = game_state.player_color_by_id(&active_player_id);
|
||||
|
||||
if let Some(color) = player_color {
|
||||
println!("in get_valid_actions, color = {:?}", color);
|
||||
match game_state.turn_stage {
|
||||
TurnStage::RollDice => {
|
||||
valid_actions.push(TrictracAction::Roll);
|
||||
|
|
@ -229,6 +230,7 @@ pub fn get_valid_actions(game_state: &GameState) -> Vec<TrictracAction> {
|
|||
}
|
||||
|
||||
for (move1, move2) in possible_moves {
|
||||
println!("adding moves {:?} {:?}", move1, move2);
|
||||
valid_actions.push(checker_moves_to_trictrac_action(
|
||||
&move1, &move2, &color, game_state,
|
||||
));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue