aboutsummaryrefslogtreecommitdiff
path: root/include/tak.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/tak.c')
-rw-r--r--include/tak.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/include/tak.c b/include/tak.c
index 57dacf7..657df9d 100644
--- a/include/tak.c
+++ b/include/tak.c
@@ -127,6 +127,11 @@ try_move(const int8_t location, const enum MOVE_DIRECTION direction,
if (won < 0xFF) return GAME_END;
// Can't do this
if (steps == 0 || steps > 5) return ACT_ILLEGAL;
+ // Check for stones at all
+ const uint8_t avail = COUNT_AT(location);
+ if (avail == 0) return ACT_ILLEGAL;
+ // Does the current player own the pile?
+ if ((colours[location] & 1) != current_colour) return ACT_ILLEGAL;
// Is the desired direction and count on the board?
int8_t delta = 0;
switch (direction) {
@@ -188,8 +193,7 @@ try_move(const int8_t location, const enum MOVE_DIRECTION direction,
}
// Can't ask to move 0, more than board_size, or stones available
- if ( (total == 0) || (total > board_size)
- || (total > COUNT_AT(location)) )
+ if ( (total == 0) || (total > board_size) || (total > avail) )
return ACT_ILLEGAL;
// Nothing illegal, do it. First we add the stones to the