display logs

This commit is contained in:
Henri Bourcereau 2025-01-12 16:38:43 +01:00
parent ff5ff74282
commit 53f95c0fe4
7 changed files with 130 additions and 20 deletions

106
Cargo.lock generated
View file

@ -27,6 +27,55 @@ version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
[[package]]
name = "anstream"
version = "0.6.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
[[package]]
name = "anstyle-parse"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
dependencies = [
"windows-sys 0.59.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2109dbce0e72be3ec00bed26e6a7479ca384ad226efdd66db8fa2e3a38c83125"
dependencies = [
"anstyle",
"windows-sys 0.59.0",
]
[[package]]
name = "anyhow"
version = "1.0.89"
@ -143,6 +192,7 @@ dependencies = [
"anyhow",
"bincode",
"bot",
"env_logger 0.11.6",
"itertools",
"pico-args",
"pretty_assertions",
@ -161,6 +211,12 @@ dependencies = [
"store",
]
[[package]]
name = "colorchoice"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
[[package]]
name = "compact_str"
version = "0.8.0"
@ -232,6 +288,16 @@ version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07"
[[package]]
name = "env_filter"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "186e05a59d4c50738528153b83b0b0194d3a29507dfec16eccd4b342903397d0"
dependencies = [
"log",
"regex",
]
[[package]]
name = "env_logger"
version = "0.10.0"
@ -245,6 +311,19 @@ dependencies = [
"termcolor",
]
[[package]]
name = "env_logger"
version = "0.11.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcaee3d8e3cfc3fd92428d477bc97fc29ec8716d180c0d74c643bb26166660e0"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"humantime",
"log",
]
[[package]]
name = "equivalent"
version = "1.0.1"
@ -347,6 +426,12 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
[[package]]
name = "itertools"
version = "0.13.0"
@ -386,9 +471,9 @@ dependencies = [
[[package]]
name = "log"
version = "0.4.20"
version = "0.4.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
[[package]]
name = "lru"
@ -871,7 +956,7 @@ name = "trictrac-server"
version = "0.1.0"
dependencies = [
"bincode",
"env_logger",
"env_logger 0.10.0",
"log",
"pico-args",
"renet",
@ -923,6 +1008,12 @@ dependencies = [
"subtle",
]
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]]
name = "version_check"
version = "0.9.4"
@ -984,6 +1075,15 @@ dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-sys"
version = "0.59.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
dependencies = [
"windows-targets 0.52.6",
]
[[package]]
name = "windows-targets"
version = "0.48.5"

View file

@ -14,3 +14,4 @@ renet = "0.0.13"
store = { path = "../store" }
bot = { path = "../bot" }
itertools = "0.13.0"
env_logger = "0.11.6"

View file

@ -25,6 +25,7 @@ ARGS:
";
fn main() -> Result<()> {
env_logger::init();
let args = match parse_args() {
Ok(v) => v,
Err(e) => {

View file

@ -6,11 +6,7 @@ doc:
cargo doc --no-deps
shell:
devenv shell
startserver:
RUST_LOG=trictrac_server cargo run --bin trictrac-server
startclient1:
RUST_LOG=trictrac_client cargo run --bin=trictrac-client Titi
startclient2:
RUST_LOG=trictrac_client cargo run --bin=trictrac-client Titu
startclienttui:
RUST_LOG=trictrac_client cargo run --bin=client_tui Tutu
runcli:
RUST_LOG=info cargo run --bin=client_cli
runclibots:
RUST_LOG=info cargo run --bin=client_cli -- --bot dummy,dummy

View file

@ -7,6 +7,7 @@ edition = "2021"
[dependencies]
base64 = "0.21.7"
# provides macros for creating log messages to be used by a logger (for example env_logger)
log = "0.4.20"
merge = "0.1.0"
rand = "0.8.5"

View file

@ -491,8 +491,9 @@ impl GameState {
p.dice_roll_count = 0;
// reset bredouille
p.can_bredouille = true;
// switch colors
p.color = p.color.opponent_color();
// XXX : switch colors
// désactivé pour le moment car la vérification des mouvements échoue, cf. https://code.rhumbs.fr/henri/trictrac/issues/31
// p.color = p.color.opponent_color();
});
// joueur actif = joueur ayant sorti ses dames ou est parti (donc deux jeux successifs)
self.turn_stage = TurnStage::RollDice;

View file

@ -3,6 +3,7 @@ use crate::board::{Board, CheckerMove, Field, EMPTY_MOVE};
use crate::dice::Dice;
use crate::game::GameState;
use crate::player::Color;
use log::info;
use std::cmp;
#[derive(std::cmp::PartialEq, Debug)]
@ -65,27 +66,34 @@ impl MoveRules {
// 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)
self.moves_possible(moves)
&& self.moves_follows_dices(moves)
&& self.moves_allowed(moves).is_ok()
self.moves_possible(moves) && self.moves_follows_dices(moves) && {
let is_allowed = self.moves_allowed(moves);
if is_allowed.is_err() {
info!("Move not allowed : {:?}", is_allowed.unwrap_err());
false
} else {
true
}
}
// && self.moves_allowed(moves).is_ok()
}
/// ---- moves_possibles : First of three checks for moves
fn moves_possible(&self, moves: &(CheckerMove, CheckerMove)) -> bool {
println!("possible ???");
let color = &Color::White;
if let Ok(chained_move) = moves.0.chain(moves.1) {
// Check intermediary move and chained_move : "Tout d'une"
if !self.board.passage_possible(color, &moves.0)
|| !self.board.move_possible(color, &chained_move)
{
info!("Tout d'une : Move not physically possible");
return false;
}
} else if !self.board.move_possible(color, &moves.0)
|| !self.board.move_possible(color, &moves.1)
{
// Move is not physically possible
println!("no phys! {} {:?}", self.board, moves);
info!("Move not physically possible");
return false;
}
true
@ -103,10 +111,12 @@ impl MoveRules {
let move1_dices = self.get_move_compatible_dices(move1);
if move1_dices.is_empty() {
info!("Move does not follow dice");
return false;
}
let move2_dices = self.get_move_compatible_dices(move2);
if move2_dices.is_empty() {
info!("Move does not follow dice");
return false;
}
if move1_dices.len() == 1
@ -114,6 +124,7 @@ impl MoveRules {
&& move1_dices[0] == move2_dices[0]
&& dice1 != dice2
{
info!("Move does not follow dice");
return false;
}
@ -1038,7 +1049,6 @@ mod tests {
CheckerMove::new(8, 13).unwrap(),
CheckerMove::new(13, 19).unwrap(),
);
println!("{:?}", state.moves_allowed(&moves));
assert!(state.moves_allowed(&moves).is_ok());
// s'il n'y a pas d'autre solution, on peut rompre