-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent_cpp.cpp
More file actions
117 lines (80 loc) · 2.65 KB
/
agent_cpp.cpp
File metadata and controls
117 lines (80 loc) · 2.65 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
#include <exception>
#include <iostream>
#include <string>
#include <ctime>
#include "./json.hpp"
using json = nlohmann::json;
using namespace std;
json make_move(const json& fighter_info, const json& opponent_info, json& saved_data) {
json action;
action["move"] = nullptr;
action["attack"] = nullptr;
action["jump"] = false;
action["dash"] = nullptr;
action["debug"] = nullptr;
//by default keep the previous saved_data
action["saved_data"] = saved_data;
//examples of how to use saved_data
// if (saved_data["last_action"].is_null()) {
// saved_data["last_action"] = 0;
// }
// else {
// saved_data["last_action"] = (saved_data["last_action"].get<int>() + 1) % 100;
// }
// action["debug"] = saved_data["last_action"];
// int current;
// try{
// current = saved_data["last_action"].get<int>();
// }catch (const exception& e) {
// current = 0;
// }
// saved_data["last_action"] = (current + 1);
//attack cooldowns
vector<int> attack_cooldowns = fighter_info["attack_cooldown"].get<vector<int>>();
int light_attack_cooldown = attack_cooldowns[0];
int heavy_attack_cooldown = attack_cooldowns[1];
//are we attacking right now
bool is_attacking = fighter_info["attacking"].get<bool>();
//dash cooldown in frames
int dash_cooldown = fighter_info["dash_cooldown"].get<int>();
//current health
int fighterHealth = fighter_info["health"].get<int>();
//are we jumping right now
bool is_jumping = fighter_info["jump"].get<bool>();
//our coordinates
int fighter_x = fighter_info["x"].get<int>();
int fighter_y = fighter_info["y"].get<int>();
//opponent coordinates
int opponent_x = opponent_info["x"].get<int>();
int opponent_y = opponent_info["y"].get<int>();
//opponent health
int opponentHealth = opponent_info["health"].get<int>();
//opponent is attacking
bool opponent_is_attacking = opponent_info["attacking"].get<bool>();
//your desicios here
return action;
}
int main() {
// Read input JSON from stdin
string input;
getline(cin, input);
try {
json data = json::parse(input);
json fighter_info = data["fighter"];
json opponent_info = data["opponent"];
json saved_data = data["saved_data"];
// Get move decision
json move = make_move(fighter_info, opponent_info,saved_data);
// Output the move as JSON
cout << move.dump() << endl;
} catch (const exception& e) {
cerr << "Error: " << e.what() << endl;
json default_move;
default_move["move"] = nullptr;
default_move["attack"] = nullptr;
default_move["jump"] = false;
default_move["dash"] = nullptr;
cout << default_move.dump() << endl;
}
return 0;
}