-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimple.cpp
More file actions
156 lines (146 loc) · 3.83 KB
/
Copy pathSimple.cpp
File metadata and controls
156 lines (146 loc) · 3.83 KB
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
//
// Simple.cpp
// PA5
//
// Created by Tisha Konz on 12/11/15.
// Copyright (c) 2015 Tisha Konz. All rights reserved.
//
#include "Simple.h"
namespace Gaming
{
const char Simple::SIMPLE_ID = 'S';
Simple::Simple(const Game &g, const Position &p, double energy)
: Agent (g, p, energy)
{
}
Simple::~Simple()
{
}
ActionType Simple::takeTurn(const Surroundings &s) const
{
ActionType ac;
for (int i = 0; i < 9; i++)
{
int n = static_cast<int>(s.array[i]);
if (n == 2) // FOOD
{
if (i == 0)
{
return NW;
}
else if (i == 1)
{
return N;
}
else if (i == 2)
{
return NE;
}
else if (i == 3)
{
return W;
}
else if (i == 5)
{
int x5 = getPosition().x;
int x6 = getPosition().y;
return E;
}
else if (i == 6)
{
return SW;
}
else if (i == 7)
{
return S;
}
else if (i == 8)
{
return SE;
}
}
else if (n == 3) // ADVANTAGE
{
if (i == 0)
{
return NW;
}
else if (i == 1)
{
return N;
}
else if (i == 2)
{
return NE;
}
else if (i == 3)
{
return W;
}
else if (i == 5)
{
return E;
}
else if (i == 6)
{
return SW;
}
else if (i == 7)
{
return S;
}
else if (i == 8)
{
return SE;
}
}
else if (n == 6) // EMPTY
{
if (i == 0)
{
return NW;
}
else if (i == 1)
{
return N;
}
else if (i == 2)
{
return NE;
}
else if (i == 3)
{
return W;
}
else if (i == 5)
{
if (getPosition().x == 0 && getPosition().y == __game.getHeight()-1)
return S;
else if (getPosition().x == 0 && getPosition().y == __game.getHeight()-2)
return SW;
else if (getPosition().y == __game.getHeight()-1 && getPosition().x == __game.getWidth()-1)
return N;
else if (getPosition().y == __game.getHeight()-1 && getPosition().x == __game.getWidth()-2)
return NW;
else
return E;
}
else if (i == 6)
{
return SW;
}
else if (i == 7)
{
return S;
}
else if (i == 8)
{
return SE;
}
}
else
ac = STAY;
}
return STAY;
}
}