aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortslil clingman <>2020-01-11 23:36:41 -0500
committertslil clingman <>2020-01-11 23:36:41 -0500
commit5ae986b316b0be692e79203f79a00a8afdd71a77 (patch)
treee4d97555f4bf12d6c05b4c1c8063413445046ee6
parent258e083264971acd3ef7ace721083972954f45e1 (diff)
Notes about action checking and generation
-rw-r--r--src/board.rs19
-rw-r--r--src/main.rs2
2 files changed, 18 insertions, 3 deletions
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<Stack>,
}
+// 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();