From ec4ae2a749315720cc12f3d71f0860e2a32f96d2 Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Mon, 20 Jan 2020 23:09:52 -0800 Subject: Move rules were incorrectly/incompletely implemented --- src/main.rs | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 2100073..6bbe52d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -36,7 +36,7 @@ fn main() { let board_bottom = (size * cell_height + 3) as i32; let board_right = (size * cell_width + hoff + 3) as i32; - let mut board_gui = BoardGUI::new( + let board_gui = BoardGUI::new( 0, 0, size, @@ -48,7 +48,15 @@ fn main() { black_colour, ); - let game_log = GameLog::new(0, board_right, height, 20); + let game_log = GameLog::new( + 0, + board_right, + height, + 20, + has_colours, + white_colour, + black_colour, + ); // Need room for '8___011111111', for example let action_entry = ActionEntry::new(board_bottom, 0, 13); @@ -64,30 +72,37 @@ fn main() { let (mut game, warning) = Game::new(5, "tslil", "taktician"); message_log.log_error(warning); - - let pos = Position { x: 0, y: 0 }; - let action = Action::Place(Player::White, pos, Stone::Flat); - - if let Err(e) = game.perform_action(action) { - message_log.log_error(e); - } - - board_gui.update(&game); game_log.update(&game); loop { let inp = action_entry.read_action(); - match parse_action(game.query_current_player(), &inp) { - Ok(act) => message_log.log_error(format!("{}", act)), + let stone_owner = game.query_stone_owner(); + let player = game.query_current_player(); + match parse_action(stone_owner, &inp) { Err(err) => message_log.log_error(format!("Input \"{}\": {}", inp, err)), + Ok(act) => { + message_log.log_message(format!( + "{} performs {}{}", + player, + act, + if stone_owner != player { + format!(" with a {} stone.", stone_owner) + } else { + String::from(".") + } + )); + match game.perform_action(act) { + Err(e) => message_log.log_error(e), + Ok(pos_vec) => { + board_gui.update(&game, pos_vec); + game_log.update(&game); + } + } + } } action_entry.clear_entry_area(); } - // game_state.perform_action(&action); - // game_state.is_legal_action(&Action::Move(Player::White, pos, Direction::Up, vec![0, 1])); - // bg.draw_game_state(&game_state); - // board_gui.read_action(); // endwin(); } -- cgit v1.3.1