summaryrefslogtreecommitdiff
path: root/apps/plugins/reversi/reversi-game.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/reversi/reversi-game.h')
-rw-r--r--apps/plugins/reversi/reversi-game.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/apps/plugins/reversi/reversi-game.h b/apps/plugins/reversi/reversi-game.h
new file mode 100644
index 0000000000..a7d0329d1f
--- /dev/null
+++ b/apps/plugins/reversi/reversi-game.h
@@ -0,0 +1,75 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (c) 2006 Alexander Levin
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19
20#ifndef _REVERSI_GAME_H
21#define _REVERSI_GAME_H
22
23#include <stdbool.h>
24
25#define WHITE 1 /* WHITE constant, it always plays first (as in chess) */
26#define BLACK 2 /* BLACK constant */
27#define FREE 0 /* Free place constant */
28
29#define BOARD_SIZE 8
30#define INIT_STONES 4
31
32/* Description of a move. A move is stored as a byte in the following format:
33 * - bit 7 : 0 for valid entries (i.e. those containing a move info,
34 * 1 for invalid entries
35 * - bits 6..4: row
36 * - bit 3 : 0 if it's white move, 1 if it's black move
37 * - bits 2..0: column
38 */
39typedef unsigned char move_t;
40
41#define MOVE_ROW(h) (((h) >> 4) & 0x7)
42#define MOVE_COL(h) ((h) & 0x7)
43#define MOVE_PLAYER(h) (((h) & 0x8) ? BLACK : WHITE)
44#define MAKE_MOVE(r,c,player) ( ((r)<<4) | ((c)&0x7) | \
45 ((player) == WHITE ? 0 : 0x8) )
46#define MOVE_INVALID 0x80
47
48
49/* State of a board */
50typedef struct _reversi_board_t {
51 /* The current state of the game (BLACK/WHITE/FREE) */
52 char board[BOARD_SIZE][BOARD_SIZE];
53
54 /* Game history. First move (mostly, but not necessarily, black) is stored
55 * in history[0], second move (mostly, but not necessarily, white) is
56 * stored in history[1] etc.
57 */
58 move_t history[BOARD_SIZE*BOARD_SIZE - INIT_STONES];
59} reversi_board_t;
60
61
62void reversi_init_game(reversi_board_t *game);
63int reversi_flipped_color(const int color);
64bool reversi_game_is_finished(const reversi_board_t *game);
65int reversi_get_turn(const reversi_board_t *game);
66int reversi_count_occupied_cells(const reversi_board_t *game,
67 int *white_count, int *black_count);
68int reversi_count_moves(const reversi_board_t *game);
69int reversi_count_white_moves(const reversi_board_t *game);
70int reversi_count_black_moves(const reversi_board_t *game);
71int reversi_make_move(reversi_board_t *game, const int row,
72 const int col, const int player);
73
74
75#endif