]> git.cworth.org Git - loudgame/blobdiff - loa-board.c
Update documentation of move command for new syntax
[loudgame] / loa-board.c
index 21f4302ffaf676283c0e7b1495f5839f191d0194..b4d13bc218cf610e70ab50879c777e8a65037394 100644 (file)
@@ -71,7 +71,7 @@ loa_move_init_from_string (loa_move_t *move, const char *string)
     move->y2 = 0;
     move->is_capture = 0;
 
-    matched = sscanf (string, "%c%d%c%c%d", &xc1, &y1, &sep, &xc2, &y2);
+    matched = sscanf (string, " %c%d%c%c%d", &xc1, &y1, &sep, &xc2, &y2);
     if (matched != 5)
        return FALSE;
 
@@ -274,10 +274,10 @@ loa_board_is_won (loa_board_t *board, int x, int y)
     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;
@@ -310,6 +310,11 @@ loa_board_move_legal (loa_board_t   *board,
        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;
 
@@ -413,35 +418,26 @@ loa_board_add_move_to_history (loa_board_t        *board,
 
 int
 loa_board_move (loa_board_t *board,
-               int x1, int y1,
-               int x2, int y2,
+               loa_move_t *move,
                char **error)
 {
     loa_cell_t cell;
-    loa_move_t move;
-
-    move.x1 = x1;
-    move.y1 = y1;
-    move.x2 = x2;
-    move.y2 = y2;
 
-    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, x1, y1);
+    cell = loa_board_remove_piece (board, move->x1, move->y1);
     assert (cell == board->player);
 
-    cell = loa_board_remove_piece (board, x2, y2);
-    if (cell == LOA_CELL_EMPTY) {
-       move.is_capture = FALSE;
-    } else {
-       assert (cell != board->player);
-       move.is_capture = TRUE;
-    }
+    cell = loa_board_remove_piece (board, move->x2, move->y2);
+    assert (cell == LOA_CELL_EMPTY ||
+           (move->is_capture && cell != board->player));
 
-    loa_board_add_piece (board, x2, y2, board->player);
+    loa_board_add_piece (board,
+                        move->x2, move->y2,
+                        board->player);
 
-    loa_board_add_move_to_history (board, &move);
+    loa_board_add_move_to_history (board, move);
 
     loa_board_next_player (board);