wip points rules
This commit is contained in:
parent
7790c07dcc
commit
aff489f134
7 changed files with 62 additions and 10 deletions
|
|
@ -1,7 +1,8 @@
|
|||
//! # Play a TricTrac Game
|
||||
use crate::board::{Board, CheckerMove, Field, EMPTY_MOVE};
|
||||
use crate::board::{Board, CheckerMove};
|
||||
use crate::dice::Dice;
|
||||
use crate::game_rules_moves::{MoveError, MoveRules};
|
||||
use crate::game_rules_moves::MoveRules;
|
||||
use crate::game_rules_points::PointsRules;
|
||||
use crate::player::{Color, Player, PlayerId};
|
||||
use log::error;
|
||||
|
||||
|
|
@ -59,6 +60,15 @@ impl fmt::Display for GameState {
|
|||
}
|
||||
}
|
||||
|
||||
impl PointsRules for GameState {
|
||||
fn board(&self) -> &Board {
|
||||
&self.board
|
||||
}
|
||||
fn dice(&self) -> &Dice {
|
||||
&self.dice
|
||||
}
|
||||
}
|
||||
|
||||
impl MoveRules for GameState {
|
||||
fn board(&self) -> &Board {
|
||||
&self.board
|
||||
|
|
@ -236,10 +246,7 @@ impl GameState {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
Mark {
|
||||
player_id,
|
||||
points: _,
|
||||
} => {
|
||||
Mark { player_id, points } => {
|
||||
// Check player exists
|
||||
if !self.players.contains_key(player_id) {
|
||||
return false;
|
||||
|
|
@ -248,6 +255,12 @@ impl GameState {
|
|||
if self.active_player_id != *player_id {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check points are correct
|
||||
let rules_points: u8 = self.get_points().iter().map(|r| r.0).sum();
|
||||
if rules_points != *points {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Move { player_id, moves } => {
|
||||
// Check player exists
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue