d5875861ab3ed522eeaf4fd72caf6d6b1e2719c3
[tagua/yd.git] / src / core / state.h
blobd5875861ab3ed522eeaf4fd72caf6d6b1e2719c3
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 #ifndef CORE__STATE_H
12 #define CORE__STATE_H
14 #include "taguaobject.h"
16 class Board;
17 class IBehaviour;
18 class IColor;
19 class IPoolCollection;
20 class Move;
22 /**
23 * @brief The state of the game in a given moment of time.
25 * A State component encapsulates the global state of the game, i.e.
26 * what pieces are on the board or on the pool, and game flags like
27 * the en-passant square for chess.
29 * A State component also provides methods to setup the initial
30 * configuration and to make a move.
32 class TAGUA_EXPORT IState {
33 public:
34 virtual ~IState();
36 virtual IState* clone() const = 0;
38 /**
39 * Setup the initial configuration of pieces and reset all flags.
41 virtual void setup() = 0;
43 /**
44 * @return The piece board.
46 virtual const Board* board() const = 0;
47 virtual Board* board() = 0;
49 /**
50 * @return The player who plays next.
52 virtual const IColor* turn() const = 0;
54 /**
55 * Change the current turn.
57 virtual void setTurn(const IColor* turn) = 0;
59 /**
60 * @return Whether two states are equal.
62 virtual bool equals(IState* other) const = 0;
64 /**
65 * Make this state equal to the given one.
67 virtual void assign(const IState* other) = 0;
69 /**
70 * Play a move.
72 virtual void move(const Move& move) = 0;
74 /**
75 * @return Current flags.
77 virtual TaguaObject* flags() = 0;
78 virtual const TaguaObject* flags() const = 0;
80 /**
81 * @return The absolute index of the n-th rank for a given player.
83 virtual int rank(int n, const IColor* turn) const = 0;
85 /**
86 * @return The pool collection associated to this state.
88 virtual const IPoolCollection* pools() const = 0;
89 virtual IPoolCollection* pools() = 0;
91 /**
92 * @return The behaviour object associated to this state.
94 virtual const IBehaviour* behaviour() const = 0;
96 virtual void setDelegator(IState* state) = 0;
99 #endif // CORE__STATE_H