X-Git-Url: https://git.cworth.org/git?p=dvonn;a=blobdiff_plain;f=dvonn-board.c;fp=dvonn-board.c;h=795ff5531d6ed2726e4b24907ccbb5ecbc5fe96f;hp=35789e7d13a238748dd3b07e5a95aed218ed0d95;hb=0eff3c58b93ea73e7f1aa866f6e317714479dd6e;hpb=eff695079bc44eb96226db9db6fd6cacc9497b9b diff --git a/dvonn-board.c b/dvonn-board.c index 35789e7..795ff55 100644 --- a/dvonn-board.c +++ b/dvonn-board.c @@ -76,7 +76,9 @@ dvonn_board_init (dvonn_board_t *board) } } + board->phase = DVONN_PHASE_PLACEMENT; board->player = DVONN_PLAYER_WHITE; + board->moves = 0; } static dvonn_bool_t @@ -123,12 +125,49 @@ dvonn_board_next_player (dvonn_board_t *board) board->player = DVONN_PLAYER_BLACK; } +int +dvonn_board_place (dvonn_board_t *board, + int x, int y, + char **error) +{ + if (board->phase != DVONN_PHASE_PLACEMENT) { + *error = "Cannot place outside of placement phase"; + return FALSE; + } + + if (board->cells[x][y].type != DVONN_CELL_EMPTY) { + *error = "Cannot place on an occupied space"; + return FALSE; + } + + if (board->moves < 3) + board->cells[x][y].type = DVONN_CELL_RED; + else if (board->moves % 2) + board->cells[x][y].type = DVONN_CELL_BLACK; + else + board->cells[x][y].type = DVONN_CELL_WHITE; + + board->moves++; + + if (board->moves == 49) { + board->phase = DVONN_PHASE_MOVEMENT; + board->moves = 0; + } + + return TRUE; +} + int dvonn_board_move (dvonn_board_t *board, int x1, int y1, int x2, int y2, char **error) { + if (board->phase != DVONN_PHASE_MOVEMENT) { + *error = "Cannot move outside of placement phase"; + return FALSE; + } + if (! dvonn_board_move_legal (board, x1, y1, x2, y2, error)) return FALSE;