-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mim_Lennig_FinalProject_classes.hpp
131 lines (89 loc) · 2.69 KB
/
Mim_Lennig_FinalProject_classes.hpp
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//
// Mim_Lennig_FinalProject_classes.hpp
// COEN 432
// Assignment #1 A
//
// Created by Miriam Lennig on 2016-11-25.
// Copyright © 2018 Miriam Lennig. All rights reserved.
//
#ifndef Mim_Lennig_FinalProject_classes_hpp
#define Mim_Lennig_FinalProject_classes_hpp
#include <iostream>
#include <vector>
#include <string>
using namespace std;
static const int N = 3;
static const int maskSize = 3;
static const int tournSize = 5;
enum Move {Left, Right, Forward};
enum Condition {north, south, east, west, empty, brickA, brickB, dontCare, edge, ownBrick, oppBrick};
enum Mutation {Add, Delete, Reorder, Modify};
// This is a Walls rule
class Rule{
public:
Rule();
Rule(const Rule&);
Rule(Condition[maskSize * maskSize], Move);
Condition mask[N*N];
Move action;
bool doesMatch(Condition[maskSize * maskSize]);
};
// This is a Walls strategy
class Strategy{
int m2b(int, int);
public:
Strategy(); // Fills strategy with a random # of random rules
Strategy(const Strategy&); // Copy constructor
Strategy(int); // Standard player
Strategy(char); // Empty strategy
Strategy(string); // Standard player from file
~Strategy();
void store2file(string);
vector<Rule*> rules;
void normalize(Condition[maskSize][maskSize], Condition[maskSize * maskSize]);
Move getMove(int, Condition[N][N], int[2], int[2], Condition[2]); // debug
static Strategy* mutate(Strategy*);
static Strategy* recombine(Strategy*, Strategy*);
};
class Game{
int xpos[2];
int ypos[2];
Condition heading[2];
Strategy* strategy[2];
int noBrickMoves[2] = {0, 0};
bool isStalled[2] = {false, false};
int moveNumber;
Condition board[N][N];
static clock_t totAAticks;
static unsigned long totAAmoves;
Move getHumanMove();
string facing(Condition);
string move2string(Move);
static void accumulateTiming(clock_t);
public:
int computeScore();
bool isOver();
int getNumBricks(int);
void print();
void makeHalfMove();
void executeMove(Move);
bool canMoveForward();
static double getTiming();
static unsigned long getTotAAmoves();
Game(Strategy*, Strategy*);
};
// This is a Walls evolution which implements the GA to evolve a set of strategies
class Evolution{
Strategy* tentativeWinner;
Strategy* standardPlayer;
vector<Strategy*> population;
vector<Strategy*> parents;
Strategy* tournamentPlayers[tournSize];
Strategy* tournament(); // Returns index of tournament player
bool canBeatStandardPlayer(Strategy*);
public:
Evolution();
~Evolution();
Strategy* getWinner();
};
#endif /* Mim_Lennig_FinalProject_classes_hpp */