]> git.sesse.net Git - stockfish/blob - src/move.h
Implement Last Seconds Noise (LSN) filtering
[stockfish] / src / move.h
1 /*
2   Glaurung, a UCI chess playing engine.
3   Copyright (C) 2004-2008 Tord Romstad
4
5   Glaurung is free software: you can redistribute it and/or modify
6   it under the terms of the GNU General Public License as published by
7   the Free Software Foundation, either version 3 of the License, or
8   (at your option) any later version.
9   
10   Glaurung is distributed in the hope that it will be useful,
11   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   GNU General Public License for more details.
14   
15   You should have received a copy of the GNU General Public License
16   along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19
20 #if !defined(MOVE_H_INCLUDED)
21 #define MOVE_H_INCLUDED
22
23 ////
24 //// Includes
25 ////
26
27 #include <iostream>
28
29 #include "misc.h"
30 #include "piece.h"
31 #include "square.h"
32
33
34 ////
35 //// Types
36 ////
37
38 class Position;
39
40 enum Move {
41   MOVE_NONE = 0,
42   MOVE_NULL = 65, 
43   MOVE_MAX = 0xFFFFFF
44 };
45
46
47 struct MoveStack {
48   Move move;
49   int score;
50 };
51
52
53 ////
54 //// Inline functions
55 ////
56
57 inline Square move_from(Move m) {
58   return Square((int(m) >> 6) & 077);
59 }
60
61 inline Square move_to(Move m) {
62   return Square(m & 077);
63 }
64
65 inline PieceType move_promotion(Move m) {
66   return PieceType((int(m) >> 12) & 7);
67 }
68
69 inline bool move_is_ep(Move m) {
70   return bool((int(m) >> 15) & 1);
71 }
72
73 inline bool move_is_castle(Move m) {
74   return bool((int(m) >> 16) & 1);
75 }
76
77 inline bool move_is_short_castle(Move m) {
78   return move_is_castle(m) && (move_to(m) > move_from(m));
79 }
80
81 inline bool move_is_long_castle(Move m) {
82   return move_is_castle(m) && (move_to(m) < move_from(m));
83 }
84
85 inline Move make_promotion_move(Square from, Square to, PieceType promotion) {
86   return Move(int(to) | (int(from) << 6) | (int(promotion) << 12));
87 }
88
89 inline Move make_move(Square from, Square to) {
90   return Move(int(to) | (int(from) << 6));
91 }
92
93 inline Move make_castle_move(Square from, Square to) {
94   return Move(int(to) | (int(from) << 6) | (1 << 16));
95 }
96
97 inline Move make_ep_move(Square from, Square to) {
98   return Move(int(to) | (int(from) << 6) | (1 << 15));
99 }
100
101
102 ////
103 //// Prototypes
104 ////
105
106 extern std::ostream &operator << (std::ostream &os, Move m);
107 extern Move move_from_string(const Position &pos, const std::string &str);
108 extern const std::string move_to_string(Move m);
109 extern bool move_is_ok(Move m);
110
111
112 #endif // !defined(MOVE_H_INCLUDED)