fix: training : exit board moves
This commit is contained in:
parent
d53b65c947
commit
688d6174e3
3 changed files with 11 additions and 15 deletions
|
|
@ -63,7 +63,6 @@ impl MoveRules {
|
||||||
|
|
||||||
fn get_board_from_color(color: &Color, board: &Board) -> Board {
|
fn get_board_from_color(color: &Color, board: &Board) -> Board {
|
||||||
if *color == Color::Black {
|
if *color == Color::Black {
|
||||||
println!("get_board_from_color -> mirror of {}", board);
|
|
||||||
board.mirror()
|
board.mirror()
|
||||||
} else {
|
} else {
|
||||||
board.clone()
|
board.clone()
|
||||||
|
|
@ -75,7 +74,6 @@ impl MoveRules {
|
||||||
moves: &(CheckerMove, CheckerMove),
|
moves: &(CheckerMove, CheckerMove),
|
||||||
// ignored_rules: Vec<TricTracRule>,
|
// ignored_rules: Vec<TricTracRule>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
println!("in moves_follow_rules");
|
|
||||||
// Check moves possibles on the board
|
// Check moves possibles on the board
|
||||||
// Check moves conforms to the dice
|
// Check moves conforms to the dice
|
||||||
// Check move is allowed by the rules (to desactivate when playing with schools)
|
// Check move is allowed by the rules (to desactivate when playing with schools)
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,14 @@
|
||||||
//! # Expose trictrac game state and rules in a python module
|
//! # Expose trictrac game state and rules in a python module
|
||||||
use pyo3::prelude::*;
|
use pyo3::prelude::*;
|
||||||
use pyo3::types::PyDict;
|
|
||||||
|
|
||||||
use crate::board::CheckerMove;
|
use crate::dice::Dice;
|
||||||
use crate::dice::{Dice, DiceRoller};
|
|
||||||
use crate::game::{GameEvent, GameState, Stage, TurnStage};
|
use crate::game::{GameEvent, GameState, Stage, TurnStage};
|
||||||
use crate::game_rules_moves::MoveRules;
|
use crate::player::PlayerId;
|
||||||
use crate::game_rules_points::PointsRules;
|
|
||||||
use crate::player::{Color, PlayerId};
|
|
||||||
use crate::training_common::{get_valid_action_indices, TrictracAction};
|
use crate::training_common::{get_valid_action_indices, TrictracAction};
|
||||||
|
|
||||||
#[pyclass]
|
#[pyclass]
|
||||||
struct TricTrac {
|
struct TricTrac {
|
||||||
game_state: GameState,
|
game_state: GameState,
|
||||||
dice_roll_sequence: Vec<(u8, u8)>,
|
|
||||||
current_dice_index: usize,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[pymethods]
|
#[pymethods]
|
||||||
|
|
@ -30,11 +24,7 @@ impl TricTrac {
|
||||||
// Commencer la partie avec le joueur 1
|
// Commencer la partie avec le joueur 1
|
||||||
game_state.consume(&GameEvent::BeginGame { goes_first: 1 });
|
game_state.consume(&GameEvent::BeginGame { goes_first: 1 });
|
||||||
|
|
||||||
TricTrac {
|
TricTrac { game_state }
|
||||||
game_state,
|
|
||||||
dice_roll_sequence: Vec::new(),
|
|
||||||
current_dice_index: 0,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn needs_roll(&self) -> bool {
|
fn needs_roll(&self) -> bool {
|
||||||
|
|
|
||||||
|
|
@ -117,6 +117,10 @@ impl TrictracAction {
|
||||||
.get_checker_field(color, *checker1 as u8)
|
.get_checker_field(color, *checker1 as u8)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
let mut to1 = from1 + dice1 as usize;
|
let mut to1 = from1 + dice1 as usize;
|
||||||
|
if 24 < to1 {
|
||||||
|
// exit board
|
||||||
|
to1 = 0;
|
||||||
|
}
|
||||||
let checker_move1 = CheckerMove::new(from1, to1).unwrap_or_default();
|
let checker_move1 = CheckerMove::new(from1, to1).unwrap_or_default();
|
||||||
|
|
||||||
let mut tmp_board = state.board.clone();
|
let mut tmp_board = state.board.clone();
|
||||||
|
|
@ -129,6 +133,10 @@ impl TrictracAction {
|
||||||
.get_checker_field(color, *checker2 as u8)
|
.get_checker_field(color, *checker2 as u8)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
let mut to2 = from2 + dice2 as usize;
|
let mut to2 = from2 + dice2 as usize;
|
||||||
|
if 24 < to2 {
|
||||||
|
// exit board
|
||||||
|
to2 = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Gestion prise de coin par puissance
|
// Gestion prise de coin par puissance
|
||||||
let opp_rest_field = 13;
|
let opp_rest_field = 13;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue