1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (c) 2006 Alexander Levin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #ifndef _REVERSI_GAME_H
23 #define _REVERSI_GAME_H
28 #define WHITE 1 /* WHITE constant, it always plays first (as in chess) */
29 #define BLACK -1 /* BLACK constant */
30 #define FREE 0 /* Free place constant */
35 /* Description of a move. A move is stored as a byte in the following format:
36 * - bit 7 : 0 for valid entries (i.e. those containing a move info,
37 * 1 for invalid entries
39 * - bit 3 : 0 if it's white move, 1 if it's black move
42 typedef unsigned char move_t
;
44 #define MOVE_ROW(h) (((h) >> 4) & 0x7)
45 #define MOVE_COL(h) ((h) & 0x7)
46 #define MOVE_PLAYER(h) (((h) & 0x8) ? BLACK : WHITE)
47 #define MAKE_MOVE(r,c,player) ( ((r)<<4) | ((c)&0x7) | \
48 ((player) == WHITE ? 0 : 0x8) )
49 #define MOVE_INVALID 0x80
52 /* State of a board */
53 typedef struct _reversi_board_t
{
54 /* The current state of the game (BLACK/WHITE/FREE) */
55 int board
[BOARD_SIZE
][BOARD_SIZE
];
57 /* Game history. First move (mostly, but not necessarily, black) is stored
58 * in history[0], second move (mostly, but not necessarily, white) is
59 * stored in history[1] etc.
61 move_t history
[BOARD_SIZE
*BOARD_SIZE
- INIT_STONES
];
65 void reversi_init_game(reversi_board_t
*game
);
66 int reversi_flipped_color(const int color
);
67 bool reversi_game_is_finished(const reversi_board_t
*game
, int cur_player
);
68 int reversi_count_occupied_cells(const reversi_board_t
*game
,
69 int *white_count
, int *black_count
);
70 int reversi_count_moves(const reversi_board_t
*game
);
71 int reversi_count_white_moves(const reversi_board_t
*game
);
72 int reversi_count_black_moves(const reversi_board_t
*game
);
73 int reversi_make_move(reversi_board_t
*game
, const int row
,
74 const int col
, const int player
);
75 int reversi_is_valid_move(const reversi_board_t
*game
,
76 const int row
, const int col
, const int player
);
77 int reversi_count_player_available_moves(const reversi_board_t
*game
,
79 int reversi_count_passes(const reversi_board_t
*game
, const int player
);