-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuman.cpp
209 lines (192 loc) · 6.06 KB
/
human.cpp
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*******************************************************************************
* Name: Samuel Menkus & Alden Faville
* Email: [email protected] & [email protected]
* Function: Implements human.h
* Input: Varies
* Output: Varies
* Completed: 12-15-2017
* Comments:
******************************************************************************/
#include <iostream>
#include <cstdlib>
#include "human.h"
using namespace std;
//constructors/deconstructor
/*******************************************************************************
* Function: Default human constructor
* Input: None
* Output: None
******************************************************************************/
human::human() {
type = 'H';
row = 0;
col = 0;
moved = false;
}
/*******************************************************************************
* Function: Copy constructor
* Input: &human
* Output: None
******************************************************************************/
human::human(const human &oldHuman) {
type = oldHuman.getType();
row = oldHuman.getRow();
col = oldHuman.getCol();
moved = false;
}
/*******************************************************************************
* Function: De-constructor
* Input: None
* Output: None
******************************************************************************/
human::~human() {
}
//getters/setters
/*******************************************************************************
* Function: Sets type
* Input: Char representing type ('H' or 'Z')
* Output: None
******************************************************************************/
void human::setType(char _type) {
type = _type;
}
/*******************************************************************************
* Function: returns the type
* Input: None
* Output: Char representing type ('H' or 'Z')
******************************************************************************/
char human::getType() const {
return type;
}
/*******************************************************************************
* Function: returns the row
* Input: None
* Output: int representing row
******************************************************************************/
int human::getRow() const {
return row;
}
/*******************************************************************************
* Function: Returns the current column of the human
* Input: None
* Output: int representing column
******************************************************************************/
int human::getCol() const {
return col;
}
/*******************************************************************************
* Function: Returns a bool representing whether the human has moved or not
* Input: None
* Output: bool representing movement having taken place
******************************************************************************/
bool human::getMoved() const {
return moved;
}
/*******************************************************************************
* Function: sets row
* Input: int representing row
* Output: None
******************************************************************************/
void human::setRow(int _row) {
if (_row >= 0 && _row < 8) {
row = _row;
}
}
/*******************************************************************************
* Function: Sets the current column of the human
* Input: int representing column
* Output: None
******************************************************************************/
void human::setCol(int _col) {
if (_col >= 0 && _col < 8) {
col = _col;
}
}
/*******************************************************************************
* Function: Sets whether or not the current human has moved
* Input: bool representing movement having taken place
* Output: None
******************************************************************************/
void human::setMoved(bool _moved) {
moved = _moved;
}
//methods
/*******************************************************************************
* Function: Prints information about the Human
* Input: None
* Output: information about the human
******************************************************************************/
void human::print() {
cout << getType() << " at col " << getCol() << " at row " << getRow();
}
/*******************************************************************************
* Function: Generates a random integer that coresponds with a direction
* Input: None
* Output: Random Integer from the list 0, 1, 2, 3
******************************************************************************/
int human::genMove() {
return rand() % 4;
}
/*******************************************************************************
* Function: Checks to see if the generated move goes out of the 8x8 grid bounds
* Input: None
* Output: Integer that corresponds w/ direction to move, or 4 if it would be
* out of bounds
******************************************************************************/
int human::checkMove() { // temp=Move | 4=Can't move
int temp = genMove();
if (temp == 0) { // Up
if (getRow()-1 < 0) {
return 4;
}
else {
return temp;
}
}
else if (temp == 1) { // Right
if (getCol()+1 > 7) {
return 4;
}
else {
return temp;
}
}
else if (temp == 2) { // Down
if (getRow()+1 > 7) {
return 4;
}
else {
return temp;
}
}
else {
if (getCol()-1 < 0) { // Left
return 4;
}
else {
return temp;
}
}
}
/*******************************************************************************
* Function: Checks if two humans are equal
* Input: &human
* Output: true if they are equal, false otherwise
******************************************************************************/
bool human::equals(human &otherHuman) {
if (getType() != otherHuman.getType()) {
return false;
}
else if (getCol() != otherHuman.getCol()) {
return false;
}
else if (getRow() != otherHuman.getRow()) {
return false;
}
else if (getMoved() != otherHuman.getMoved()) {
return false;
}
else {
return true;
}
}