aboutsummaryrefslogtreecommitdiff
path: root/include/state.c
diff options
context:
space:
mode:
Diffstat (limited to 'include/state.c')
-rw-r--r--include/state.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/include/state.c b/include/state.c
index dfdd02b..94d0773 100644
--- a/include/state.c
+++ b/include/state.c
@@ -40,24 +40,13 @@ reset_state(const uint8_t new_board_size) {
void
next_turn(void) {
- /*
-
- StartType::CPS(c) => {
- if ply / 2 >= (*c as usize) {
- if ply % 2 == 0 {
- (Player::White, TurnOrder::Normal)
- } else {
- (Player::Black, TurnOrder::Normal)
- }
- } else {
- if ply % 2 == 0 {
- (Player::White, TurnOrder::WhitePlacesBlack)
- } else {
- (Player::Black, TurnOrder::BlackPlacesWhite)
- }
- }
- }
- */
+ turn++;
+ if (turn == 2) {
+ current_colour = C_WHITE;
+ } else {
+ if (current_colour == C_BLACK) current_colour = C_WHITE;
+ else current_colour = C_BLACK;
+ }
}
// -------------------------------------------------------------------
@@ -104,18 +93,18 @@ try_place(const int8_t location, const enum COLOUR colour,
// -------------------------------------------------------------------
// Move stack
-void
+static void
push_stones(const int8_t location, const uint8_t count, const uint8_t new_colours,
const enum STONE_VARIANT top_stone) {
colours[location] = (colours[location] << count) | new_colours;
celldat[location] = ((celldat[location] + ((count << NUM_SHIFT))) & NUM_MASK) | top_stone;
}
-void
+static void
drop_stones(const int8_t location, const uint8_t count) {
// Calling this with count = 0 is destructive
colours[location] >>= count;
- const uint8_t dec_count = celldat[location] + (((~count) << NUM_SHIFT));
+ const uint8_t dec_count = celldat[location] - (count << NUM_SHIFT);
celldat[location] = dec_count & NUM_MASK;
}
@@ -186,11 +175,11 @@ try_move(const int8_t location, const enum MOVE_DIRECTION direction,
j -= drops[k];
push_stones(location+(k+1)*delta,
drops[k],
- (colours[location] >> j) & (0xFFFF >> (16 - drops[k])),
+ (colours[location] >> j) & (0xFFFF >> (0x10 - drops[k])),
(k == steps - 1) ? STONE_AT(location) : STONE_FLAT);
}
- drop_stones(location, COUNT_AT(location)-total);
+ drop_stones(location, total);
return A_OK;
}
@@ -198,7 +187,7 @@ try_move(const int8_t location, const enum MOVE_DIRECTION direction,
// -------------------------------------------------------------------
// Win conditions
-uint8_t
+static uint8_t
board_full(void) {
for (uint8_t k; k < board_size*board_size; k++) {
if (COUNT_AT(k) == 0) return 0;
@@ -207,7 +196,7 @@ board_full(void) {
}
// direction == 0 --> left-to-right, otherwise --> top-to-bottom
-uint8_t
+static uint8_t
dfs_road(uint8_t dfs_stack[board_size*board_size], uint8_t dfs_pntr,
const enum COLOUR colour, const uint8_t direction) {
while (dfs_pntr > 0) {
@@ -249,7 +238,7 @@ dfs_road(uint8_t dfs_stack[board_size*board_size], uint8_t dfs_pntr,
return 0;
}
-enum E_RESULT
+static enum E_RESULT
check_road_colour(const enum COLOUR colour) {
uint8_t dfs_stack[board_size * board_size];
uint8_t dfs_pntr = 0;