Refactored TurnTest.
[tagua/yd.git] / src / turnpolicy.h
blobb759269f567abf9ceaf4cb9e5610d2b3bd157757
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 TURNPOLICY_H
12 #define TURNPOLICY_H
14 #include <map>
15 #include <boost/shared_ptr.hpp>
17 namespace TurnPolicy {
19 /**
20 * An abstract class encapsulating the user ability
21 * to move in a given turn.
23 class Abstract {
24 public:
25 virtual ~Abstract();
26 virtual bool check() const = 0;
29 /**
30 * The user can always move in this turn.
32 class Always : public Abstract {
33 public:
34 virtual bool check() const { return true; }
37 boost::shared_ptr<Always> always();
39 /**
40 * The user cannot move in this turn. A null pointer in turn test
41 * has the same effect of this class.
43 class Never : public Abstract {
44 public:
45 virtual bool check() const { return false; }
48 boost::shared_ptr<Never> never();
50 class Collection {
51 typedef boost::shared_ptr<Abstract> PolicyPtr;
52 typedef std::map<int, PolicyPtr> Policies;
53 Policies m_policies;
55 bool m_premove;
56 public:
57 Collection();
59 bool operator()(int turn) const;
60 void setPolicy(int turn, const PolicyPtr& policy);
61 void clear();
63 void setPremove(bool value);
64 bool premove() const;
68 typedef TurnPolicy::Collection TurnTest;
70 #endif // TURNPOLICY_H