From 5ae986b316b0be692e79203f79a00a8afdd71a77 Mon Sep 17 00:00:00 2001 From: tslil clingman <> Date: Sat, 11 Jan 2020 23:36:41 -0500 Subject: Notes about action checking and generation --- src/board.rs | 19 +++++++++++++++++-- src/main.rs | 2 +- 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/board.rs b/src/board.rs index 626dcb0..9ba89dc 100644 --- a/src/board.rs +++ b/src/board.rs @@ -96,9 +96,22 @@ type Stack = Vec<(Player, Stone)>; pub struct Board { size: u16, + black_flats: u8, + white_flats: u8, + black_capstones: u8, + white_capstones: u8, board: Vec, } +// Probably it's best to split the move and place actions into their +// own methods, they should also take an extra argument which can be +// used to log error messages + +// How to solve code duplication between is_legal_action and +// perform_action? + +// TODO: Generate all legal actions for a given player + impl Board { fn lookup(&self, pos: &Position) -> Option<&Stack> { let y: u16 = pos.y as u16; @@ -106,10 +119,12 @@ impl Board { self.board.get((x + y * self.size) as usize) } - fn is_legal_move(&self, mov: &Action) -> bool { + fn is_legal_action(&self, mov: &Action) -> bool { match mov { - Action::Place(_, pos, _) => match self.lookup(pos) { + Action::Place(player, pos, piece) => match self.lookup(pos) { Some(stack) => { + // Incomplete and incorrect, must take account of + // piece availabilty if stack.len() == 0 { true } else { diff --git a/src/main.rs b/src/main.rs index 039ea9f..5794458 100644 --- a/src/main.rs +++ b/src/main.rs @@ -118,7 +118,7 @@ struct MoveEntry { impl MoveEntry { fn init(&self) { - self.win.attrset(COLOR_PAIR(3) | A_BOLD); // ???? + self.win.attrset(COLOR_PAIR(3) | A_BOLD); // ???? how self.win.mvaddstr(0, 0, "Enter move: ashtsaht"); // self.win.mvchgat(0,12,10,A_NORMAL,COLOR_PAIR(1)); self.win.refresh(); -- cgit v1.3.1