-
Notifications
You must be signed in to change notification settings - Fork 1
/
ai.cpp
109 lines (90 loc) · 2.65 KB
/
ai.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
#include "ai.h"
#include <random>
namespace monkeymusic {
namespace ai {
web::json::value random_direction() {
auto moves = std::vector<std::string>{"up", "left", "down", "right"};
std::random_device rd; // obtain a random number from hardware
std::mt19937 eng(rd()); // seed the generator
std::uniform_int_distribution<> distr(0, 3); // define the range
return web::json::value::string(moves[distr(eng)]);
}
web::json::value move(const web::json::value ¤t_game_state) {
// The gameState looks like this:
//
// {
//
// layout: [[String]],
// remainingTurns: Number,
// isGameOver: Boolean,
//
// score: Number,
// position: [Number, Number],
// inventory: [String],
// inventorySize: Number,
// buffs: {String: Number}
// }
// This is an example of a possible game state:
//
// {
// layout: [["empty", "monkey"],
// ["empty", "song"]],
// remainingTurns: 10,
// isGameOver: false,
//
// score: 3,
// position: [0, 1],
// inventory: ["trap"],
// buffs: {"speedy": 3}
// }
// You control your monkey by sending one of the following commands to the server:
//
// {"command": "move", "direction": ("left"|"right"|"up"|"down")}
// {"command": "use", "item": ("banana"|"trap")}
// {"command": "idle"}
// Remember that you can only use items that you have in your inventory!
// Lets talk positions and directions.
//
// X and Y coordinates can be confusing.
// Which way is up and which way is down?
//
// Here is an example explaining how coordinates work in
// Monkey Music Challenge:
//
// {
// "layout": [["empty", "monkey"]
// ["song", "empty"]]
// "position": [0, 1],
// ...
// }
//
// The "position" attribute tells you the location of your monkey
// in the "layout" matrix. In this example, you're at layout[0][1].
// Here's an example!
//
// If you send {"command": "move", "direction": "down"}
// to the server, you'll get back:
//
// {
// "layout": [["empty", "empty"]
// ["song", "monkey"]]
// "position": [1, 1]
// }
//
// If you instead send { "command": "move", "direction": "left"}
// to the server, you'll get back:
//
// {
// "layout": [["monkey", "empty"]
// ["song", "empty"]]
// "position": [0, 0]
// }
// Go to <TODO: url> for more info about the rules of Monkey Music Challenge!
// TODO: You may want to do something smarter here
web::json::value ret;
ret[U("command")] = web::json::value::string(U("move"));
ret[U("direction")] = random_direction();
return ret;
}
} // namespace ai
} // namespace monkeymusic