Rename delegate members, trying to avoid confusion.
[tagua/yd.git] / src / variants / crazyhouse / validator.cpp
blob69fd79b981632342a7bee81fdebf713b72e9ec56
1 /*
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.
8 */
10 #include "validator.h"
12 #include <KDebug>
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>
20 #include "global.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_dgate_validator->pseudolegal(state, move);
40 else {
41 // dropping on a valid square
42 if (!state->board()->valid(move.dst()))
43 return false;
45 // cannot drop on occupied squares
46 if (state->board()->get(move.dst()) != Piece())
47 return false;
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])))
53 return false;
55 return true;
59 const IColor* Validator::mover(const IState* state, const Move& move) const {
60 if (move.drop() != Piece())
61 return move.drop().color();
62 else
63 return m_dgate_validator->mover(state, move);
66 } // namespace Crazyhouse