move->is_capture = 0;
matched = sscanf (string, " %c%d%c%c%d", &xc1, &y1, &sep, &xc2, &y2);
- if (matched != 5) {
- printf ("Matched only %d fields of %s\n", matched, string);
+ if (matched != 5)
return FALSE;
- }
x1 = tolower (xc1) - 'a';
x2 = tolower (xc2) - 'a';
return 0;
}
-static loa_bool_t
-loa_board_move_legal (loa_board_t *board,
- const loa_move_t *move,
- char **error)
+loa_bool_t
+loa_board_move_is_legal (loa_board_t *board,
+ loa_move_t *move,
+ char **error)
{
int x, y;
int x1, y1, x2, y2;
return FALSE;
}
+ if (board->cells[x2][y2] == LOA_CELL_EMPTY)
+ move->is_capture = FALSE;
+ else
+ move->is_capture = TRUE;
+
dx = x2 - x1;
dy = y2 - y1;
{
loa_cell_t cell;
- if (! loa_board_move_legal (board, move, error))
+ if (! loa_board_move_is_legal (board, move, error))
return FALSE;
cell = loa_board_remove_piece (board, move->x1, move->y1);
assert (cell == board->player);
cell = loa_board_remove_piece (board, move->x2, move->y2);
- if (cell == LOA_CELL_EMPTY) {
- move->is_capture = FALSE;
- } else {
- assert (cell != board->player);
- move->is_capture = TRUE;
- }
+ assert (cell == LOA_CELL_EMPTY ||
+ (move->is_capture && cell != board->player));
loa_board_add_piece (board,
move->x2, move->y2,