forked from ivogeorg/ucd-csci2312-pa4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.h
114 lines (89 loc) · 3.73 KB
/
Game.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
108
109
110
111
112
113
114
//
// Created by Ivo Georgiev on 11/22/15.
//
#ifndef PA5GAME_GAME_H
#define PA5GAME_GAME_H
#include <iostream>
#include <vector>
#include <array>
#include "Gaming.h"
#include "DefaultAgentStrategy.h"
namespace Gaming {
class Piece;
class Agent;
class Strategy;
class DefaultAgentStrategy;
class Game {
public:
enum Status { NOT_STARTED, PLAYING, OVER };
private:
static const unsigned int NUM_INIT_AGENT_FACTOR;
static const unsigned int NUM_INIT_RESOURCE_FACTOR;
static PositionRandomizer __posRandomizer;
void populate(); // populate the grid (used in automatic random initialization of a Game)
unsigned __numInitAgents, __numInitResources;
unsigned __width, __height;
std::vector<Piece *> __grid; // if a position is empty, nullptr
unsigned int __round;
Status __status;
bool __verbose;
public:
static const unsigned MIN_WIDTH, MIN_HEIGHT;
static const double STARTING_AGENT_ENERGY;
static const double STARTING_RESOURCE_CAPACITY;
Game();
Game(unsigned width, unsigned height, bool manual = true); // note: manual population by default
Game(const Game &) = delete;
Game &operator=(const Game &) = delete;
~Game();
// getters
unsigned int getWidth() const { return __width; }
unsigned int getHeight() const { return __height; }
unsigned int getNumPieces() const;
unsigned int getNumAgents() const;
unsigned int getNumSimple() const;
unsigned int getNumStrategic() const;
unsigned int getNumResources() const;
Status getStatus() const { return __status; }
unsigned int getRound() const { return __round; }
const Piece *getPiece(unsigned int x, unsigned int y) const;
// grid population methods
void addSimple(const Position &position);
void addSimple(const Position &position, double energy); // used for testing only
void addSimple(unsigned x, unsigned y);
void addSimple(unsigned x, unsigned y, double energy);
void addStrategic(const Position &position, Strategy *s = new DefaultAgentStrategy());
void addStrategic(unsigned x, unsigned y, Strategy *s = new DefaultAgentStrategy());
void addFood(const Position &position);
void addFood(unsigned x, unsigned y);
void addAdvantage(const Position &position);
void addAdvantage(unsigned x, unsigned y);
const Surroundings getSurroundings(const Position &pos) const;
// gameplay methods
static const ActionType reachSurroundings(const Position &from, const Position &to); // note: STAY by default
static const Position randomPosition(const std::vector<int> &positions) { // note: from Surroundings as an array
return __posRandomizer(positions);
}
bool isLegal(const ActionType &ac, const Position &pos) const;
const Position move(const Position &pos, const ActionType &ac) const; // note: assumes legal, use with isLegal()
void round(); // play a single round
void play(bool verbose = false); // play game until over
// const Agent &winner(); // what if no winner or multiple winners?
// Print as follows the state of the game after the last round:
//
// Round 1:
// [F0 ][ ][T1 ]
// [W2 ][ ][F3 ]
// [ ][S4 ][ ]
// Status: Playing...
//
// Round 5:
// [ ][ ][ ]
// [ ][T1 ][ ]
// [ ][ ][ ]
// Status: Over!
//
friend std::ostream &operator<<(std::ostream &os, const Game &game);
};
}
#endif //PA5GAME_GAME_H