Skip to content
Newer
Older
100755 67 lines (56 sloc) 2.93 KB
f6de70a @fcardinaux Initial commit: a chess move generator
authored
1 %% @doc Chess Move Generator: Header file
2 %% @end
3 %%
94a2948 @fcardinaux Added license information
authored
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
8
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored
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
e088b06 @fcardinaux New prefix for records. Added a prefix to custom types.
authored
30 % Positions of the elements inside the chessfold_piece record
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored
31 -define(PIECE_RECORD_COLOR, 2).
32 -define(PIECE_RECORD_TYPE, 3).
33 -define(PIECE_RECORD_SQUARE, 4).
34
e088b06 @fcardinaux New prefix for records. Added a prefix to custom types.
authored
35 -type chessfold_piece_color() :: 'black' | 'white'.
36 -type chessfold_piece_type() :: 'pawn' | 'knight' | 'bishop' | 'rook' | 'queen' | 'king'.
37 -type chessfold_square() :: ?BOTTOM_LEFT_CORNER..?TOP_RIGHT_CORNER. % In 0x88 representation
38 -type chessfold_castling() :: 'false' | 'queen' | 'king'.
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored
39
e088b06 @fcardinaux New prefix for records. Added a prefix to custom types.
authored
40 -record(chessfold_piece, {
41 color :: chessfold_piece_color(),
42 type :: chessfold_piece_type(),
43 square = false :: 'false' | chessfold_square()}).
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored
44
e088b06 @fcardinaux New prefix for records. Added a prefix to custom types.
authored
45 -record(chessfold_position, {
46 pieces :: [#chessfold_piece{}],
47 turn :: 'false' | chessfold_piece_color(),
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored
48 allowedCastling = 0 :: 0..?CASTLING_ALL,
e088b06 @fcardinaux New prefix for records. Added a prefix to custom types.
authored
49 enPassantSquare = false :: 'false' | chessfold_square(),
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored
50 halfMoveClock = 0 :: integer(),
51 moveNumber = 0 :: integer()}).
f6de70a @fcardinaux Initial commit: a chess move generator
authored
52
e088b06 @fcardinaux New prefix for records. Added a prefix to custom types.
authored
53 -record(chessfold_move, {
54 from :: #chessfold_piece{},
55 to :: #chessfold_piece{}, % May be a different piece, in case of promotion
56 newPosition :: #chessfold_position{},
57 castling = false :: chessfold_castling(),
58 taken = false :: 'false' | #chessfold_piece{}}). % Not necessarily the same square as 'to' (en passant)
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored
59
60 % Source: Programming Erlang, p 424
593bcab @fcardinaux New function to get the string representation of a move
authored
61 -define(debug(X, Y), (begin
62 Info = io_lib:format(X, Y),
63 io:format("~nDebug in module ~p, line ~p:~n~p~n", [?MODULE, ?LINE, Info])
64cea53 @fcardinaux Improved the record definition, enhanced it with type definition and …
authored
64 end)).
65
f6de70a @fcardinaux Initial commit: a chess move generator
authored
66
Something went wrong with that request. Please try again.