aboutsummaryrefslogtreecommitdiff
path: root/src/board.rs
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 /src/board.rs
parent258e083264971acd3ef7ace721083972954f45e1 (diff)
Notes about action checking and generation
Diffstat (limited to 'src/board.rs')
-rw-r--r--src/board.rs19
1 files changed, 17 insertions, 2 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 {