diff options
author | Antoine Cellerier <dionoea@videolan.org> | 2007-06-30 20:04:42 +0000 |
---|---|---|
committer | Antoine Cellerier <dionoea@videolan.org> | 2007-06-30 20:04:42 +0000 |
commit | b4b34f0c0723c29f368d7793889ef92bc6404a52 (patch) | |
tree | 0dfeb4a5b0a2a54f85a0deb227baafed92ae6549 /apps/plugins/reversi/reversi-game.h | |
parent | 9789acc3e04a8cd23fe0a2359a0fb8801ee7255e (diff) | |
download | rockbox-b4b34f0c0723c29f368d7793889ef92bc6404a52.tar.gz rockbox-b4b34f0c0723c29f368d7793889ef92bc6404a52.zip |
FS #6509 - "Plugin for playing reversi game" by Alexander Levin + changes by me to make it compile due to the menu api change and compile for e200.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13745 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/reversi/reversi-game.h')
-rw-r--r-- | apps/plugins/reversi/reversi-game.h | 75 |
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 | */ | ||
39 | typedef 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 */ | ||
50 | typedef 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 | |||
62 | void reversi_init_game(reversi_board_t *game); | ||
63 | int reversi_flipped_color(const int color); | ||
64 | bool reversi_game_is_finished(const reversi_board_t *game); | ||
65 | int reversi_get_turn(const reversi_board_t *game); | ||
66 | int reversi_count_occupied_cells(const reversi_board_t *game, | ||
67 | int *white_count, int *black_count); | ||
68 | int reversi_count_moves(const reversi_board_t *game); | ||
69 | int reversi_count_white_moves(const reversi_board_t *game); | ||
70 | int reversi_count_black_moves(const reversi_board_t *game); | ||
71 | int reversi_make_move(reversi_board_t *game, const int row, | ||
72 | const int col, const int player); | ||
73 | |||
74 | |||
75 | #endif | ||