Added legality checking to shogi.
[tagua/yd.git] / src / turnpolicy.cpp
blob4c7a57e35ab23c492f7c902a4923e78a45ad93bb
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 #include "turnpolicy.h"
13 namespace TurnPolicy {
15 Abstract::~Abstract() { }
17 class Simple : public Abstract {
18 bool m_value;
19 public:
20 Simple(bool value) : m_value(value) { }
21 bool check() const { return m_value; }
24 Premove::~Premove() { }
26 bool Collection::operator()(int turn) const {
27 Policies::const_iterator it = m_policies.find(turn);
28 if (it == m_policies.end()) {
29 return false;
31 else {
32 return it->second->check();
36 void Collection::setPolicy(int turn, const PolicyPtr& policy) {
37 m_policies[turn] = policy;
40 void Collection::setSimplePolicy(int turn, bool value) {
41 setPolicy(turn, boost::shared_ptr<Simple>(new Simple(value)));
44 void Collection::clear() {
45 m_policies.clear();
46 m_premove.reset();
49 bool Collection::premove() const {
50 return m_premove ? m_premove->check() : false;
53 void Collection::setPremovePolicy(const PremovePolicyPtr& policy) {
54 m_premove = policy;