forked from ivogeorg/ucd-csci2312-pa4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gaming.h
63 lines (49 loc) · 1.79 KB
/
Gaming.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
//
// Created by Ivo Georgiev on 11/22/15.
//
#ifndef PA5GAME_GAMING_H
#define PA5GAME_GAMING_H
#include <array>
#include <random>
#include "Exceptions.h"
namespace Gaming {
// matrix convention: x indexes rows from top to bottom, y column from left to right
struct Position {
unsigned int x, y;
Position() {}
Position(unsigned int x, unsigned int y) : x(x), y(y) {}
};
// actions are either a motion in one of 8 directions or staying in place
enum ActionType { N=0, NE, NW, E, W, SE, SW, S, STAY };
// what a position on the game grid can be filled with
enum PieceType { SIMPLE=0, STRATEGIC, FOOD, ADVANTAGE, INACCESSIBLE, SELF, EMPTY };
// a "map" of the 8 squares adjacent to a piece
struct Surroundings {
// encoded as an array/vector top-left row-wise bottom-right
// [0][1][2]
// [3][4][5]
// [6][7][8]
// the piece is always at 1x1 (SELF)
std::array<PieceType, 9> array;
};
class PositionRandomizer {
std::default_random_engine __gen;
std::uniform_int_distribution<int> *__dist[10];
public:
PositionRandomizer() {
for (int i = 0; i < 10; i++)
__dist[i] = new std::uniform_int_distribution<int>(0, i);
}
~PositionRandomizer() {
for (int i = 0; i < 10; i++) delete __dist[i];
}
const Position operator()(const std::vector<int> &positionIndices) {
if (positionIndices.size() == 0) throw PosVectorEmptyEx();
int posIndex = (*__dist[positionIndices.size() - 1])(__gen);
return Position(
(unsigned) (positionIndices[posIndex] / 3),
(unsigned) (positionIndices[posIndex] % 3));
}
};
}
#endif // PA5GAME_GAMING_H