2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
10 #include "validator.h"
14 #include <core/board.h>
15 #include <core/move.h>
16 #include <core/poolcollection.h>
17 #include <core/pool.h>
18 #include <core/state.h>
22 namespace Crazyhouse
{
24 Validator::Validator(IValidator
* validator
)
25 : Delegators::Validator(validator
) { }
27 Validator::~Validator() { }
29 bool Validator::pseudolegal(const IState
* state
, Move
& move
) const {
30 // add drop information to move, if missing
31 if (move
.drop() == Piece() &&
32 move
.pool() && move
.index() != -1) {
33 move
.setDrop(state
->pools()->pool(move
.pool())->get(move
.index()));
36 Piece dropped
= move
.drop();
37 if (dropped
== Piece()) {
38 return m_validator
->pseudolegal(state
, move
);
41 // dropping on a valid square
42 if (!state
->board()->valid(move
.dst()))
45 // cannot drop on occupied squares
46 if (state
->board()->get(move
.dst()) != Piece())
49 // cannot drop pawns in first or eighth rank
50 if (dropped
.type() == pawn
&&
51 (move
.dst().y
== state
->rank(0, players
[0]) ||
52 move
.dst().y
== state
->rank(state
->board()->size().y
- 1, players
[0])))
59 const IColor
* Validator::mover(const IState
* state
, const Move
& move
) const {
60 if (move
.drop() != Piece())
61 return move
.drop().color();
63 return m_validator
->mover(state
, move
);
66 } // namespace Crazyhouse