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
15 namespace Crazyhouse
{
17 template <typename _GameState
>
18 class LegalityCheck
: public Chess::LegalityCheck
<_GameState
> {
20 typedef _GameState GameState
;
22 typedef Chess::LegalityCheck
<GameState
> Base
;
23 typedef typename
Base::Board Board
;
24 typedef typename
Base::Move Move
;
25 typedef typename
Base::Piece Piece
;
29 LegalityCheck(const GameState
& state
);
31 virtual bool pseudolegal(Move
& move
) const;
32 virtual typename
Piece::Color
mover(const Move
& move
) const;
37 template <typename GameState
>
38 LegalityCheck
<GameState
>::LegalityCheck(const GameState
& state
)
41 template <typename GameState
>
42 bool LegalityCheck
<GameState
>::pseudolegal(Move
& move
) const {
43 // add drop information to move, if missing
44 if (move
.drop() == Piece() &&
45 move
.pool() != Piece::INVALID_COLOR
&&
47 move
.setDrop(m_state
.pools().pool(move
.pool()).get(move
.index()));
50 Piece dropped
= move
.drop();
52 if (dropped
== Piece()) {
53 return Base::pseudolegal(move
);
56 // dropping on a valid square
57 if (!m_state
.board().valid(move
.to()))
60 // cannot drop on occupied squares
61 if (m_state
.board().get(move
.to()) != Piece())
64 // cannot drop pawns in first or eighth rank
65 if (dropped
.type() == Piece::PAWN
&&
66 (move
.to().y
== m_state
.startingRank(Piece::WHITE
) ||
67 move
.to().y
== m_state
.promotionRank(Piece::WHITE
)))
74 template <typename GameState
>
75 typename LegalityCheck
<GameState
>::Piece::Color
76 LegalityCheck
<GameState
>::mover(const Move
& move
) const {
77 if (move
.drop() != Piece())
78 return move
.drop().color();
80 return Base::mover(move
);
83 } // namespace Crazyhouse
84 } // namespace HLVariant
87 #endif // HLVARIANT__CRAZYHOUSE__LEGALITYCHECK_H