Rename variables sectorbuf and verbose to avoid clashes in rbutil. Cleanup exports...
[Rockbox.git] / apps / plugins / reversi / reversi-game.h
blob9558f000bfa286e0d7fd00a5c5efa742a6821146
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (c) 2006 Alexander Levin
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 #ifndef _REVERSI_GAME_H
21 #define _REVERSI_GAME_H
23 #include <stdbool.h>
24 #include "plugin.h"
26 #define WHITE 1 /* WHITE constant, it always plays first (as in chess) */
27 #define BLACK -1 /* BLACK constant */
28 #define FREE 0 /* Free place constant */
30 #define BOARD_SIZE 8
31 #define INIT_STONES 4
33 /* Description of a move. A move is stored as a byte in the following format:
34 * - bit 7 : 0 for valid entries (i.e. those containing a move info,
35 * 1 for invalid entries
36 * - bits 6..4: row
37 * - bit 3 : 0 if it's white move, 1 if it's black move
38 * - bits 2..0: column
40 typedef unsigned char move_t;
42 #define MOVE_ROW(h) (((h) >> 4) & 0x7)
43 #define MOVE_COL(h) ((h) & 0x7)
44 #define MOVE_PLAYER(h) (((h) & 0x8) ? BLACK : WHITE)
45 #define MAKE_MOVE(r,c,player) ( ((r)<<4) | ((c)&0x7) | \
46 ((player) == WHITE ? 0 : 0x8) )
47 #define MOVE_INVALID 0x80
50 /* State of a board */
51 typedef struct _reversi_board_t {
52 /* The current state of the game (BLACK/WHITE/FREE) */
53 int board[BOARD_SIZE][BOARD_SIZE];
55 /* Game history. First move (mostly, but not necessarily, black) is stored
56 * in history[0], second move (mostly, but not necessarily, white) is
57 * stored in history[1] etc.
59 move_t history[BOARD_SIZE*BOARD_SIZE - INIT_STONES];
61 const struct plugin_api *rb;
62 } reversi_board_t;
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,
78 const int player);
79 int reversi_count_passes(const reversi_board_t *game, const int player);
82 #endif