Skip to content
Newer
Older
100755 66 lines (55 sloc) 2.83 KB
f6de70a @fcardinaux Initial commit: a chess move generator
authored Jun 24, 2011
1 %% @doc Chess Move Generator: Header file
2 %% @end
3 %%
94a2948 @fcardinaux Added license information
authored Jun 27, 2011
4 %% This file is released under the GNU General Public License (GPL) version 3.
5 %%
6 %% @author François Cardinaux, CH 1207 Genève
7 %% @copyright 2011 François Cardinaux
f6de70a @fcardinaux Initial commit: a chess move generator
authored Jun 24, 2011
8
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored Jun 27, 2011
9 % Noticeable values in 0x88 representation:
10 -define(ROW_SPAN, 16).
11 -define(MOVE_UP, 16).
12 -define(MOVE_UP_LEFT, 15).
13 -define(MOVE_UP_RIGHT, 17).
14 -define(MOVE_UP_2, 32).
15 -define(MOVE_DOWN, -16).
16 -define(MOVE_DOWN_LEFT, -17).
17 -define(MOVE_DOWN_RIGHT, -15).
18 -define(MOVE_DOWN_2, -32).
19 -define(BOTTOM_LEFT_CORNER, 0).
20 -define(BOTTOM_RIGHT_CORNER, 7).
21 -define(TOP_LEFT_CORNER, 112).
22 -define(TOP_RIGHT_CORNER, 119).
23
24 -define(CASTLING_ALL, 15).
25 -define(CASTLING_WHITE_KING, 8).
26 -define(CASTLING_WHITE_QUEEN, 4).
27 -define(CASTLING_BLACK_KING, 2).
28 -define(CASTLING_BLACK_QUEEN, 1).
29
30 % Positions of the elements inside the ntc_chess_piece record
31 -define(PIECE_RECORD_COLOR, 2).
32 -define(PIECE_RECORD_TYPE, 3).
33 -define(PIECE_RECORD_SQUARE, 4).
34
35 -type chess_piece_color() :: 'black' | 'white'.
36 -type chess_piece_type() :: 'pawn' | 'knight' | 'bishop' | 'rook' | 'queen' | 'king'.
37 -type chess_piece_square() :: ?BOTTOM_LEFT_CORNER..?TOP_RIGHT_CORNER. % In 0x88 representation
38 -type castling() :: 'false' | 'queen' | 'king'.
39
f6de70a @fcardinaux Initial commit: a chess move generator
authored Jun 24, 2011
40 -record(ntc_chess_piece, {
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored Jun 26, 2011
41 color :: chess_piece_color(),
42 type :: chess_piece_type(),
43 square = false :: 'false' | chess_piece_square()}).
44
45 -record(ntc_chess_position, {
46 pieces :: [#ntc_chess_piece{}],
47 turn :: 'false' | chess_piece_color(),
48 allowedCastling = 0 :: 0..?CASTLING_ALL,
49 enPassantSquare = false :: 'false' | chess_piece_square(),
50 halfMoveClock = 0 :: integer(),
51 moveNumber = 0 :: integer()}).
f6de70a @fcardinaux Initial commit: a chess move generator
authored Jun 24, 2011
52
53 -record(ntc_chess_move, {
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored Jun 26, 2011
54 from :: #ntc_chess_piece{},
55 to :: #ntc_chess_piece{}, % May be a different piece, in case of promotion
56 newPosition :: #ntc_chess_position{},
57 castling = false :: castling(),
58 taken = false :: 'false' | #ntc_chess_piece{}}). % Not necessarily the same square as 'to' (en passant)
59
60 % Source: Programming Erlang, p 424
61 -define(NYI(X), (begin
62 io:format("*** NYI ~p ~p ~p~n", [?MODULE, ?LINE, X])
63 end)).
64
f6de70a @fcardinaux Initial commit: a chess move generator
authored Jun 24, 2011
65
Something went wrong with that request. Please try again.