feat: show last jans & moves
This commit is contained in:
parent
fbd5976d88
commit
c5321e6186
|
|
@ -230,6 +230,13 @@ impl App {
|
||||||
output = output + "\nRolled dice : " + &self.game.state.dice.to_display_string();
|
output = output + "\nRolled dice : " + &self.game.state.dice.to_display_string();
|
||||||
|
|
||||||
if self.game.state.stage != Stage::PreGame {
|
if self.game.state.stage != Stage::PreGame {
|
||||||
|
output = output + "\nRolled dice jans : " + &format!("{:?}", self.game.state.dice_jans);
|
||||||
|
output = output
|
||||||
|
+ "\nLast move : "
|
||||||
|
+ &self.game.state.dice_moves.0.to_display_string()
|
||||||
|
+ ", "
|
||||||
|
+ &self.game.state.dice_moves.1.to_display_string();
|
||||||
|
|
||||||
// display players points
|
// display players points
|
||||||
output += format!("\n\n{:<11} :: {:<5} :: {}", "Player", "holes", "points").as_str();
|
output += format!("\n\n{:<11} :: {:<5} :: {}", "Player", "holes", "points").as_str();
|
||||||
|
|
||||||
|
|
@ -293,6 +300,8 @@ Rolled dice : 0 & 0
|
||||||
let expected = "-------------------------------
|
let expected = "-------------------------------
|
||||||
InGame > myself > RollDice
|
InGame > myself > RollDice
|
||||||
Rolled dice : 4 & 6
|
Rolled dice : 4 & 6
|
||||||
|
Rolled dice jans : {}
|
||||||
|
Last move : CheckerMove { from: 24, to: 20 } , CheckerMove { from: 24, to: 18 }
|
||||||
|
|
||||||
Player :: holes :: points
|
Player :: holes :: points
|
||||||
1. myself :: 0 :: 0
|
1. myself :: 0 :: 0
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,10 @@ impl Default for CheckerMove {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CheckerMove {
|
impl CheckerMove {
|
||||||
|
pub fn to_display_string(self) -> String {
|
||||||
|
format!("{:?} ", self)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(from: Field, to: Field) -> Result<Self, Error> {
|
pub fn new(from: Field, to: Field) -> Result<Self, Error> {
|
||||||
// println!("from {} to {}", from, to);
|
// println!("from {} to {}", from, to);
|
||||||
// check if the field is on the board
|
// check if the field is on the board
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
use crate::board::{Board, CheckerMove};
|
use crate::board::{Board, CheckerMove};
|
||||||
use crate::dice::Dice;
|
use crate::dice::Dice;
|
||||||
use crate::game_rules_moves::MoveRules;
|
use crate::game_rules_moves::MoveRules;
|
||||||
use crate::game_rules_points::PointsRules;
|
use crate::game_rules_points::{PointsRules, PossibleJans};
|
||||||
use crate::player::{Color, Player, PlayerId};
|
use crate::player::{Color, Player, PlayerId};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
|
|
@ -45,6 +45,8 @@ pub struct GameState {
|
||||||
pub dice: Dice,
|
pub dice: Dice,
|
||||||
/// players points computed for the last dice pair rolled
|
/// players points computed for the last dice pair rolled
|
||||||
dice_points: (u8, u8),
|
dice_points: (u8, u8),
|
||||||
|
pub dice_moves: (CheckerMove, CheckerMove),
|
||||||
|
pub dice_jans: PossibleJans,
|
||||||
/// true if player needs to roll first
|
/// true if player needs to roll first
|
||||||
roll_first: bool,
|
roll_first: bool,
|
||||||
// NOTE: add to a Setting struct if other fields needed
|
// NOTE: add to a Setting struct if other fields needed
|
||||||
|
|
@ -77,6 +79,8 @@ impl Default for GameState {
|
||||||
history: Vec::new(),
|
history: Vec::new(),
|
||||||
dice: Dice::default(),
|
dice: Dice::default(),
|
||||||
dice_points: (0, 0),
|
dice_points: (0, 0),
|
||||||
|
dice_moves: (CheckerMove::default(), CheckerMove::default()),
|
||||||
|
dice_jans: PossibleJans::default(),
|
||||||
roll_first: true,
|
roll_first: true,
|
||||||
schools_enabled: false,
|
schools_enabled: false,
|
||||||
}
|
}
|
||||||
|
|
@ -339,7 +343,6 @@ impl GameState {
|
||||||
}
|
}
|
||||||
|
|
||||||
let player_id = self.players.len() + 1;
|
let player_id = self.players.len() + 1;
|
||||||
println!("player_id {}", player_id);
|
|
||||||
let color = if player_id == 1 {
|
let color = if player_id == 1 {
|
||||||
Color::White
|
Color::White
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -419,7 +422,7 @@ impl GameState {
|
||||||
self.dice = *dice;
|
self.dice = *dice;
|
||||||
self.inc_roll_count(self.active_player_id);
|
self.inc_roll_count(self.active_player_id);
|
||||||
self.turn_stage = TurnStage::MarkPoints;
|
self.turn_stage = TurnStage::MarkPoints;
|
||||||
self.dice_points = self.get_rollresult_points(dice);
|
(self.dice_jans, self.dice_points) = self.get_rollresult_jans(dice);
|
||||||
if !self.schools_enabled {
|
if !self.schools_enabled {
|
||||||
// Schools are not enabled. We mark points automatically
|
// Schools are not enabled. We mark points automatically
|
||||||
// the points earned by the opponent will be marked on its turn
|
// the points earned by the opponent will be marked on its turn
|
||||||
|
|
@ -460,6 +463,7 @@ impl GameState {
|
||||||
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();
|
||||||
self.board.move_checker(&player.color, moves.1).unwrap();
|
self.board.move_checker(&player.color, moves.1).unwrap();
|
||||||
|
self.dice_moves = *moves;
|
||||||
self.active_player_id = *self.players.keys().find(|id| *id != player_id).unwrap();
|
self.active_player_id = *self.players.keys().find(|id| *id != player_id).unwrap();
|
||||||
self.turn_stage = if self.schools_enabled {
|
self.turn_stage = if self.schools_enabled {
|
||||||
TurnStage::MarkAdvPoints
|
TurnStage::MarkAdvPoints
|
||||||
|
|
@ -490,10 +494,10 @@ impl GameState {
|
||||||
self.board = Board::new();
|
self.board = Board::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_rollresult_points(&self, dice: &Dice) -> (u8, u8) {
|
fn get_rollresult_jans(&self, dice: &Dice) -> (PossibleJans, (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);
|
||||||
points_rules.get_points(player.dice_roll_count)
|
points_rules.get_result_jans(player.dice_roll_count)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Determines if someone has won the game
|
/// Determines if someone has won the game
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
use std::cmp;
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use crate::board::{Board, Field, EMPTY_MOVE};
|
use crate::board::{Board, Field, EMPTY_MOVE};
|
||||||
use crate::dice::{self, Dice};
|
use crate::dice::Dice;
|
||||||
use crate::game_rules_moves::MoveRules;
|
use crate::game_rules_moves::MoveRules;
|
||||||
use crate::player::Color;
|
use crate::player::Color;
|
||||||
use crate::CheckerMove;
|
use crate::CheckerMove;
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
#[derive(PartialEq, Eq, Hash, Clone, Debug)]
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::cmp;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq, Hash, Clone, Debug, Serialize, Deserialize)]
|
||||||
pub enum Jan {
|
pub enum Jan {
|
||||||
FilledQuarter,
|
FilledQuarter,
|
||||||
TrueHitSmallJan,
|
TrueHitSmallJan,
|
||||||
|
|
@ -61,9 +62,9 @@ impl Jan {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type PossibleJans = HashMap<Jan, Vec<(CheckerMove, CheckerMove)>>;
|
pub type PossibleJans = HashMap<Jan, Vec<(CheckerMove, CheckerMove)>>;
|
||||||
|
|
||||||
trait PossibleJansMethods {
|
pub trait PossibleJansMethods {
|
||||||
fn push(&mut self, jan: Jan, cmoves: (CheckerMove, CheckerMove));
|
fn push(&mut self, jan: Jan, cmoves: (CheckerMove, CheckerMove));
|
||||||
fn merge(&mut self, other: Self);
|
fn merge(&mut self, other: Self);
|
||||||
// fn get_points(&self) -> u8;
|
// fn get_points(&self) -> u8;
|
||||||
|
|
@ -468,6 +469,12 @@ impl PointsRules {
|
||||||
let jans = self.get_jans(&self.board, dice_rolls_count);
|
let jans = self.get_jans(&self.board, dice_rolls_count);
|
||||||
self.get_jans_points(jans)
|
self.get_jans_points(jans)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_result_jans(&self, dice_rolls_count: u8) -> (PossibleJans, (u8, u8)) {
|
||||||
|
let jans = self.get_jans(&self.board, dice_rolls_count);
|
||||||
|
let points_jans = jans.clone();
|
||||||
|
(jans, self.get_jans_points(points_jans))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue