User moves are now created by the entity.
[tagua/yd.git] / src / hlvariant / dummy / legalitycheck.h
blob6b6c9778e70f1e60fc80845b3bc1247b0dffe8c5
1 /*
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.
9 */
11 #ifndef HLVARIANT__DUMMY__LEGALITYCHECK_H
12 #define HLVARIANT__DUMMY__LEGALITYCHECK_H
14 #include "../chess/legalitycheck.h"
15 #include "interactiontype.h"
16 #include "turnpolicy.h"
18 namespace HLVariant {
19 namespace Dummy {
21 template <typename _GameState>
22 class LegalityCheck {
23 public:
24 typedef _GameState GameState;
25 protected:
26 typedef typename GameState::Board Board;
27 typedef typename GameState::Move Move;
28 typedef typename Board::Piece Piece;
30 const GameState& m_state;
31 public:
32 LegalityCheck(const GameState&);
33 virtual ~LegalityCheck();
35 virtual bool legal(Move&) const;
36 virtual InteractionType movable(const TurnTest&, const Point&);
37 virtual InteractionType droppable(const TurnTest&, int);
40 // IMPLEMENTATION
42 template <typename GameState>
43 LegalityCheck<GameState>::LegalityCheck(const GameState& state)
44 : m_state(state) { }
46 template <typename GameState>
47 LegalityCheck<GameState>::~LegalityCheck() { }
49 template <typename GameState>
50 bool LegalityCheck<GameState>::legal(Move& move) const {
51 if (move.drop() == Piece() &&
52 move.index() != -1 &&
53 move.pool() != -1) {
54 move.setDrop(m_state.pools().pool(move.pool()).get(move.index()));
57 return true;
60 template <typename GameState>
61 InteractionType LegalityCheck<GameState>::movable(const TurnTest& test, const Point& p) {
62 Piece piece = m_state.board().get(p);
63 return piece != Piece() && test(piece.color()) ? Moving : NoAction;
66 template <typename GameState>
67 InteractionType LegalityCheck<GameState>::droppable(const TurnTest& test, int index) {
68 return test(index) ? Moving : NoAction;
72 } // namespace Dummy
73 } // namespace HLVariant
76 #endif // HLVARIANT__DUMMY__LEGALITYCHECK_H