-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVersion2Submission.cpp
More file actions
190 lines (152 loc) · 4.91 KB
/
Version2Submission.cpp
File metadata and controls
190 lines (152 loc) · 4.91 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
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
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
bool DEBUG_FLAG = true;
void DebugLog(std::string log)
{
if (!DEBUG_FLAG) { return; }
std::cerr << "[DEBUG] " << log << std::endl;
}
struct PlayerStatus {
int x; int y;
int health;
int score;
int hammer_charges;
int scythe_charges;
int bow_charges;
};
enum MapEntityType {
EXIT, OBSTACLE
};
enum ItemType {
TREASURE, POTION,
HAMMER, SCYTHE, BOW
};
enum MonsterType {
BOX, SKELETON, GARGOYLE, ORC, VAMPIRE
};
struct EnemyStatus {
int x; int y;
int health;
int view_range;
int attack_range;
int damage;
};
struct EnemyKeyData {
int view_range;
int attack_range;
int damage;
};
struct ItemStatus {
int x; int y;
ItemType item_type;
int value;
};
struct EntityList {
std::vector<EnemyStatus> enemy_vector;
std::vector<ItemStatus> item_vector;
};
PlayerStatus getFramePlayerData() {
PlayerStatus player_data;
std::cin >> player_data.x >> player_data.y >> player_data.health
>> player_data.score >> player_data.hammer_charges >> player_data.scythe_charges
>> player_data.bow_charges;
std::cin.ignore();
return player_data;
}
void addItemStatus(EntityList& entity_list, int x, int y, int type, int value) {
ItemStatus item_for_push_back;
item_for_push_back.item_type = static_cast<ItemType>(type - 2);
item_for_push_back.x = x; item_for_push_back.y = y;
item_for_push_back.value = value;
entity_list.item_vector.push_back(item_for_push_back);
DebugLog("ITEM VALUE : " + std::to_string(value) + " X: " + std::to_string(x) + " Y: " + std::to_string(y));
}
EnemyKeyData parseEnemyKeyData(int enemy_type)
{
EnemyKeyData enemy_data;
switch (static_cast<MonsterType>(enemy_type)) {
case MonsterType::BOX:
enemy_data.view_range = 0;
enemy_data.attack_range = 0;
enemy_data.damage = 0;
break;
case MonsterType::SKELETON:
enemy_data.view_range = 1;
enemy_data.attack_range = 1;
enemy_data.damage = 1;
break;
case MonsterType::GARGOYLE:
enemy_data.view_range = 2;
enemy_data.attack_range = 1;
enemy_data.damage = 1;
break;
case MonsterType::ORC:
enemy_data.view_range = 2;
enemy_data.attack_range = 2;
enemy_data.damage = 1;
break;
case MonsterType::VAMPIRE:
enemy_data.view_range = 3;
enemy_data.attack_range = 1;
enemy_data.damage = 3;
default:
return enemy_data;
}
return enemy_data;
}
void addEnemyStatus(EntityList& entity_list, int x, int y, int type, int value) {
EnemyStatus enemy_for_push_back;
enemy_for_push_back.health = value;
enemy_for_push_back.x = x; enemy_for_push_back.y = y;
EnemyKeyData current_enemy_data = parseEnemyKeyData(type);
enemy_for_push_back.view_range = current_enemy_data.view_range;
enemy_for_push_back.attack_range = current_enemy_data.attack_range;
enemy_for_push_back.damage = current_enemy_data.damage;
entity_list.enemy_vector.push_back(enemy_for_push_back);
DebugLog("ENEMY: Health: " + std::to_string(value) + " X: " + std::to_string(x) + " Y: " + std::to_string(y) + " Type: " + std::to_string(type));
}
void pushBackEntity(EntityList& entity_list, int x, int y, int type, int value) {
if(type <= 1){ return; }
if (type >= 2 && type <= 6) {
addItemStatus(entity_list, x, y, type, value);
return;
}
if (type >= 7 && type <= 11) {
addEnemyStatus(entity_list, x, y, type, value);
return;
}
DebugLog("Severely Undefined Behavior. To be honest, I didn't think this was possible.");
}
EntityList initializeEntityList()
{
EntityList entity_list;
entity_list.enemy_vector = std::vector <EnemyStatus>();
entity_list.item_vector = std::vector <ItemStatus>();
return entity_list;
}
EntityList getVisibleEntityData() {
EntityList visible_entity_list = initializeEntityList();
int visible_entities; // the number of visible entities
std::cin >> visible_entities; std::cin.ignore();
for (int i = 0; i < visible_entities; i++) {
int ex; // x position of the entity
int ey; // y position of the entity
int etype; // the type of the entity
int evalue; // value associated with the entity
std::cin >> ex >> ey >> etype >> evalue; std::cin.ignore();
pushBackEntity(visible_entity_list, ex, ey, etype, evalue);
}
return visible_entity_list;
}
int main()
{
while (1) {
PlayerStatus player_data = getFramePlayerData();
EntityList visible_entities = getVisibleEntityData();
// Write an action using cout. DON'T FORGET THE "<< endl"
// To debug: cerr << "Debug messages..." << endl;
std::cout << "MOVE 6 8 Let's go!" << std::endl; // MOVE x y [message] | ATTACK weapon x y [message]
}
}