wip: relevé
This commit is contained in:
parent
fc58768006
commit
18bd87e68f
|
|
@ -105,6 +105,7 @@ impl App {
|
||||||
"history" => self.show_history(),
|
"history" => self.show_history(),
|
||||||
"quit" => self.quit(),
|
"quit" => self.quit(),
|
||||||
"roll" => self.roll_dice(),
|
"roll" => self.roll_dice(),
|
||||||
|
"go" => self.go(),
|
||||||
_ => self.add_move(input),
|
_ => self.add_move(input),
|
||||||
}
|
}
|
||||||
println!("{}", self.display());
|
println!("{}", self.display());
|
||||||
|
|
@ -152,6 +153,20 @@ impl App {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn go(&mut self) {
|
||||||
|
if self.game.player_id.is_none() {
|
||||||
|
println!("player_id not set ");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if self.game.state.turn_stage != TurnStage::HoldOrGoChoice {
|
||||||
|
println!("Not in position to go");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
self.game.handle_event(&GameEvent::Go {
|
||||||
|
player_id: self.game.player_id.unwrap(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
fn add_move(&mut self, input: &str) {
|
fn add_move(&mut self, input: &str) {
|
||||||
if self.game.player_id.is_none() {
|
if self.game.player_id.is_none() {
|
||||||
println!("player_id not set ");
|
println!("player_id not set ");
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ pub enum TurnStage {
|
||||||
RollDice,
|
RollDice,
|
||||||
RollWaiting,
|
RollWaiting,
|
||||||
MarkPoints,
|
MarkPoints,
|
||||||
|
HoldOrGoChoice,
|
||||||
Move,
|
Move,
|
||||||
MarkAdvPoints,
|
MarkAdvPoints,
|
||||||
}
|
}
|
||||||
|
|
@ -133,8 +134,9 @@ impl GameState {
|
||||||
TurnStage::RollWaiting => "000",
|
TurnStage::RollWaiting => "000",
|
||||||
TurnStage::RollDice => "001",
|
TurnStage::RollDice => "001",
|
||||||
TurnStage::MarkPoints => "010",
|
TurnStage::MarkPoints => "010",
|
||||||
TurnStage::Move => "011",
|
TurnStage::HoldOrGoChoice => "011",
|
||||||
TurnStage::MarkAdvPoints => "100",
|
TurnStage::Move => "100",
|
||||||
|
TurnStage::MarkAdvPoints => "101",
|
||||||
};
|
};
|
||||||
pos_bits.push_str(step_bits);
|
pos_bits.push_str(step_bits);
|
||||||
|
|
||||||
|
|
@ -273,6 +275,20 @@ impl GameState {
|
||||||
// return false;
|
// return false;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
Go { player_id } => {
|
||||||
|
if !self.players.contains_key(player_id) {
|
||||||
|
error!("Player {} unknown", player_id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Check player is currently the one making their move
|
||||||
|
if self.active_player_id != *player_id {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Check the player can leave (ie the game is in the KeepOrLeaveChoice stage)
|
||||||
|
if self.turn_stage != TurnStage::HoldOrGoChoice {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Move { player_id, moves } => {
|
Move { player_id, moves } => {
|
||||||
// Check player exists
|
// Check player exists
|
||||||
if !self.players.contains_key(player_id) {
|
if !self.players.contains_key(player_id) {
|
||||||
|
|
@ -284,6 +300,12 @@ impl GameState {
|
||||||
error!("Player not active : {}", self.active_player_id);
|
error!("Player not active : {}", self.active_player_id);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// Check the turn stage
|
||||||
|
if self.turn_stage != TurnStage::HoldOrGoChoice
|
||||||
|
|| self.turn_stage != TurnStage::Move
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
let color = &self.players[player_id].color;
|
let color = &self.players[player_id].color;
|
||||||
|
|
||||||
let rules = MoveRules::new(color, &self.board, self.dice);
|
let rules = MoveRules::new(color, &self.board, self.dice);
|
||||||
|
|
@ -411,6 +433,7 @@ impl GameState {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Go { player_id } => self.new_pick_up()
|
||||||
Move { player_id, moves } => {
|
Move { player_id, moves } => {
|
||||||
let player = self.players.get(player_id).unwrap();
|
let player = self.players.get(player_id).unwrap();
|
||||||
self.board.move_checker(&player.color, moves.0).unwrap();
|
self.board.move_checker(&player.color, moves.0).unwrap();
|
||||||
|
|
@ -427,6 +450,21 @@ impl GameState {
|
||||||
self.history.push(valid_event.clone());
|
self.history.push(valid_event.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set a new pick up ('relevé') after a player won a hole and choose to 'go',
|
||||||
|
/// or after a player has bore off (took of his men off the board)
|
||||||
|
fn new_pick_up(&mut self) {
|
||||||
|
// réinitialisation dice_roll_count
|
||||||
|
self.players.iter_mut().map(|(id, p)| p.dice_roll_count = 0);
|
||||||
|
// joueur actif = joueur ayant sorti ses dames (donc deux jeux successifs)
|
||||||
|
self.turn_stage = TurnStage::RollDice;
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
// - échanger les couleurs
|
||||||
|
// - remettre les dames des deux joueurs aux talons
|
||||||
|
// - jeton bredouille replaçé sur joueur actif (?)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
fn get_rollresult_points(&self, dice: &Dice) -> (u8, u8) {
|
fn get_rollresult_points(&self, dice: &Dice) -> (u8, u8) {
|
||||||
let player = &self.players.get(&self.active_player_id).unwrap();
|
let player = &self.players.get(&self.active_player_id).unwrap();
|
||||||
let points_rules = PointsRules::new(&player.color, &self.board, *dice);
|
let points_rules = PointsRules::new(&player.color, &self.board, *dice);
|
||||||
|
|
@ -497,6 +535,9 @@ pub enum GameEvent {
|
||||||
player_id: PlayerId,
|
player_id: PlayerId,
|
||||||
points: u8,
|
points: u8,
|
||||||
},
|
},
|
||||||
|
Go {
|
||||||
|
player_id: PlayerId,
|
||||||
|
},
|
||||||
Move {
|
Move {
|
||||||
player_id: PlayerId,
|
player_id: PlayerId,
|
||||||
moves: (CheckerMove, CheckerMove),
|
moves: (CheckerMove, CheckerMove),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue