2008-08-31 23:59:13 -06:00
|
|
|
/*
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish, a UCI chess playing engine derived from Glaurung 2.1
|
2021-01-08 09:04:23 -07:00
|
|
|
Copyright (C) 2004-2021 The Stockfish developers (see AUTHORS file)
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is free software: you can redistribute it and/or modify
|
2008-08-31 23:59:13 -06:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2008-10-26 14:44:58 -06:00
|
|
|
|
2008-10-19 10:56:28 -06:00
|
|
|
Stockfish is distributed in the hope that it will be useful,
|
2008-08-31 23:59:13 -06:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2008-10-26 14:44:58 -06:00
|
|
|
|
2008-08-31 23:59:13 -06:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2013-07-23 07:31:57 -06:00
|
|
|
#ifndef MOVEGEN_H_INCLUDED
|
2008-08-31 23:59:13 -06:00
|
|
|
#define MOVEGEN_H_INCLUDED
|
|
|
|
|
2017-04-16 02:48:17 -06:00
|
|
|
#include <algorithm>
|
|
|
|
|
2011-12-04 02:53:40 -07:00
|
|
|
#include "types.h"
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2021-02-26 02:02:13 -07:00
|
|
|
namespace Stockfish {
|
|
|
|
|
2015-01-09 04:35:44 -07:00
|
|
|
class Position;
|
|
|
|
|
2012-06-24 03:08:16 -06:00
|
|
|
enum GenType {
|
|
|
|
CAPTURES,
|
|
|
|
QUIETS,
|
|
|
|
QUIET_CHECKS,
|
|
|
|
EVASIONS,
|
|
|
|
NON_EVASIONS,
|
|
|
|
LEGAL
|
2011-01-05 11:00:30 -07:00
|
|
|
};
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2015-01-09 04:35:44 -07:00
|
|
|
struct ExtMove {
|
|
|
|
Move move;
|
2017-04-23 08:57:48 -06:00
|
|
|
int value;
|
2015-01-31 10:39:51 -07:00
|
|
|
|
|
|
|
operator Move() const { return move; }
|
2015-02-01 05:29:27 -07:00
|
|
|
void operator=(Move m) { move = m; }
|
2017-08-13 12:01:26 -06:00
|
|
|
|
|
|
|
// Inhibit unwanted implicit conversions to Move
|
|
|
|
// with an ambiguity that yields to a compile error.
|
2017-11-25 20:33:34 -07:00
|
|
|
operator float() const = delete;
|
2015-01-09 04:35:44 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
inline bool operator<(const ExtMove& f, const ExtMove& s) {
|
|
|
|
return f.value < s.value;
|
|
|
|
}
|
2011-12-04 02:53:40 -07:00
|
|
|
|
2012-06-24 03:08:16 -06:00
|
|
|
template<GenType>
|
2014-12-07 16:53:33 -07:00
|
|
|
ExtMove* generate(const Position& pos, ExtMove* moveList);
|
2008-08-31 23:59:13 -06:00
|
|
|
|
2013-12-02 11:04:09 -07:00
|
|
|
/// The MoveList struct is a simple wrapper around generate(). It sometimes comes
|
|
|
|
/// in handy to use this class instead of the low level generate() function.
|
2012-06-24 03:08:16 -06:00
|
|
|
template<GenType T>
|
2011-07-02 06:33:06 -06:00
|
|
|
struct MoveList {
|
|
|
|
|
2015-01-18 00:00:50 -07:00
|
|
|
explicit MoveList(const Position& pos) : last(generate<T>(pos, moveList)) {}
|
|
|
|
const ExtMove* begin() const { return moveList; }
|
|
|
|
const ExtMove* end() const { return last; }
|
2014-12-07 16:53:33 -07:00
|
|
|
size_t size() const { return last - moveList; }
|
2015-01-31 10:39:51 -07:00
|
|
|
bool contains(Move move) const {
|
2017-04-16 02:48:17 -06:00
|
|
|
return std::find(begin(), end(), move) != end();
|
2012-12-25 03:40:28 -07:00
|
|
|
}
|
2011-07-02 06:33:06 -06:00
|
|
|
|
|
|
|
private:
|
2015-01-18 00:00:50 -07:00
|
|
|
ExtMove moveList[MAX_MOVES], *last;
|
2011-07-02 06:33:06 -06:00
|
|
|
};
|
|
|
|
|
2021-02-26 02:02:13 -07:00
|
|
|
} // namespace Stockfish
|
|
|
|
|
2013-07-23 07:31:57 -06:00
|
|
|
#endif // #ifndef MOVEGEN_H_INCLUDED
|