Refactored TurnTest.
[tagua/yd.git] / src / turnpolicy.cpp
blob9882c4aed405914cd4a95416d3043fceb6a01725
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 boost::shared_ptr<Always> always() {
18 return boost::shared_ptr<Always>(new Always);
21 boost::shared_ptr<Never> never() {
22 return boost::shared_ptr<Never>(new Never);
25 Collection::Collection()
26 : m_premove(true) { }
28 bool Collection::operator()(int turn) const {
29 Policies::const_iterator it = m_policies.find(turn);
30 if (it == m_policies.end()) {
31 return false;
33 else {
34 return it->second->check();
38 void Collection::setPolicy(int turn, const PolicyPtr& policy) {
39 m_policies[turn] = policy;
42 void Collection::clear() {
43 m_policies.clear();
46 void Collection::setPremove(bool value) {
47 m_premove = value;
50 bool Collection::premove() const {
51 return m_premove;