2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@sns.it>
3 (c) 2007 Maurizio Monge <maurizio.monge@kdemail.net>
5 This program 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 2 of the License, or
8 (at your option) any later version.
11 #ifndef HLVARIANT__CRAZYHOUSE__LEGALITYCHECK_H
12 #define HLVARIANT__CRAZYHOUSE__LEGALITYCHECK_H
14 #include "../chess/legalitycheck.h"
17 namespace Crazyhouse
{
19 template <typename _GameState
>
20 class LegalityCheck
: public Chess::LegalityCheck
<_GameState
> {
22 typedef _GameState GameState
;
24 typedef Chess::LegalityCheck
<GameState
> Base
;
25 typedef typename
Base::Board Board
;
26 typedef typename
Base::Move Move
;
27 typedef typename
Base::Piece Piece
;
31 LegalityCheck(const GameState
& state
);
33 virtual bool pseudolegal(Move
& move
) const;
34 virtual typename
Piece::Color
mover(const Move
& move
) const;
39 template <typename GameState
>
40 LegalityCheck
<GameState
>::LegalityCheck(const GameState
& state
)
43 template <typename GameState
>
44 bool LegalityCheck
<GameState
>::pseudolegal(Move
& move
) const {
45 // add drop information to move, if missing
46 if (move
.drop() == Piece() &&
47 move
.pool() != Piece::INVALID_COLOR
&&
49 move
.setDrop(m_state
.pools().pool(move
.pool()).get(move
.index()));
52 Piece dropped
= move
.drop();
54 if (dropped
== Piece()) {
55 return Base::pseudolegal(move
);
58 // dropping on a valid square
59 if (!m_state
.board().valid(move
.to()))
62 // cannot drop on occupied squares
63 if (m_state
.board().get(move
.to()) != Piece())
66 // cannot drop pawns in first or eighth rank
67 if (dropped
.type() == Piece::PAWN
&&
68 (move
.to().y
== m_state
.startingRank(Piece::WHITE
) ||
69 move
.to().y
== m_state
.promotionRank(Piece::WHITE
)))
76 template <typename GameState
>
77 typename LegalityCheck
<GameState
>::Piece::Color
78 LegalityCheck
<GameState
>::mover(const Move
& move
) const {
79 if (move
.drop() != Piece())
80 return move
.drop().color();
82 return Base::mover(move
);
85 } // namespace Crazyhouse
86 } // namespace HLVariant
89 #endif // HLVARIANT__CRAZYHOUSE__LEGALITYCHECK_H