-
Notifications
You must be signed in to change notification settings - Fork 2
/
GameState.h
executable file
·107 lines (93 loc) · 3.31 KB
/
GameState.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#ifndef _GAMESTATE_H
#define _GAMESTATE_H
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include "mt_random.h"
#include "ProblemState.h"
#include "States.h"
namespace hearts {
const double INF = 999999999999999.9;
const double NINF = -999999999999999.9;
const unsigned int uINF = 0xFFFFFFFF;
const unsigned int MAXPLAYERS = 6;
class iiGameState;
class Game;
/*
* Class GameState describes a particular game. It defines the next player,
* the current player, and the state of the game.
*
* A game state should be able to provide an optimized game state for
* a hash table.
*
* If the game supports partition search, getPartition should return a valid
* partition.
*
*/
class GameState : public ProblemState {
public:
GameState();
virtual ~GameState();
void randomlySwitchPlayers();
void addPlayer(Player *p);
void deletePlayers();
void setTeam(Player *p, int team);
void setTeam(int who, int team);
int getTeam(int who);
void setGame(Game *g)
{ game = g; }
Game *getGame()
{ return game; }
virtual void Reset(int NEWSEED = -1);
virtual void Print(int val = 0) const = 0;
virtual Player *getNextPlayer() const = 0;
virtual int getNextPlayerNum() const = 0;
virtual Player *getPreviousPlayer() const = 0;
virtual int getPreviousPlayerNum() const = 0;
virtual void ApplyMove(Move *move) {}
virtual void UndoMove(Move *move) {}
virtual bool IsLegalMove(Move *m);
virtual Move *getMoves() = 0; // get moves for next player
virtual Move *getAllMoves() { return getMoves(); } // get moves for next player
virtual Move *getRandomMove();
Move *getNewMove();
void freeMove(Move *);
virtual bool Done() const;
virtual int Winner() const { return -1; }
virtual double score(int who) const { return -1; } // this is the *actual* game score
// return score if we can calculate the end score from here
//virtual returnValue *checkEndGame() { return 0; }
// redefine to use hash table
// the argument, if provided, indicates to use that memory instead of allocating new
// memory. The indicated memory will be the result of a previous call to getHashState
virtual HashState *getHashState(HashState *mem = 0) { return 0; }
// define to use history heuristic
virtual uint32_t getMoveHash(const Move *m) { return 0; }
virtual Move *getMoveFromHash(uint32_t hash) { return 0; }
virtual uint64_t HashCurrentState(int who) const { return 0; }
// get partition representations of the current state
// virtual partition *getPartition(int me, double value) { return 0; }
// virtual HashState *getPartitionHashState(GameState *g, int me) { return 0; }
Player *getPlayer(int which) const;
int getPlayerNum(Player *) const;
inline unsigned int getNumPlayers() const { return numPlayers; }
// unsigned int getDepth() { return movesSoFar; } // our current depth in the tree
// unsigned int getTurns() { return movesSoFar/numPlayers; }
virtual bool isImperfectInformation() { return false; }
virtual iiGameState *getiiGameState(bool consistent, int who, Player *playerModel=0) { return 0; }
double gameScore[MAXPLAYERS];
mt_random r;
void copyMoveList(GameState *g);
protected:
virtual Move *allocateMoreMoves(int n) = 0;
Player *men[MAXPLAYERS];
int teams[MAXPLAYERS];
unsigned int numPlayers;
private:
// this is a cache of allocated moves
Move *moveList;
Game *game;
};
} // namespace hearts
#endif