-
Notifications
You must be signed in to change notification settings - Fork 0
/
HowToUseChessBoard.txt
180 lines (140 loc) · 6.62 KB
/
HowToUseChessBoard.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
---------------------------------------------------------------------------
This is a very short description of the public methods of ChessBoard.
---------------------------------------------------------------------------
chessboard = ChessBoard()
Creates a new instance of the ChessBoard component.
chessboard.resetBoard()
Resets the chess board and all states.
chessboard.setFEN(fen)
Sets the board and states accoring from a Forsyth-Edwards Notation string.
Ex. 'rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2'
chessboard.getFEN()
Returns the current state as Forsyth-Edwards Notation string.
chessboard.isCheck()
Returns True if the current players king is checked.
chessboard.isGameOver()
Returns True if the game is over by either checkmate or draw.
Use getGameResult() to find out why game is over.
chessboard.getGameResult()
Returns the reason for game over.
If game is not over this method returns None.
It can be the following reasons:
ChessBoard.WHITE_WIN
ChessBoard.BLACK_WIN
ChessBoard.STALEMATE
ChessBoard.FIFTY_MOVES_RULE
ChessBoard.THREE_REPETITION_RULE
chessboard.getBoard()
Returns a copy of the current board layout. Uppercase letters for white, lovercase for black.
K=King, Q=Queen, B=Bishop, N=Night, R=Rook, P=Pawn.
Empty squares are marked with a period (.)
Exmaple return value (the initial board):
[['r','n','b','q','k','b','n','r'],
['p','p','p','p','p','p','p','p'],
['.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.'],
['.','.','.','.','.','.','.','.'],
['P','P','P','P','P','P','P','P'],
['R','N','B','Q','K','B','N','R']]
chessboard.getTurn()
Returns the current player.
Return value can be:
ChessBoard.WHITE
ChessBoard.BLACK
chessboard.getValidMoves(location)
Returns a list of valid moves. (ex [ (3,4),(3,5),(3,6) ... ] ) If there isn't a valid piece on that location or the piece on the selected
location hasn't got any valid moves an empty list is returned.
The location argument must be a tuple containing an x,y value Ex. (3,3)
Example (with a fresh board):
chessboard.getValidMoves((4,6)) returns [(4,5),(4,4)]
chessboard.addMove(fromPos,toPos)
Tries to move the piece located on fromPos to toPos. Returns True if that was a valid move.
The position arguments must be tuples containing x,y value Ex. (4,6)
If this method returns False you can use the getReason method to determin why.
Right now ChessBoard only use its own internal coordinates in the comunication with the client.
The coordinates starts at (0,0) in the upper left corner. Ex: (0,0) = A8, (7,7) = H1.
Example:
The popular opening e2-e4 is done by calling chessboard.addMove((4,6),(4,4))
chessboard.addTextMove(move)
Adds a move using several different standards of the Algebraic chess notation.
AN Examples: 'e2e4' 'f1d1' 'd7-d8' 'g1-f3'
SAN Examples: 'e4' 'Rfxd1' 'd8=Q' 'Nxf3+'
LAN Examples: 'Pe2e4' 'Rf1xd1' 'Pd7d8=Q' 'Ng1xf3+'
chessboard.getReason()
Returns the reason to why addMove() returned False.
Return values can be:
ChessBoard.INVALID_MOVE
ChessBoard.INVALID_COLOR
ChessBoard.INVALID_FROM_LOCATION
ChessBoard.INVALID_TO_LOCATION
ChessBoard.MUST_SET_PROMOTION (use setPormotion() and call addMove() again)
ChessBoard.GAME_IS_OVER
ChessBoard.AMBIGUOUS_MOVE (a given textmove could be done by two different pieces)
chessboard.setPromotion(promotion)
Tell the chessboard how to promote a pawn.
Use this when addMove returns MUST_SET_PROMOTION.
The promotion value is stored until another promotion value is set.
promotion can be:
ChessBoard.QUEEN
ChessBoard.ROOK
ChessBoard.KNIGHT
ChessBoard.BISHOP
Use setPromotion(0) to clear the promotion value.
chessboard.getPromotion()
Return the current promotion value.
result can be:
ChessBoard.QUEEN
ChessBoard.ROOK
ChessBoard.KNIGHT
ChessBoard.BISHOP
or 0 (zero) if no promotion value is set.
chessboard.getLastMove:
Returns a tupple containing two tupples describing the move just made using the internal coordinates.
In the format ((from_x,from_y),(to_x,to_y))
Ex. ((4,6),(4,4))
Returns None if no moves has been made.
chessboard.getAllTextMoves(format)
Returns a list of all moves done so far in Algebraic chess notation.
Returns None if no moves has been made.
format can be:
ChessBoard.AN
ChessBoard.SAN (default)
ChessBoard.AN
chessboard.getLastTextMove(format)
Returns the latest move as Algebraic chess notation.
Returns None if no moves has been made.
format can be:
ChessBoard.AN
ChessBoard.SAN (default)
ChessBoard.AN
chessboard.getLastMoveType()
Returns a value that indicates if the last move was a "special move".
Returns -1 if no move has been done.
Return value can be:
chessboard.NORMAL_MOVE
chessboard.EP_MOVE (Pawn is moved two steps and is valid for en passant strike)
chessboard.EP_CAPTURE_MOVE (A pawn has captured another pawn by using the en passant rule)
chessboard.PROMOTION_MOVE (A pawn has been promoted. Use getPromotion() to see the promotion piece.)
chessboard.KING_CASTLE_MOVE (Castling on the king side.)
chessboard.QUEEN_CASTLE_MOVE (Castling on the queen side.)
chessboard.getMoveCount()
Returns the number of halfmoves in the stack.
Zero (0) means no moves has been made.
chessboard.getCurrentMove()
Returns the current halfmove number. Zero (0) means before first move.
chessboard.gotoMove(move)
Goto the specified halfmove. Zero (0) is before the first move.
Returns False if move is out of range.
chessboard.gotoFirst()
Goto the state before the first known move.
chessboard.gotoLast()
Goto after the last knwon move.
chessboard.undo()
Undo the last move. Can be used to step back until the initial board setup.
Returns True or False if no more moves can be undone.
chessboard.redo()
If you used the undo method to step backwards you can use this method to step forward until the last move i reached.
Returns True or False if no more moves can be redone.
chessboard.printBoard()
Prints the current board layout to standard output.