src/chess/rules.h

Tue, 28 Apr 2026 12:25:48 +0200

author
Mike Becker <universe@uap-core.de>
date
Tue, 28 Apr 2026 12:25:48 +0200
changeset 115
206201d544be
parent 107
36dd94278142
permissions
-rw-r--r--

relax validation of premoves to allow retaking pieces

fixes #832

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
78
ceb9197b3c6d improve code structure
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
33 #include "game-info.h"
ceb9197b3c6d improve code structure
Mike Becker <universe@uap-core.de>
parents: 69
diff changeset
34
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
35 #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
36 #include <stdbool.h>
10
1347e4dabac0 prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff changeset
37
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
38 #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
39 #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
40 #define INVALID_MOVE_SYNTAX 1
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 INVALID_POSITION 2
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 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
43 #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
44 #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
45 #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
46 #define KING_MOVES_INTO_CHECK 7
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
47 #define RULES_VIOLATED 10
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
48
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
49 #define ENPASSANT_THREAT 0x40
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
50
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
51 #define POS_UNSPECIFIED UINT8_MAX
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
52 #define mdst(b,m) b[(m)->torow][(m)->tofile]
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
53 #define msrc(b,m) b[(m)->fromrow][(m)->fromfile]
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
54
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
55 #define isidx(idx) ((uint8_t)(idx) < 8)
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
56
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
57 #define isfile(file) (file >= 'a' && file <= 'h')
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
58 #define isrow(row) (row >= '1' && row <= '8')
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
59
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
60 #define rowidx(row) (row-'1')
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
61 #define fileidx(file) (file-'a')
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
62
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
63 #define rowchr(row) (row+'1')
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
64 #define filechr(file) (file+'a')
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
65
115
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
66 #define chkidx_from(move) (isidx((move)->fromfile) && isidx((move)->fromrow))
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
67 #define chkidx_to(move) (isidx((move)->tofile) && isidx((move)->torow))
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
68 #define chkidx(move) (chkidx_from(move) && chkidx_to(move))
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
69
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
70 /* secure versions - use, if index is not checked with isidx() */
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
71 #define fileidx_s(c) (isfile(c)?fileidx(c):POS_UNSPECIFIED)
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
72 #define rowidx_s(c) (isrow(c)?rowidx(c):POS_UNSPECIFIED)
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
73
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
74 /**
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
75 * Maps a character to a piece.
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
76 *
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
77 * Does not work for pawns, since they don't have a character.
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
78 *
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
79 * @param c one of R,N,B,Q,K
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
80 * @return numeric value for the specified piece
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
81 */
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
82 uint8_t getpiece(char c);
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
83
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
84 /**
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
85 * Maps a piece to a character.
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
86 *
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
87 * Does not work for pawns, scince they don't have a character.
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
88 *
69
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
89 * @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
90 * @return character value for the specified piece
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
91 */
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
92 char getpiecechr(uint8_t piece);
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
93
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
94 /**
69
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
95 * Maps a piece to a unicode character sequence.
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
96 *
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
97 * The returned unicode is for black pieces.
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
98 * You may colorize the output by setting the terminal foreground color.
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
99 *
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
100 * @param piece the piece to dispaly
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
101 * @return unicode character sequence for the specified piece
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
102 */
87
d4d67105d4e1 minor code improvements
Mike Becker <universe@uap-core.de>
parents: 80
diff changeset
103 char* getpieceunicode(uint8_t piece);
69
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
104
c8f2c280cff7 adds unicode support
Mike Becker <universe@uap-core.de>
parents: 63
diff changeset
105 /**
25
3ab0c2e1a4e2 implemented king
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
106 * Checks, if a specified field is covered by a piece of a certain color.
3ab0c2e1a4e2 implemented king
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
107 *
29
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
108 * 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
109 * 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
110 *
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
111 * @param gamestate the current game state
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
112 * @param row row of the field to check
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
113 * @param file file of the field to check
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
114 * @param color the color of the piece that should threaten the field
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
115 * @param threats the array where to store the threats (should be able to hold
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
116 * the rare maximum of 16 elements)
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
117 * @param threatcount a pointer to an uint8_t where the count of threats 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
118 * stored
80
b980a7192b5a replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents: 78
diff changeset
119 * @return true, if any piece of the specified color threatens the specified
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
120 * field (i.e. could capture an opponent piece)
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
121 */
80
b980a7192b5a replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents: 78
diff changeset
122 bool get_threats(GameState *gamestate, uint8_t row, uint8_t file,
29
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
123 uint8_t color, Move* threats, uint8_t* threatcount);
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
124
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
125 /**
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
126 * Checks, if a specified field is covered by a piece of a certain color AND
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
127 * 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
128 *
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
129 * 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
130 * 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
131 *
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
132 * @param gamestate the current game state
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
133 * @param row row of the field to check
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
134 * @param file file of the field to check
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
135 * @param color the color of the piece that should threaten the field
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
136 * @param threats the array where to store the threats (should be able to hold
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
137 * the rare maximum of 16 elements)
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
138 * @param threatcount a pointer to an uint8_t where the count of threats 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
139 * stored
80
b980a7192b5a replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents: 78
diff changeset
140 * @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
141 * field (i.e. 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
142 */
80
b980a7192b5a replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents: 78
diff changeset
143 bool get_real_threats(GameState *gamestate, uint8_t row, uint8_t file,
29
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
144 uint8_t color, Move* threats, uint8_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
145
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
146 /**
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
147 * Checks, if a specified field is covered by a piece of a certain color.
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
148 *
25
3ab0c2e1a4e2 implemented king
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
149 * @param gamestate the current game state
3ab0c2e1a4e2 implemented king
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
150 * @param row row of the field to check
3ab0c2e1a4e2 implemented king
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
151 * @param file file of the field to check
3ab0c2e1a4e2 implemented king
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
152 * @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
153 * @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
154 * field
25
3ab0c2e1a4e2 implemented king
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
155 */
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
156 #define is_covered(gamestate, row, file, color) \
29
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
157 get_threats(gamestate, row, file, color, NULL, NULL)
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
158
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
159 /**
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
160 * Checks, if a specified field is attacked 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
161 *
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
162 * I.e. the field is covered by a piece AND this piece is not pinned and
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
163 * 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
164 *
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
165 * @param gamestate the current game state
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
166 * @param row row of the field to check
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
167 * @param file file of the field to check
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
168 * @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
169 * @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
170 * 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
171 */
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
172 #define is_attacked(gamestate, row, file, color) \
61
e3a1a794351e fixes wrong macro expansion for is_attacked()
Mike Becker <universe@uap-core.de>
parents: 55
diff changeset
173 get_real_threats(gamestate, row, file, 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
174
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
175 /**
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
176 * 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
177 *
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
178 * I.e. the field is covered by a piece that is NOT the king AND this piece is
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
179 * 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
180 *
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
181 * @param gamestate the current game state
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
182 * @param row row of the field to check
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
183 * @param file file of the field to check
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
184 * @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
185 * @return true, if any piece (excluding the king) of the specified color
29
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
186 * threatens the specified 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
187 */
80
b980a7192b5a replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents: 78
diff changeset
188 bool is_protected(GameState *gamestate, uint8_t row, uint8_t file,
29
c6a1ad6cf749 fixed checkmate and completed implementation (more testing is still advised)
Mike Becker <universe@uap-core.de>
parents: 28
diff changeset
189 uint8_t color);
25
3ab0c2e1a4e2 implemented king
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
190
3ab0c2e1a4e2 implemented king
Mike Becker <universe@uap-core.de>
parents: 23
diff changeset
191 /**
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
192 * 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
193 * 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
194 *
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
195 * 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
196 * 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
197 * 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
198 * 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
199 *
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
200 * @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
201 * @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
202 * @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
203 * 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
204 */
80
b980a7192b5a replace _Bool with bool from C23 and/or stdbool.h
Mike Becker <universe@uap-core.de>
parents: 78
diff changeset
205 bool is_pinned(GameState *gamestate, 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
206
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
207 /**
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
208 * 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
209 * object.
115
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
210 *
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
211 * When short algebraic notation is used, the source position is determined by
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
212 * the evaluating the allowed moves according to the current game state.
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
213 *
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
214 * 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
215 * 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
216 *
23
824c9522ce66 introduced game state structure
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
217 * @param gamestate the current game state
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
218 * @param mstr the input string to parse
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
219 * @param move a pointer to object where the move data shall be stored
50
41017d0a72c5 added pgn parser and writer (without comment support yet) + minor refactorings
Mike Becker <universe@uap-core.de>
parents: 49
diff changeset
220 * @param color the color of the player to evaluate the move for
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
221 * @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
222 */
50
41017d0a72c5 added pgn parser and writer (without comment support yet) + minor refactorings
Mike Becker <universe@uap-core.de>
parents: 49
diff changeset
223 int eval_move(GameState *gamestate, char *mstr, Move *move, uint8_t color);
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
224
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
225 /**
115
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
226 * 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
227 * allowed to move that way.
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
228 *
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
229 * @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
230 * @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
231 * @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
232 */
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
233 int check_move(char *mstr, uint8_t color);
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
234
206201d544be relax validation of premoves to allow retaking pieces
Mike Becker <universe@uap-core.de>
parents: 107
diff changeset
235 /**
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
236 * Validates move by applying chess rules.
23
824c9522ce66 introduced game state structure
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
237 * @param gamestate the current game state
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
238 * @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
239 * @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
240 */
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
241 int validate_move(GameState *gamestate, Move *move);
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
242
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
243 /**
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
244 * Applies a move and deletes captured pieces.
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
245 *
23
824c9522ce66 introduced game state structure
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
246 * @param gamestate the current game state
19
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
247 * @param move the move to apply
6a26114297a1 moved chess rules to separate lib
Mike Becker <universe@uap-core.de>
parents: 18
diff changeset
248 */
23
824c9522ce66 introduced game state structure
Mike Becker <universe@uap-core.de>
parents: 19
diff changeset
249 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
250
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
251 /**
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
252 * 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
253 * 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
254 *
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
255 * @param gameinfo the information about the game
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
256 * @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
257 * @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
258 * @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
259 * 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
260 */
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
261 uint16_t remaining_movetime2(GameInfo *gameinfo, GameState *gamestate,
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
262 unsigned move_number);
33
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
263
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
264 /**
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
265 * Returns the remaining time on the clock for the specified player.
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
266 *
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
267 * @param gameinfo the information about the game
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
268 * @param gamestate the current game state
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
269 * @param color either BLACK or WHITE
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
270 * @return the remaining time - if time control is disabled, this function
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
271 * always returns zero
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
272 */
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
273 uint16_t remaining_movetime(GameInfo *gameinfo, GameState *gamestate,
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
274 uint8_t color);
866025982aa9 implemented time control
Mike Becker <universe@uap-core.de>
parents: 32
diff changeset
275
100
685af47592b5 add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
276 /**
685af47592b5 add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
277 * Converts clock time to string.
685af47592b5 add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
278 *
685af47592b5 add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
279 * @param time the time to format
685af47592b5 add API for formatting clocks
Mike Becker <universe@uap-core.de>
parents: 99
diff changeset
280 * @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
281 * @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
282 */
107
36dd94278142 fix that PGN (with comments) can exceed 80 chars
Mike Becker <universe@uap-core.de>
parents: 100
diff changeset
283 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
284
10
1347e4dabac0 prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff changeset
285 #endif /* RULES_H */
1347e4dabac0 prepared code base for implementing rules
Mike Becker <universe@uap-core.de>
parents:
diff changeset
286

mercurial