Tue, 08 Sep 2026 14:34:48 +0200
test and ensure C++ compatibility of chess headers
do not need C++ compatibility of terminal-chess application, though
relates to #986
|
10
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
1 | /* |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
2 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
3 | * |
|
55
54ea19938d57
updated copyright and version info
Mike Becker <universe@uap-core.de>
parents:
50
diff
changeset
|
4 | * Copyright 2016 Mike Becker. All rights reserved. |
|
10
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
5 | * |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
6 | * Redistribution and use in source and binary forms, with or without |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
7 | * modification, are permitted provided that the following conditions are met: |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
8 | * |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
9 | * 1. Redistributions of source code must retain the above copyright |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
10 | * notice, this list of conditions and the following disclaimer. |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
11 | * |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
13 | * notice, this list of conditions and the following disclaimer in the |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
14 | * documentation and/or other materials provided with the distribution. |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
15 | * |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
26 | * POSSIBILITY OF SUCH DAMAGE. |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
27 | * |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
28 | */ |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
29 | |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
30 | #ifndef RULES_H |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
31 | #define RULES_H |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
32 | |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
33 | #include <stdlib.h> |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
34 | #include <stdint.h> |
|
80
b980a7192b5a
replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents:
78
diff
changeset
|
35 | #include <stdbool.h> |
|
10
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
36 | |
|
48
0cedda2544da
added return code to move validation (for more informative messages) + fixed a bug where simulations added movelist items to the original gamestate
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
37 | #define VALID_MOVE_SYNTAX 0 |
|
0cedda2544da
added return code to move validation (for more informative messages) + fixed a bug where simulations added movelist items to the original gamestate
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
38 | #define VALID_MOVE_SEMANTICS 0 /* use same code for a success */ |
|
0cedda2544da
added return code to move validation (for more informative messages) + fixed a bug where simulations added movelist items to the original gamestate
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
39 | #define INVALID_MOVE_SYNTAX 1 |
|
154
5336e985bd69
rename INVALID_POSITION to PIECE_NOT_FOUND
Mike Becker <universe@uap-core.de>
parents:
153
diff
changeset
|
40 | #define PIECE_NOT_FOUND 2 |
|
48
0cedda2544da
added return code to move validation (for more informative messages) + fixed a bug where simulations added movelist items to the original gamestate
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
41 | #define AMBIGUOUS_MOVE 3 |
|
0cedda2544da
added return code to move validation (for more informative messages) + fixed a bug where simulations added movelist items to the original gamestate
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
42 | #define NEED_PROMOTION 4 |
|
0cedda2544da
added return code to move validation (for more informative messages) + fixed a bug where simulations added movelist items to the original gamestate
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
43 | #define PIECE_PINNED 5 |
|
0cedda2544da
added return code to move validation (for more informative messages) + fixed a bug where simulations added movelist items to the original gamestate
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
44 | #define KING_IN_CHECK 6 |
|
0cedda2544da
added return code to move validation (for more informative messages) + fixed a bug where simulations added movelist items to the original gamestate
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
45 | #define KING_MOVES_INTO_CHECK 7 |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
46 | #define MISSING_CHECK 8 |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
47 | #define MISSING_CHECKMATE 9 |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
48 | #define INVALID_CHECK 10 |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
49 | #define INVALID_CHECKMATE 11 |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
50 | #define RULES_VIOLATED 32 |
|
16
a298c6637c30
introduced status codes for get_location to produce detailed error messages + added knight rules
Mike Becker <universe@uap-core.de>
parents:
10
diff
changeset
|
51 | |
|
224
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
52 | #ifdef __cplusplus |
|
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
53 | extern "C" { |
|
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
54 | #define enum_byte(name) enum e##name : uint8_t |
|
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
55 | #define typedef_enum_byte(name) typedef enum e##name name |
|
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
56 | #elif __STDC_VERSION__ < 202310L |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
57 | /* since #warning is also a C23 feature, the only hope is this: */ |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
58 | #pragma GCC warning "Type safety for enums is only available since C23" |
| 194 | 59 | #define enum_byte(name) enum e##name |
| 60 | #define typedef_enum_byte(name) typedef uint8_t name | |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
61 | #else |
| 194 | 62 | #define enum_byte(name) enum e##name : uint8_t |
| 63 | #define typedef_enum_byte(name) typedef enum e##name name | |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
64 | #endif |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
65 | |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
66 | #define ENPASSANT_THREAT 0x40u |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
67 | |
| 194 | 68 | enum_byte(Color) { |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
69 | WHITE = 0x10u, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
70 | BLACK = 0x20u, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
71 | }; |
| 194 | 72 | typedef_enum_byte(Color); |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
73 | |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
74 | static inline Color opponent_color(Color color) { |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
75 | return color == WHITE ? BLACK : WHITE; |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
76 | } |
| 129 | 77 | |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
78 | #define PIECE_MASK 0x0Fu |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
79 | #define COLOR_MASK 0x30u |
| 129 | 80 | |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
81 | #define PAWN 0x01u |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
82 | #define ROOK 0x02u |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
83 | #define KNIGHT 0x03u |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
84 | #define BISHOP 0x04u |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
85 | #define QUEEN 0x05u |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
86 | #define KING 0x06u |
| 129 | 87 | |
| 194 | 88 | enum_byte(Piece) { |
|
224
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
89 | NOPIECE = 0, |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
90 | WPAWN = WHITE|PAWN, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
91 | WROOK = WHITE|ROOK, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
92 | WKNIGHT = WHITE|KNIGHT, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
93 | WBISHOP = WHITE|BISHOP, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
94 | WQUEEN = WHITE|QUEEN, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
95 | WKING = WHITE|KING, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
96 | BPAWN = BLACK|PAWN, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
97 | BROOK = BLACK|ROOK, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
98 | BKNIGHT = BLACK|KNIGHT, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
99 | BBISHOP = BLACK|BISHOP, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
100 | BQUEEN = BLACK|QUEEN, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
101 | BKING = BLACK|KING, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
102 | }; |
| 194 | 103 | typedef_enum_byte(Piece); |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
104 | |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
105 | #define POS_UNSPECIFIED 255u |
| 194 | 106 | enum_byte(Rank) { |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
107 | RANK_1 = 0, RANK_2, RANK_3, RANK_4, RANK_5, RANK_6, RANK_7, RANK_8, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
108 | RANK_UNSPECIFIED = POS_UNSPECIFIED |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
109 | }; |
| 194 | 110 | typedef_enum_byte(Rank); |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
111 | |
| 194 | 112 | enum_byte(File) { |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
113 | FILE_A = 0, FILE_B, FILE_C, FILE_D, FILE_E, FILE_F, FILE_G, FILE_H, |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
114 | FILE_UNSPECIFIED = POS_UNSPECIFIED |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
115 | }; |
| 194 | 116 | typedef_enum_byte(File); |
| 129 | 117 | |
| 118 | typedef uint8_t Board[8][8]; | |
| 119 | ||
| 120 | struct movetimeval { | |
|
181
8bda076d0a16
simplify how the elapsed move time is recorded
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
121 | uint64_t sec; |
|
8bda076d0a16
simplify how the elapsed move time is recorded
Mike Becker <universe@uap-core.de>
parents:
179
diff
changeset
|
122 | int32_t usec; /* important that this is signed b/c potential carry */ |
| 129 | 123 | }; |
| 124 | ||
| 125 | typedef struct { | |
|
182
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
126 | char string[8]; |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
127 | struct movetimeval timestamp; /* TODO: remove this from the struct */ |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
128 | uint64_t movetime; /* the time for this move in microseconds */ |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
129 | Piece piece; |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
130 | File fromfile; |
| 194 | 131 | Rank fromrank; |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
132 | File tofile; |
| 194 | 133 | Rank torank; |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
134 | Piece promotion; |
|
182
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
135 | bool check; /* must always be set if checkmate is set */ |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
136 | bool checkmate; |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
137 | bool capture; |
| 129 | 138 | } Move; |
| 139 | ||
| 140 | typedef struct { | |
|
184
93c81539b702
fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents:
182
diff
changeset
|
141 | Color servercolor; |
|
93c81539b702
fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents:
182
diff
changeset
|
142 | /** play with timecontrol? */ |
|
93c81539b702
fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents:
182
diff
changeset
|
143 | bool timecontrol; |
|
93c81539b702
fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents:
182
diff
changeset
|
144 | /** If timecontrol is true, initial clock time in seconds */ |
| 129 | 145 | uint16_t time; |
|
184
93c81539b702
fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents:
182
diff
changeset
|
146 | /** If timecontrol is true, time added per move in seconds */ |
| 129 | 147 | uint16_t addtime; |
|
184
93c81539b702
fix byte-order problem in GameInfo and change decline reason to one byte
Mike Becker <universe@uap-core.de>
parents:
182
diff
changeset
|
148 | /** If timecontrol is true, delay before the clock starts ticking down */ |
|
130
3fc6b1d6cbe9
implement optional delay - resolves #820
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
149 | uint16_t delay; |
| 129 | 150 | } GameInfo; |
| 151 | ||
|
130
3fc6b1d6cbe9
implement optional delay - resolves #820
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
152 | /** The buffer length for player names in GameState structures. */ |
| 129 | 153 | #define PLAYER_NAME_BUFLEN 32 |
| 154 | ||
| 155 | typedef struct { | |
|
157
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
156 | /** optional name of the white player - only used for PGN exports */ |
|
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
157 | char wname[PLAYER_NAME_BUFLEN]; |
|
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
158 | /** optional name of the black player - only used for PGN exports */ |
|
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
159 | char bname[PLAYER_NAME_BUFLEN]; |
|
130
3fc6b1d6cbe9
implement optional delay - resolves #820
Mike Becker <universe@uap-core.de>
parents:
129
diff
changeset
|
160 | GameInfo info; |
| 129 | 161 | Board board; |
| 162 | Move* moves; | |
|
157
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
163 | /** starting position in FEN notation */ |
|
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
164 | char *fen_start; |
|
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
165 | /** array of subsequent positions in FEN notation. |
|
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
166 | * The capacity and element count are identical to the moves array. |
|
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
167 | */ |
|
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
168 | char **fen; |
| 129 | 169 | /** capacity of the move array */ |
|
157
07cbfc477b22
add FEN history to the game state
Mike Becker <universe@uap-core.de>
parents:
154
diff
changeset
|
170 | unsigned int movecapacity; |
| 129 | 171 | /** number of (half-)moves (counting BOTH colors) */ |
| 172 | unsigned int movecount; | |
|
218
1e9751f8eb0d
add function to reconstruct a board from a FEN string
Mike Becker <universe@uap-core.de>
parents:
216
diff
changeset
|
173 | /** number of half-moves that have been played before reaching fen_start */ |
|
219
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
174 | unsigned int move_start; |
|
218
1e9751f8eb0d
add function to reconstruct a board from a FEN string
Mike Becker <universe@uap-core.de>
parents:
216
diff
changeset
|
175 | /** number of half-moves w/o capture or pawn move played before fen_start */ |
|
1e9751f8eb0d
add function to reconstruct a board from a FEN string
Mike Becker <universe@uap-core.de>
parents:
216
diff
changeset
|
176 | unsigned int fifty_cntr_start; |
| 129 | 177 | /** a premove that shall be evaluated next time it's our turn */ |
| 178 | char premove[8]; | |
| 179 | bool checkmate; | |
| 180 | bool stalemate; | |
|
131
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
181 | bool threefold; |
|
179
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
182 | /** drawn due to insufficient material on both sides */ |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
183 | bool nomaterial; |
|
171
09f18c3316f9
add expected game result to test-real-pgn suite
Mike Becker <universe@uap-core.de>
parents:
170
diff
changeset
|
184 | /** flag is only set when players agreed on remis */ |
| 129 | 185 | bool remis; |
| 186 | bool wresign; | |
| 187 | bool bresign; | |
| 188 | /** this flag is only supposed to be set when the opponent disconnects */ | |
| 189 | bool ragequit; | |
| 190 | bool review; | |
|
216
d0c3d3016650
make castling rights part of the game state
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
191 | struct { |
|
d0c3d3016650
make castling rights part of the game state
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
192 | bool K; /* white lost right to castle king-side */ |
|
d0c3d3016650
make castling rights part of the game state
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
193 | bool Q; /* white lost right to castle queen-side */ |
|
d0c3d3016650
make castling rights part of the game state
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
194 | bool k; /* black lost right to castle king-side */ |
|
d0c3d3016650
make castling rights part of the game state
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
195 | bool q; /* black lost right to castle queen-side */ |
|
d0c3d3016650
make castling rights part of the game state
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
196 | } castling; /* castling rights */ |
| 129 | 197 | } GameState; |
| 198 | ||
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
199 | #define piece_type(piece) ((uint8_t)(piece)&PIECE_MASK) |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
200 | #define piece_color(piece) ((uint8_t)(piece)&COLOR_MASK) |
|
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
201 | #define mkpiece(type,color) (Piece)((type)|(color)) |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
202 | |
|
153
bad2d6d4b861
fix wrong error message when move indices are invalid
Mike Becker <universe@uap-core.de>
parents:
147
diff
changeset
|
203 | /** Checks if the index is specified and valid. */ |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
204 | static inline bool isidx(uint8_t idx) {return idx < 8;} |
|
153
bad2d6d4b861
fix wrong error message when move indices are invalid
Mike Becker <universe@uap-core.de>
parents:
147
diff
changeset
|
205 | /** Checks if the index is unspecified or valid. */ |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
206 | static inline bool isidxr(uint8_t idx) {return idx==POS_UNSPECIFIED || idx<8;} |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
207 | |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
208 | static inline bool isfile(char file) {return file >= 'a' && file <= 'h';} |
| 194 | 209 | static inline bool isrank(char rank) {return rank >= '1' && rank <= '8';} |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
210 | |
|
224
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
211 | static inline Rank rankidx(char rank) {return (Rank)(rank-'1');} |
|
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
212 | static inline File fileidx(char file) {return (File)(file-'a');} |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
213 | |
| 194 | 214 | static inline char rankchr(Rank rank) {return (char)rank+'1';} |
|
193
d1420f5c5704
increase type safety + add backwards compatibility including C99
Mike Becker <universe@uap-core.de>
parents:
186
diff
changeset
|
215 | static inline char filechr(File file) {return (char)file+'a';} |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
216 | |
|
161
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
217 | |
|
219
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
218 | /** |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
219 | * Returns the current move number. |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
220 | * |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
221 | * @param gamestate the current game state |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
222 | * @return the full move number of the move that is next to play |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
223 | */ |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
224 | static inline unsigned move_number(const GameState *gamestate) { |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
225 | return 1 + (gamestate->move_start + gamestate->movecount) / 2; |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
226 | } |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
227 | |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
228 | /** |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
229 | * Returns the current half-move number. |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
230 | * |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
231 | * The counter starts with one. |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
232 | * |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
233 | * @param gamestate the current game state |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
234 | * @return the half-move number of the move that is next to play |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
235 | */ |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
236 | static inline unsigned move_number_half(const GameState *gamestate) { |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
237 | return 1 + gamestate->move_start + gamestate->movecount; |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
238 | } |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
239 | |
|
161
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
240 | static inline void enpassant_threat_add(GameState *gamestate, |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
241 | File file, Rank rank) { |
| 194 | 242 | gamestate->board[rank][file] |= ENPASSANT_THREAT; |
|
161
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
243 | } |
|
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
244 | |
|
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
245 | static inline void enpassant_threat_remove(GameState *gamestate, |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
246 | File file, Rank rank) { |
| 194 | 247 | gamestate->board[rank][file] &= ~ENPASSANT_THREAT; |
|
161
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
248 | } |
|
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
249 | |
|
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
250 | static inline bool enpassant_threat_exists(const GameState *gamestate, |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
251 | File file, Rank rank) { |
| 194 | 252 | return gamestate->board[rank][file] & ENPASSANT_THREAT; |
|
161
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
253 | } |
|
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
254 | |
|
173
e541b6002933
implement first naive draw by threefold repetition
Mike Becker <universe@uap-core.de>
parents:
171
diff
changeset
|
255 | static inline bool is_game_drawn(const GameState *gamestate) { |
|
179
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
256 | return gamestate->threefold || gamestate->stalemate |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
257 | || gamestate->nomaterial || gamestate->remis; |
|
173
e541b6002933
implement first naive draw by threefold repetition
Mike Becker <universe@uap-core.de>
parents:
171
diff
changeset
|
258 | } |
|
e541b6002933
implement first naive draw by threefold repetition
Mike Becker <universe@uap-core.de>
parents:
171
diff
changeset
|
259 | |
|
161
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
260 | static inline bool is_game_running(const GameState *gamestate) { |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
261 | return !(gamestate->checkmate || gamestate->wresign || gamestate->bresign |
|
173
e541b6002933
implement first naive draw by threefold repetition
Mike Becker <universe@uap-core.de>
parents:
171
diff
changeset
|
262 | || is_game_drawn(gamestate) || gamestate->review); |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
263 | } |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
264 | |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
265 | static inline bool is_check_position(const GameState *gamestate) { |
|
216
d0c3d3016650
make castling rights part of the game state
Mike Becker <universe@uap-core.de>
parents:
195
diff
changeset
|
266 | if (gamestate->movecount == 0) return false; |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
267 | return gamestate->moves[gamestate->movecount - 1].check; |
|
161
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
268 | } |
|
3ff96fec144a
convert some macros to static inline functions
Mike Becker <universe@uap-core.de>
parents:
160
diff
changeset
|
269 | |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
270 | static inline Color field_color(File f, Rank r) { |
|
219
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
271 | return ((unsigned)r + (unsigned)f) % 2 == 0 ? BLACK : WHITE; |
|
179
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
272 | } |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
273 | |
| 129 | 274 | /** |
| 275 | * Initializes a game state and prepares the chess board. | |
| 276 | * @param gamestate the game state to initialize | |
| 277 | */ | |
| 278 | void gamestate_init(GameState *gamestate); | |
| 279 | ||
| 280 | /** | |
| 281 | * Cleans up a game state and frees the memory for the movement list. | |
| 282 | * @param gamestate the game state to clean up | |
| 283 | */ | |
| 284 | void gamestate_cleanup(GameState *gamestate); | |
| 285 | ||
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
286 | /** |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
287 | * Maps a character to a piece. |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
288 | * |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
289 | * Does not work for pawns, since they don't have a character. |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
290 | * |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
291 | * @param c one of R,N,B,Q,K |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
292 | * @param color the piece color |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
293 | * @return the specified piece or zero when the character is invalid |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
294 | */ |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
295 | Piece getpiece(char c, Color color); |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
296 | |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
297 | /** |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
298 | * Maps a piece to a character. |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
299 | * |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
300 | * Does not work for pawns, since they don't have a character. |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
301 | * |
| 69 | 302 | * @param piece may have color or additional flags |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
303 | * @return character value for the specified piece |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
304 | */ |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
305 | char getpiecechr(Piece piece); |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
306 | |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
307 | /** |
| 69 | 308 | * Maps a piece to a unicode character sequence. |
| 309 | * | |
| 310 | * The returned unicode is for black pieces. | |
| 311 | * You may colorize the output by setting the terminal foreground color. | |
| 312 | * | |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
313 | * @param piece the piece to display |
| 69 | 314 | * @return unicode character sequence for the specified piece |
| 315 | */ | |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
316 | char* getpieceunicode(Piece piece); |
| 69 | 317 | |
| 318 | /** | |
|
133
c58ae152733e
simplify FEN generation and add current_color() function to rules
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
319 | * Returns the color of the player who is next to move. |
|
c58ae152733e
simplify FEN generation and add current_color() function to rules
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
320 | * |
|
c58ae152733e
simplify FEN generation and add current_color() function to rules
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
321 | * @param gamestate the current game state |
|
c58ae152733e
simplify FEN generation and add current_color() function to rules
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
322 | * @return the color of the player who is next to move |
|
c58ae152733e
simplify FEN generation and add current_color() function to rules
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
323 | */ |
|
219
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
324 | static inline Color current_color(const GameState *gamestate) { |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
325 | return move_number_half(gamestate) % 2 ? WHITE : BLACK; |
|
24b866230dd4
identify all and fix some occurrences where the new move_start offset matters
Mike Becker <universe@uap-core.de>
parents:
218
diff
changeset
|
326 | } |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
327 | |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
328 | /** |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
329 | * Returns the piece at the specified position. |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
330 | * |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
331 | * @param gamestate the current game state |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
332 | * @param file the file |
| 194 | 333 | * @param rank the rank |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
334 | * @return the piece at the specified position |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
335 | */ |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
336 | Piece piece_at(const GameState *gamestate, File file, Rank rank); |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
337 | |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
338 | /** |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
339 | * Places a piece at the specified position in the current game state. |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
340 | * |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
341 | * @param gamestate the current game state |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
342 | * @param file the file |
| 194 | 343 | * @param rank the rank |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
344 | * @param piece the piece to place at the specified position |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
345 | */ |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
346 | void piece_set(GameState *gamestate, File file, Rank rank, Piece piece); |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
347 | |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
348 | /** |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
349 | * Removes the piece at the specified position in the current game state. |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
350 | * |
|
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
351 | * @param gamestate the current game state |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
352 | * @param file the file |
| 194 | 353 | * @param rank the rank |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
354 | */ |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
355 | static inline void piece_remove(GameState *gamestate, File file, Rank rank) { |
|
224
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
356 | piece_set(gamestate, file, rank, NOPIECE); |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
357 | } |
|
133
c58ae152733e
simplify FEN generation and add current_color() function to rules
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
358 | |
|
170
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
359 | typedef size_t(*moves_generator_func)(const GameState *gamestate, |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
360 | Color c, File f, Rank r, Move *moves); |
|
169
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
361 | |
|
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
362 | /** |
|
170
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
363 | * Calculates all allowed moves for a specific piece. |
|
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
364 | * |
|
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
365 | * Use the macros for the specific pieces instead. |
|
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
366 | * |
|
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
367 | * @param gamestate the current gamestate |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
368 | * @param f the file of the piece |
| 194 | 369 | * @param r the rank of the piece |
|
170
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
370 | * @param moves target array for the list of moves |
|
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
371 | * @return the number of moves stored in the @p moves array |
|
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
372 | */ |
|
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
373 | size_t piece_moves_allowed(const GameState *gamestate, |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
374 | File f, Rank r, Move *moves); |
|
170
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
375 | |
|
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
376 | /** |
|
169
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
377 | * Internal function used to filter out illegal moves. |
|
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
378 | * |
|
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
379 | * Use the macros for the specific pieces instead. |
|
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
380 | * |
|
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
381 | * @param gamestate the current gamestate |
|
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
382 | * @param c color of the piece |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
383 | * @param f the file of the piece |
| 194 | 384 | * @param r the rank of the piece |
|
169
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
385 | * @param moves target array for the list of moves |
|
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
386 | * @param func a function that unconditionally generates the moves |
|
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
387 | * @return the number of moves stored in the @p moves array |
|
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
388 | */ |
|
170
bde99d803caf
implements stalemate detection + fixes missing const qualifier in new *_moves[_allowed] API
Mike Becker <universe@uap-core.de>
parents:
169
diff
changeset
|
389 | size_t filter_moves_allowed(const GameState *gamestate, |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
390 | Color c, File f, Rank r, Move *moves, moves_generator_func func); |
|
169
9962f5d98764
add functions to list the possible moves for each piece
Mike Becker <universe@uap-core.de>
parents:
168
diff
changeset
|
391 | |
|
133
c58ae152733e
simplify FEN generation and add current_color() function to rules
Mike Becker <universe@uap-core.de>
parents:
131
diff
changeset
|
392 | /** |
|
167
fd1d3f0a7a73
fix regression: pieces could not threaten fields when pinned
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
393 | * Determines a list of theoretically possible moves to the specified field. |
|
fd1d3f0a7a73
fix regression: pieces could not threaten fields when pinned
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
394 | * |
|
fd1d3f0a7a73
fix regression: pieces could not threaten fields when pinned
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
395 | * This will also list moves for pieces that are actually pinned. |
|
168
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
396 | * Use get_real_candidates() to get only moves for pieces that are not pinned. |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
397 | * |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
398 | * The out-parameters may both be NULL, but if any of them is set, the other |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
399 | * must be set, too. |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
400 | * |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
401 | * @param gamestate the current game state |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
402 | * @param file file of the field to check |
| 194 | 403 | * @param rank rank of the field to check |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
404 | * @param color the color of the piece that should move to the field |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
405 | * @param moves the array where to store the moves |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
406 | * (must be large enough, 16 is always enough) |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
407 | * @param movecount a pointer where the number of moves is stored |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
408 | * @return true, if any piece of the specified color can move to the specified |
|
167
fd1d3f0a7a73
fix regression: pieces could not threaten fields when pinned
Mike Becker <universe@uap-core.de>
parents:
166
diff
changeset
|
409 | * field regardless of being pinned |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
410 | */ |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
411 | bool get_candidates(const GameState *gamestate, File file, Rank rank, |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
412 | Color color, Move* moves, size_t* movecount); |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
413 | |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
414 | /** |
|
168
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
415 | * Determines a list of possible moves to the specified field. |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
416 | * |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
417 | * This cannot be used to check if a piece covers / threatens a field because |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
418 | * this is also possible when the piece is pinned. Use get_candidates() for a |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
419 | * list of possible moves regardless of pins. |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
420 | * |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
421 | * The out-parameters may both be NULL, but if any of them is set, the other |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
422 | * must be set, too. |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
423 | * |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
424 | * @param gamestate the current game state |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
425 | * @param file file of the field to check |
| 194 | 426 | * @param rank rank of the field to check |
|
168
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
427 | * @param color the color of the piece that should move to the field |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
428 | * @param moves the array where to store the moves |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
429 | * (must be large enough, 16 is always enough) |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
430 | * @param movecount a pointer where the number of moves is stored |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
431 | * @return true, if any piece of the specified color can move to the specified |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
432 | * field and is not pinned |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
433 | */ |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
434 | bool get_real_candidates(const GameState *gamestate, File file, Rank rank, |
|
168
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
435 | Color color, Move* moves, size_t* movecount); |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
436 | |
|
663676cfef6e
fix unnecessary disambiguation + simplify get_real_threats() code
Mike Becker <universe@uap-core.de>
parents:
167
diff
changeset
|
437 | /** |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
438 | * Checks, if a specified field is threatened by a piece of a certain color. |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
439 | * |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
440 | * A field is threatened, if there is a piece of the specified color that could |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
441 | * capture an opponent piece on this field, regardless of being pinned. |
| 25 | 442 | * |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
443 | * The out-parameters may both be NULL, but if any of them is set, the other |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
444 | * must be set, too. |
|
28
0c1371488d87
NEED TESTING: implemented check and checkmate - TODO: avoid checkmate by moving another piece in between
Mike Becker <universe@uap-core.de>
parents:
27
diff
changeset
|
445 | * |
|
0c1371488d87
NEED TESTING: implemented check and checkmate - TODO: avoid checkmate by moving another piece in between
Mike Becker <universe@uap-core.de>
parents:
27
diff
changeset
|
446 | * @param gamestate the current game state |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
447 | * @param file file of the field to check |
| 194 | 448 | * @param rank rank of the field to check |
|
28
0c1371488d87
NEED TESTING: implemented check and checkmate - TODO: avoid checkmate by moving another piece in between
Mike Becker <universe@uap-core.de>
parents:
27
diff
changeset
|
449 | * @param color the color of the piece that should threaten the field |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
450 | * @param threats the array where to store the threats |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
451 | * (must be large enough, 16 is always enough) |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
452 | * @param threatcount a pointer where the count of threats is stored |
|
80
b980a7192b5a
replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents:
78
diff
changeset
|
453 | * @return true, if any piece of the specified color threatens the specified |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
454 | * field |
|
28
0c1371488d87
NEED TESTING: implemented check and checkmate - TODO: avoid checkmate by moving another piece in between
Mike Becker <universe@uap-core.de>
parents:
27
diff
changeset
|
455 | */ |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
456 | bool get_threats(const GameState *gamestate, File file, Rank rank, |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
457 | Color color, Move* threats, size_t* threatcount); |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
458 | |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
459 | /** |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
460 | * Checks, if a specified field is threatened by a piece of a certain color AND |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
461 | * if this piece is not pinned and therefore able to perform the move. |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
462 | * |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
463 | * The out-parameters may both be NULL, but if any of them is set, the other |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
464 | * must be set, too. |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
465 | * |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
466 | * @param gamestate the current game state |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
467 | * @param file file of the field to check |
| 194 | 468 | * @param rank rank of the field to check |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
469 | * @param color the color of the piece that should threaten the field |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
470 | * @param threats the array where to store the threats |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
471 | * (must be large enough, 16 is always enough) |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
472 | * @param threatcount a pointer where the count of threats is stored |
|
80
b980a7192b5a
replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents:
78
diff
changeset
|
473 | * @return true, if any piece of the specified color threatens the specified |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
474 | * field and is not pinned |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
475 | */ |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
476 | bool get_real_threats(const GameState *gamestate, File file, Rank rank, |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
477 | Color color, Move* threats, size_t* threatcount); |
|
28
0c1371488d87
NEED TESTING: implemented check and checkmate - TODO: avoid checkmate by moving another piece in between
Mike Becker <universe@uap-core.de>
parents:
27
diff
changeset
|
478 | |
|
0c1371488d87
NEED TESTING: implemented check and checkmate - TODO: avoid checkmate by moving another piece in between
Mike Becker <universe@uap-core.de>
parents:
27
diff
changeset
|
479 | /** |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
480 | * Checks, if a specified field is threatened by a piece of a certain color. |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
481 | * |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
482 | * A field is threatened, if there is a piece of the specified color that could |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
483 | * capture an opponent piece on this field, regardless of being pinned. |
|
28
0c1371488d87
NEED TESTING: implemented check and checkmate - TODO: avoid checkmate by moving another piece in between
Mike Becker <universe@uap-core.de>
parents:
27
diff
changeset
|
484 | * |
| 25 | 485 | * @param gamestate the current game state |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
486 | * @param file file of the field to check |
| 194 | 487 | * @param rank rank of the field to check |
| 25 | 488 | * @param color the color of the piece that should cover the field |
|
80
b980a7192b5a
replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents:
78
diff
changeset
|
489 | * @return true, if any piece of the specified color threatens the specified |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
490 | * field |
| 25 | 491 | */ |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
492 | #define is_covered(gamestate, file, rank, color) \ |
|
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
493 | get_threats(gamestate, file, rank, color, NULL, NULL) |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
494 | |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
495 | /** |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
496 | * Checks, if a specified field is attacked by a piece of a certain color. |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
497 | * |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
498 | * I.e. the field is threatened by a piece AND this piece is not pinned and |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
499 | * therefore able to perform the move. |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
500 | * |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
501 | * @param gamestate the current game state |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
502 | * @param file file of the field to check |
| 194 | 503 | * @param rank rank of the field to check |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
504 | * @param color the color of the piece that should cover the field |
|
80
b980a7192b5a
replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents:
78
diff
changeset
|
505 | * @return true, if any piece of the specified color threatens the specified |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
506 | * field and could capture an opponent piece |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
507 | */ |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
508 | #define is_attacked(gamestate, file, rank, color) \ |
|
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
509 | get_real_threats(gamestate, file, rank, color, NULL, NULL) |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
510 | |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
511 | /** |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
512 | * Checks, if a specified field is protected by a piece of a certain color. |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
513 | * |
|
166
1a9b662bc201
fix regression: pawns cannot block check threats
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
514 | * A field is protected, if any piece except the king can either capture on |
|
1a9b662bc201
fix regression: pawns cannot block check threats
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
515 | * that field or move to that field (and is not pinned). |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
516 | * |
|
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
517 | * @param gamestate the current game state |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
518 | * @param file file of the field to check |
| 194 | 519 | * @param rank rank of the field to check |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
520 | * @param color the color of the piece that should cover the field |
|
80
b980a7192b5a
replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents:
78
diff
changeset
|
521 | * @return true, if any piece (excluding the king) of the specified color |
|
166
1a9b662bc201
fix regression: pawns cannot block check threats
Mike Becker <universe@uap-core.de>
parents:
163
diff
changeset
|
522 | * can move to the specified field (including capturing moves) |
|
29
c6a1ad6cf749
fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents:
28
diff
changeset
|
523 | */ |
|
195
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
524 | bool is_protected(const GameState *gamestate, |
|
27d02ccb0cef
flip File and Rank parameters into correct order
Mike Becker <universe@uap-core.de>
parents:
194
diff
changeset
|
525 | File file, Rank rank, Color color); |
| 25 | 526 | |
| 527 | /** | |
|
47
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
528 | * Checks, if the specified move cannot be performed, because the piece is |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
529 | * either pinned or cannot remove the check. |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
530 | * |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
531 | * Note: in chess a piece is pinned, when it can't be moved because the move |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
532 | * would result in a check position. But this function <u>also</u> returns true, |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
533 | * if the king is already in check position and the specified move does not |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
534 | * protect the king. |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
535 | * |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
536 | * @param gamestate the current game state |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
537 | * @param move the move to check |
|
80
b980a7192b5a
replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents:
78
diff
changeset
|
538 | * @return true, if the move cannot be performed because the king would be in |
|
47
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
539 | * check after the move |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
540 | */ |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
541 | bool is_pinned(const GameState *gamestate, const Move *move); |
|
47
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
542 | |
|
d726e4b46c33
refactoring of getlocation mechanism for better short algebraic notation support (does now respect pinned pieces) + fixed a bug where a pawn could advance through a piece (e.g. e2e4 could jump over a piece on e3)
Mike Becker <universe@uap-core.de>
parents:
41
diff
changeset
|
543 | /** |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
544 | * Evaluates a move syntactically and stores the move data in the specified |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
545 | * object. |
|
115
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
546 | * |
|
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
547 | * When short algebraic notation is used, the source position is determined by |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
548 | * evaluating the allowed moves according to the current game state. |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
549 | * |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
550 | * This function expects correct notation of check and checkmate indicators. |
|
182
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
551 | * For a more lazy evaluation, use eval_move(). |
|
115
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
552 | * |
|
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
553 | * For a purely syntactic check, regardless of whether a piece exists that is |
|
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
554 | * allowed to move that way, use check_move(). |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
555 | * |
|
23
824c9522ce66
introduced game state structure
Mike Becker <universe@uap-core.de>
parents:
19
diff
changeset
|
556 | * @param gamestate the current game state |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
557 | * @param mstr the input string to parse |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
558 | * @param color the color of the player to evaluate the move for |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
559 | * @param move a pointer to object where the move data shall be stored |
|
48
0cedda2544da
added return code to move validation (for more informative messages) + fixed a bug where simulations added movelist items to the original gamestate
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
560 | * @return status code (see macros in this file for the list of codes) |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
561 | */ |
|
182
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
562 | int eval_move_strict(const GameState *gamestate, |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
563 | const char *mstr, Color color, Move *move); |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
564 | |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
565 | /** |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
566 | * Evaluates a move syntactically and stores the move data in the specified |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
567 | * object. |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
568 | * |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
569 | * When short algebraic notation is used, the source position is determined by |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
570 | * evaluating the allowed moves according to the current game state. |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
571 | * |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
572 | * This function automatically corrects missing or incorrect check/checkmate |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
573 | * indicators. Use eval_move_strict() if you want to keep the original notation. |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
574 | * |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
575 | * For a purely syntactic check, regardless of whether a piece exists that is |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
576 | * allowed to move that way, use check_move(). |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
577 | * |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
578 | * @param gamestate the current game state |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
579 | * @param mstr the input string to parse |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
580 | * @param color the color of the player to evaluate the move for |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
581 | * @param move a pointer to object where the move data shall be stored |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
582 | * @return status code (see macros in this file for the list of codes) |
|
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
583 | */ |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
584 | int eval_move(const GameState *gamestate, |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
585 | const char *mstr, Color color, Move *move); |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
586 | |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
587 | /** |
|
182
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
588 | * Calculates the move string within the specified move. |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
589 | * |
|
186
8230904458a7
fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents:
184
diff
changeset
|
590 | * The string calculated in short algebraic notation. |
|
8230904458a7
fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents:
184
diff
changeset
|
591 | * The @p gamestate is needed to determine how to disambiguate the move, |
|
8230904458a7
fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents:
184
diff
changeset
|
592 | * if necessary. |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
593 | * |
|
186
8230904458a7
fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents:
184
diff
changeset
|
594 | * Recommended to be called before apply_move() so that a clean |
|
8230904458a7
fix regression in network play: we have to transmit capture/check(mate) flags
Mike Becker <universe@uap-core.de>
parents:
184
diff
changeset
|
595 | * move string is added to the list of recorded moves. |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
596 | * |
|
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
597 | * @param gamestate the current game state |
|
182
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
598 | * @param move the move data |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
599 | */ |
|
182
04c65336777f
start fixing the network protocol
Mike Becker <universe@uap-core.de>
parents:
181
diff
changeset
|
600 | void format_move(const GameState *gamestate, Move *move); |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
601 | |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
602 | /** |
|
115
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
603 | * Syntactically checks a move without verifying that a piece exists that is |
|
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
604 | * allowed to move that way. |
|
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
605 | * |
|
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
606 | * @param mstr the input string to parse |
|
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
607 | * @param color the color of the player to evaluate the move for |
|
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
608 | * @return status code (see macros in this file for the list of codes) |
|
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
609 | */ |
|
160
f87832cba8b8
refactor rules.h / rules.c
Mike Becker <universe@uap-core.de>
parents:
157
diff
changeset
|
610 | int check_move(const char *mstr, Color color); |
|
115
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
611 | |
|
206201d544be
relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents:
107
diff
changeset
|
612 | /** |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
613 | * Validates move by applying chess rules. |
|
23
824c9522ce66
introduced game state structure
Mike Becker <universe@uap-core.de>
parents:
19
diff
changeset
|
614 | * @param gamestate the current game state |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
615 | * @param move the move to validate |
|
48
0cedda2544da
added return code to move validation (for more informative messages) + fixed a bug where simulations added movelist items to the original gamestate
Mike Becker <universe@uap-core.de>
parents:
47
diff
changeset
|
616 | * @return status code (see macros in this file for the list of codes) |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
617 | */ |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
618 | int validate_move(const GameState *gamestate, const Move *move); |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
619 | |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
620 | /** |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
621 | * Applies a move and deletes captured pieces. |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
622 | * |
|
23
824c9522ce66
introduced game state structure
Mike Becker <universe@uap-core.de>
parents:
19
diff
changeset
|
623 | * @param gamestate the current game state |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
624 | * @param move the move to apply |
|
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
625 | */ |
|
23
824c9522ce66
introduced game state structure
Mike Becker <universe@uap-core.de>
parents:
19
diff
changeset
|
626 | void apply_move(GameState *gamestate, Move *move); |
|
19
6a26114297a1
moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents:
18
diff
changeset
|
627 | |
|
99
231a79d93c0c
add API for calculating the clock for a specific move + fixes wrong handling of move time and increment in move 1
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
628 | /** |
|
122
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
629 | * Copies the state of the game at the specified move number. |
|
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
630 | * |
|
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
631 | * This function is helpful to generate a game state for reviewing past moves. |
|
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
632 | * |
|
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
633 | * @param gamestate the current game state |
|
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
634 | * @param move_number the half-move that would now be played |
|
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
635 | * @param replay the struct to populate with the state at the specified move |
|
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
636 | */ |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
637 | void gamestate_at_move(const GameState *gamestate, |
|
122
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
638 | unsigned move_number, GameState *replay); |
|
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
639 | |
|
e65d9b5e9324
implement interactive game review
Mike Becker <universe@uap-core.de>
parents:
115
diff
changeset
|
640 | /** |
|
99
231a79d93c0c
add API for calculating the clock for a specific move + fixes wrong handling of move time and increment in move 1
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
641 | * Returns the remaining time on the clock for the specified |
|
231a79d93c0c
add API for calculating the clock for a specific move + fixes wrong handling of move time and increment in move 1
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
642 | * half-move number. |
|
231a79d93c0c
add API for calculating the clock for a specific move + fixes wrong handling of move time and increment in move 1
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
643 | * |
|
231a79d93c0c
add API for calculating the clock for a specific move + fixes wrong handling of move time and increment in move 1
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
644 | * @param gamestate the current game state |
|
231a79d93c0c
add API for calculating the clock for a specific move + fixes wrong handling of move time and increment in move 1
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
645 | * @param move_number the half-move that is now going to be played |
|
231a79d93c0c
add API for calculating the clock for a specific move + fixes wrong handling of move time and increment in move 1
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
646 | * @return the remaining time - if time control is disabled, this function |
|
231a79d93c0c
add API for calculating the clock for a specific move + fixes wrong handling of move time and increment in move 1
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
647 | * always returns zero |
|
231a79d93c0c
add API for calculating the clock for a specific move + fixes wrong handling of move time and increment in move 1
Mike Becker <universe@uap-core.de>
parents:
87
diff
changeset
|
648 | */ |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
649 | uint16_t remaining_movetime2(const GameState *gamestate, unsigned move_number); |
| 33 | 650 | |
| 651 | /** | |
| 652 | * Returns the remaining time on the clock for the specified player. | |
| 653 | * | |
| 654 | * @param gamestate the current game state | |
| 655 | * @param color either BLACK or WHITE | |
| 656 | * @return the remaining time - if time control is disabled, this function | |
| 657 | * always returns zero | |
| 658 | */ | |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
659 | uint16_t remaining_movetime(const GameState *gamestate, Color color); |
| 33 | 660 | |
|
100
685af47592b5
add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents:
99
diff
changeset
|
661 | /** |
|
685af47592b5
add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents:
99
diff
changeset
|
662 | * Converts clock time to string. |
|
685af47592b5
add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents:
99
diff
changeset
|
663 | * |
|
685af47592b5
add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents:
99
diff
changeset
|
664 | * @param time the time to format |
|
685af47592b5
add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents:
99
diff
changeset
|
665 | * @param str the target buffer (should be at least 10 chars large) |
|
685af47592b5
add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents:
99
diff
changeset
|
666 | * @param always_hours if hours should always be printed |
|
685af47592b5
add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents:
99
diff
changeset
|
667 | */ |
|
107
36dd94278142
fix that PGN (with comments) can exceed 80 chars
Mike Becker <universe@uap-core.de>
parents:
100
diff
changeset
|
668 | int print_clk(uint16_t time, char *str, bool always_hours); |
|
100
685af47592b5
add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents:
99
diff
changeset
|
669 | |
|
131
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
670 | /** |
|
220
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
671 | * Checks if the current position is a checkmate. |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
672 | * |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
673 | * This does a full recalculation. You should use the checkmate flag |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
674 | * in the game state instead, if you want to test this after applying a |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
675 | * move. |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
676 | * |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
677 | * @param gamestate the current game state |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
678 | * @return true if the game is in a checkmate |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
679 | */ |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
680 | bool check_checkmate(const GameState *gamestate); |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
681 | |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
682 | /** |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
683 | * Checks if the current position is a stalemate. |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
684 | * |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
685 | * This does a full recalculation. You should use the stalemate flag |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
686 | * in the game state instead, if you want to test this after applying a |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
687 | * move. |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
688 | * |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
689 | * @param gamestate the current game state |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
690 | * @return true if the game is in a stalemate position |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
691 | */ |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
692 | bool check_stalemate(const GameState *gamestate); |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
693 | |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
694 | /** |
|
131
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
695 | * Checks if the current position already appeared two times before. |
|
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
696 | * |
|
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
697 | * This does not set the threefold flag in the game state as this flag is |
|
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
698 | * intended to be set only when the game ends after actually claiming a draw. |
|
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
699 | * |
|
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
700 | * By standard chess rules this is not automatically a draw. |
|
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
701 | * But implementation may choose to automatically draw the game anyway. |
|
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
702 | * |
|
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
703 | * @param gamestate the current game state |
|
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
704 | * @return true if the game is in a threefold repetition position |
|
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
705 | */ |
|
163
2a6d83f4677e
major refactoring of rules API
Mike Becker <universe@uap-core.de>
parents:
161
diff
changeset
|
706 | bool check_threefold_repetition(const GameState *gamestate); |
|
131
c33567d61ba7
prepare netcode for claiming threefold repetition
Mike Becker <universe@uap-core.de>
parents:
130
diff
changeset
|
707 | |
|
179
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
708 | /** |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
709 | * Checks if neither side has enough material left to win the game. |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
710 | * |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
711 | * Returns true if for both players one of the following three cases are true: |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
712 | * - they have only the king left |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
713 | * - they have a king + knight and the opponent has king + queens |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
714 | * - they have a king + bishop and the opponent doesn't have |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
715 | * opposite color bishops or knights or pawns |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
716 | * |
|
220
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
717 | * If you want to test this after applying a move, you should use the |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
718 | * nomaterial flag in the game state, instead. |
|
04da225a5677
implement that fen_parse() sets the game-end flags correctly
Mike Becker <universe@uap-core.de>
parents:
219
diff
changeset
|
719 | * |
|
179
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
720 | * @param gamestate the current game state |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
721 | * @return true if neither side can win due to insufficient material |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
722 | */ |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
723 | bool check_no_material(const GameState *gamestate); |
|
5ef724e21702
implement draw due to insufficient material
Mike Becker <universe@uap-core.de>
parents:
173
diff
changeset
|
724 | |
|
224
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
725 | #ifdef __cplusplus |
|
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
726 | } |
|
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
727 | #endif |
|
93e0e89496fe
test and ensure C++ compatibility of chess headers
Mike Becker <universe@uap-core.de>
parents:
220
diff
changeset
|
728 | |
|
10
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
729 | #endif /* RULES_H */ |
|
1347e4dabac0
prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff
changeset
|
730 |