-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVertex.h
143 lines (119 loc) · 2.57 KB
/
Vertex.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
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
#pragma once
#include "olcPixelGameEngine/olcPixelGameEngine.h"
class Vertex
{
public:
olc::vi2d pos;
public:
Vertex()
: pos({-1, -1})
{ }
Vertex* north = nullptr;
Vertex* south = nullptr;
Vertex* east = nullptr;
Vertex* west = nullptr;
bool walkableNorth = false;
bool walkableSouth = false;
bool walkableEast = false;
bool walkableWest = false;
bool hasApple = false;
bool hasLimb = false;
bool hadTail = false;
double distanceToApple = 0;
void connectNorth(Vertex* north)
{
this->north = north;
north->south = this;
}
void connectSouth(Vertex* south)
{
this->south = south;
south->north = this;
}
void connectEast(Vertex* east)
{
this->east = east;
east->west = this;
}
void connectWest(Vertex* west)
{
this->west = west;
west->east = this;
}
/* north */
bool unblockNorth()
{
if(this->north == nullptr) return false;
this->walkableNorth = this->north->walkableSouth = true;
return true;
}
bool blockNorth()
{
if(this->north == nullptr) return false;
this->walkableNorth = this->north->walkableSouth = false;
return true;
}
bool swapBlockNorth()
{
if(this->north == nullptr) return false;
this->walkableNorth = this->north->walkableSouth = !this->walkableNorth;
return true;
}
/* south */
bool unblockSouth()
{
if(this->south == nullptr) return false;
this->walkableSouth = this->south->walkableNorth = true;
return true;
}
bool blockSouth()
{
if(this->south == nullptr) return false;
this->walkableSouth = this->south->walkableNorth = false;
return true;
}
bool swapBlockSouth()
{
if(this->south == nullptr) return false;
this->walkableSouth = this->south->walkableNorth = !this->walkableSouth;
return true;
}
/* east */
bool unblockEast()
{
if(this->east == nullptr) return false;
this->walkableEast = this->east->walkableWest = true;
return true;
}
bool blockEast()
{
if(this->east == nullptr) return false;
this->walkableEast = this->east->walkableWest = false;
return true;
}
bool swapBlockEast()
{
if(this->east == nullptr) return false;
this->walkableEast = this->east->walkableWest = !this->walkableEast;
return true;
}
/* west */
bool unblockWest()
{
if(this->west == nullptr) return false;
this->walkableWest = this->west->walkableEast = true;
return true;
}
bool blockWest()
{
if(this->west == nullptr) return false;
this->walkableWest = this->west->walkableEast = false;
return true;
}
bool swapBlockWest()
{
if(this->west == nullptr) return false;
this->walkableWest = this->west->walkableEast = !this->walkableWest;
return true;
}
};