Prepare 1.0 alpha3 release.
[tagua/yd.git] / src / turnpolicy.cpp
bloba9a281735371e98d91f21d8f1b2dbcbd0255958e
1 /*
2 Copyright (c) 2007 Paolo Capriotti <p.capriotti@gmail.com>
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;