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__SHOSHOGI__LEGALITYCHECK_H
12 #define HLVARIANT__SHOSHOGI__LEGALITYCHECK_H
14 #include "interactiontype.h"
15 #include "../shogi/legalitycheck.h"
20 template <typename _GameState
>
21 class LegalityCheck
: public Shogi::LegalityCheck
<_GameState
> {
22 typedef Shogi::LegalityCheck
<_GameState
> Base
;
24 typedef _GameState GameState
;
25 typedef typename
GameState::Board Board
;
26 typedef typename
Board::Piece Piece
;
27 typedef typename
GameState::Move Move
;
29 LegalityCheck(const GameState
& state
);
30 bool legal(Move
& move
) const;
31 virtual InteractionType
droppable(const TurnTest
&, int index
) const;
36 template <typename GameState
>
37 LegalityCheck
<GameState
>::LegalityCheck(const GameState
& state
)
40 template <typename GameState
>
41 InteractionType LegalityCheck
<GameState
>::droppable(const TurnTest
&, int) const {
45 template <typename GameState
>
46 bool LegalityCheck
<GameState
>::legal(Move
& move
) const {
47 if (!pseudolegal(move
))
50 GameState
tmp(Base::m_state
);
53 // find king and prince positions
54 Point king_pos
= tmp
.board().find(Piece(Base::m_state
.turn(), Piece::KING
));
55 Point prince_pos
= tmp
.board().find(Piece(Base::m_state
.turn(), Piece::DRUNKEN_ELEPHANT
, true));
57 // check if the king and prince can be captured
58 if ((canBeCaptured(tmp
, king_pos
) && canBeCaptured(tmp
, prince_pos
)) ||
59 (canBeCaptured(tmp
, king_pos
) && !prince_pos
.valid()) ||
60 (canBeCaptured(tmp
, prince_pos
) && !king_pos
.valid()) ||
61 (!prince_pos
.valid() && !king_pos
.valid()))
67 } // namespace ShoShogi
68 } // namespace HLVariant
70 #endif // HLVARIANT__SHOSHOGI__LEGALITYCHECK_H