summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs43
1 files changed, 38 insertions, 5 deletions
diff --git a/src/main.rs b/src/main.rs
index 263997f..be24a77 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,10 +1,27 @@
+mod consulter;
mod game;
mod gui;
mod parser;
+use crate::consulter::*;
use crate::game::*;
use crate::gui::*;
use crate::parser::*;
+use std::io::Error;
+
+fn human_action(
+ action_entry: &ActionEntry,
+ message_log: &MessageLog,
+ game: &Game,
+) -> Result<Action, Error> {
+ loop {
+ let inp = action_entry.read_action();
+ match parse_action(&game, &inp) {
+ Err(err) => message_log.log_error(format!("Input \"{}\": {}", inp, err)),
+ Ok(action) => return Ok(action),
+ }
+ }
+}
fn main() {
let screen = initscr();
@@ -74,10 +91,18 @@ fn main() {
message_log.log_error(warning);
game_log.update(&game);
+ const CONSULT_PROC: &str = "/home/tslil/bin/wrap_taktician";
loop {
- let inp = action_entry.read_action();
- match parse_action(&game, &inp) {
- Err(err) => message_log.log_error(format!("Input \"{}\": {}", inp, err)),
+ let inp = match game.query_current_player() {
+ Player::Black => consult_next_action(&game, CONSULT_PROC),
+ Player::White => human_action(&action_entry, &message_log, &game),
+ };
+
+ match inp {
+ Err(err) => {
+ message_log.log_error(format!("{}", err));
+ break;
+ }
Ok(act) => {
let stone_owner = game.query_stone_owner();
let player = game.query_current_player();
@@ -93,7 +118,14 @@ fn main() {
}
));
match game.perform_action(act) {
- Err(e) => message_log.log_error(e),
+ Err(e) => {
+ message_log.log_error(e);
+ if game.query_current_player() == Player::Black {
+ // external and internal gamestates diverged
+ break;
+ }
+ }
+
Ok((pos_vec, win)) => {
board_gui.update(&game, pos_vec);
game_log.update(&game);
@@ -108,6 +140,7 @@ fn main() {
action_entry.clear_entry_area();
}
- board_gui.read_action();
+ screen.getch();
+ // board_gui.read_action();
endwin();
}