From 0a3b2d825077b5e6c5f1cf4a0dcb13fdfffc0be6 Mon Sep 17 00:00:00 2001 From: tslil Date: Tue, 29 Dec 2020 22:48:53 -0500 Subject: Working on the big wrapper for everything --- include/state.c | 106 +++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 78 insertions(+), 28 deletions(-) (limited to 'include/state.c') diff --git a/include/state.c b/include/state.c index 3708792..dfdd02b 100644 --- a/include/state.c +++ b/include/state.c @@ -18,7 +18,8 @@ // ------------------------------------------------------------------- // Game management -void reset_state(const uint8_t new_board_size) { +void +reset_state(const uint8_t new_board_size) { if (new_board_size == 6) { board_size = 6; white_flats = 30; black_flats = 30; @@ -30,16 +31,39 @@ void reset_state(const uint8_t new_board_size) { black_caps = 1; turn = 0; + current_colour = C_BLACK; for (uint8_t k = 0; k < board_size * board_size; k++ ) { celldat[k] = 0; } } +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) + } + } + } + */ +} + // ------------------------------------------------------------------- // Place stone -enum ACTION_RESULT +enum E_RESULT try_place(const int8_t location, const enum COLOUR colour, const enum STONE_VARIANT stone) { @@ -95,7 +119,7 @@ drop_stones(const int8_t location, const uint8_t count) { celldat[location] = dec_count & NUM_MASK; } -enum ACTION_RESULT +enum E_RESULT try_move(const int8_t location, const enum MOVE_DIRECTION direction, const uint8_t steps, const uint8_t drops[5]) { // Can't do this @@ -225,34 +249,16 @@ dfs_road(uint8_t dfs_stack[board_size*board_size], uint8_t dfs_pntr, return 0; } -enum WIN_RESULT -check_win(const enum COLOUR colour) { - // Do we do a flat count? - if (black_flats == 0 || white_flats == 0 || board_full()) { - int8_t total = 0; - for (uint8_t k = 0; k < board_size * board_size; k++) { - if (STONE_AT(k) == STONE_FLAT) { - total += ((colours[k] & 1) == C_BLACK) ? +1 : -1 ; - } - } - if (total > 0) return W_FLAT_BLACK; - else return W_FLAT_WHITE; - } - - // Road? +enum E_RESULT +check_road_colour(const enum COLOUR colour) { uint8_t dfs_stack[board_size * board_size]; uint8_t dfs_pntr = 0; // Prime the depth-first-search stack with all boundary cells of - // colour COLOUR, we're using the two left-over bits in data_t to - // track whether we've seen it. Reset those before anything. + // colour COLOUR. - for (uint8_t k=0; k 0) { + return W_FLAT_BLACK; + } else if (total < 0) { + return W_FLAT_WHITE; + } else { + return W_DRAW; + } + } + + // Road? + + // We're using the two left-over bits in data_t to track whether + // we've seen it. Reset those before anything. No need to do it + // between checks, however, as pieces are black XOR white. + + for (uint8_t k=0; k