SPN C++ Bot Framework
Loading...
Searching...
No Matches
ipc_format.h
1#pragma once
2
3#include <stdlib.h>
4#include <stdint.h>
5#include <stdbool.h>
6
7extern "C" {
8
9#define ALIGNED __attribute__((aligned(4)))
10
11typedef float ipc_real_t;
12typedef uint64_t ipc_guid_t;
13
17struct ALIGNED IpcSelfInfo {
18 ipc_real_t segment_radius;
19 ipc_real_t mass;
20 ipc_real_t sight_radius;
21 ipc_real_t consume_radius;
22
23 uint32_t start_frame;
24 uint32_t current_frame;
25
26 ipc_real_t speed;
27 ipc_real_t max_step_angle;
28
32};
33
40struct ALIGNED IpcServerConfig {
43
44 ipc_real_t snake_pull_factor;
45
47
50
52
55
57
58 ipc_real_t food_decay_step;
59
62 ipc_real_t log_max_credits;
63};
64
68struct ALIGNED IpcFoodInfo {
69 ipc_real_t x;
70 ipc_real_t y;
71 ipc_real_t val;
72 ipc_real_t dir;
73 ipc_real_t dist;
74};
75
79struct ALIGNED IpcBotInfo {
80 ipc_guid_t bot_id;
81 char bot_name[64];
82};
83
87struct ALIGNED IpcSegmentInfo {
88 ipc_real_t x;
89 ipc_real_t y;
90 ipc_real_t r;
91 ipc_real_t dir;
92 ipc_real_t dist;
93 uint32_t idx;
94 ipc_guid_t bot_id;
95 bool is_self;
96};
97
101struct ALIGNED IpcColor {
102 uint8_t r;
103 uint8_t g;
104 uint8_t b;
105};
106
107const size_t IPC_FOOD_MAX_BYTES = 1 * 1024*1024;
108const size_t IPC_FOOD_MAX_COUNT = IPC_FOOD_MAX_BYTES / sizeof(struct IpcFoodInfo);
109
110const size_t IPC_BOT_MAX_COUNT = 1024;
111const size_t IPC_BOT_MAX_BYTES = IPC_BOT_MAX_COUNT * sizeof(struct IpcBotInfo);
112
113const size_t IPC_SEGMENT_MAX_BYTES = 1 * 1024*1024;
114const size_t IPC_SEGMENT_MAX_COUNT = IPC_SEGMENT_MAX_BYTES / sizeof(struct IpcSegmentInfo);
115
116const size_t IPC_COLOR_MAX_COUNT = 1024;
117const size_t IPC_COLOR_MAX_BYTES = IPC_COLOR_MAX_COUNT * sizeof(struct IpcColor);
118
119const size_t IPC_LOG_MAX_BYTES = 1024;
120
121const size_t IPC_PERSISTENT_MAX_BYTES = 4096;
122
131
133
134 uint32_t foodCount;
135 struct IpcFoodInfo foodInfo[IPC_FOOD_MAX_COUNT];
136
137 uint32_t botCount;
138 struct IpcBotInfo botInfo[IPC_BOT_MAX_COUNT];
139
140 uint32_t segmentCount;
141 struct IpcSegmentInfo segmentInfo[IPC_SEGMENT_MAX_COUNT];
142
143 uint32_t colorCount;
144 struct IpcColor colors[IPC_COLOR_MAX_COUNT];
145
146 char logData[IPC_LOG_MAX_BYTES];
147
148 uint32_t faceID;
149 uint32_t dogTagID;
150
151 uint8_t persistentData[IPC_PERSISTENT_MAX_BYTES];
152};
153
154const size_t IPC_SHARED_MEMORY_BYTES = sizeof(struct IpcSharedMemory);
155
156/*
157 * Communication structures.
158 */
159
160enum IpcRequestType {
161 REQ_INIT,
162 REQ_STEP
163};
164
170struct ALIGNED IpcRequest {
171 enum IpcRequestType type;
172};
173
174enum IpcResponseType {
175 RES_OK,
176 RES_ERROR
177};
178
185 enum IpcResponseType type;
186
187 union ALIGNED {
188 struct ALIGNED {
189 ipc_real_t deltaAngle;
190 bool boost;
191 } step;
192 };
193};
194
195} // extern "C"
IPC representation of a bot.
Definition: ipc_format.h:79
ipc_guid_t bot_id
Bot ID.
Definition: ipc_format.h:80
IPC representation of a color value.
Definition: ipc_format.h:101
uint8_t g
Green channel (0-255)
Definition: ipc_format.h:103
uint8_t b
Blue channel (0-255)
Definition: ipc_format.h:104
uint8_t r
Red channel (0-255)
Definition: ipc_format.h:102
IPC representation of a food particle.
Definition: ipc_format.h:68
ipc_real_t val
Food value.
Definition: ipc_format.h:71
ipc_real_t dist
Distance measured from the center of your head.
Definition: ipc_format.h:73
ipc_real_t x
Relative position X in world orientation.
Definition: ipc_format.h:69
ipc_real_t y
Relative position Y in world orientation.
Definition: ipc_format.h:70
ipc_real_t dir
Direction angle relative to your heading (range -π to +π)
Definition: ipc_format.h:72
A request to the bot by the gameserver.
Definition: ipc_format.h:170
Definition: ipc_format.h:188
ipc_real_t deltaAngle
Direction change in this frame (radians, -π to +π).
Definition: ipc_format.h:189
bool boost
Set to true to boost.
Definition: ipc_format.h:190
Response of the Bot.
Definition: ipc_format.h:184
IPC representation of a snake segment.
Definition: ipc_format.h:87
bool is_self
True if this segment belongs to ones own snake.
Definition: ipc_format.h:95
ipc_real_t dist
Distance between the center of your head and the segment's center.
Definition: ipc_format.h:92
ipc_guid_t bot_id
Bot ID.
Definition: ipc_format.h:94
ipc_real_t dir
Direction angle relative to your heading (range -π to +π)
Definition: ipc_format.h:91
ipc_real_t r
Segment radius.
Definition: ipc_format.h:90
ipc_real_t y
Relative position Y in world orientation.
Definition: ipc_format.h:89
ipc_real_t x
Relative position X in world orientation.
Definition: ipc_format.h:88
uint32_t idx
Segment number starting from head (idx == 0)
Definition: ipc_format.h:93
IPC representation of one's own snake and current world parameters.
Definition: ipc_format.h:17
ipc_real_t consumed_food_hunted_by_self
Amount of food you consumed and that was created from snakes you killed.
Definition: ipc_format.h:30
uint32_t start_frame
Frame number when your snake was spawned.
Definition: ipc_format.h:23
ipc_real_t consume_radius
Radius around your snake's head in which food is consumed.
Definition: ipc_format.h:21
ipc_real_t speed
Distance per step.
Definition: ipc_format.h:26
ipc_real_t mass
Your Snake's current mass.
Definition: ipc_format.h:19
uint32_t current_frame
Current frame number.
Definition: ipc_format.h:24
ipc_real_t consumed_food_hunted_by_others
Amount of food you consumed and that was created from snakes others killed (carrion)
Definition: ipc_format.h:31
ipc_real_t consumed_natural_food
Amount of "naturally" spawned food your snake consumed.
Definition: ipc_format.h:29
ipc_real_t segment_radius
Radius of your snake's segments.
Definition: ipc_format.h:18
ipc_real_t sight_radius
Radius around your snake's head in which you can see food and segments.
Definition: ipc_format.h:20
ipc_real_t max_step_angle
Maximum direction change in this step.
Definition: ipc_format.h:27
IPC representation of the static server and world configuration.
Definition: ipc_format.h:40
ipc_real_t log_initial_credits
How many log messages you can send right after startup.
Definition: ipc_format.h:61
ipc_real_t snake_segment_distance_exponent
segment distance = (mass * factor)^exponent
Definition: ipc_format.h:49
uint32_t snake_boost_steps
Number of steps a snake moves per frame while boosting.
Definition: ipc_format.h:41
ipc_real_t snake_turn_radius_factor
Multiplied with your segment radius to determine the inner turn radius.
Definition: ipc_format.h:42
ipc_real_t snake_self_kill_mass_threshold
Mass below which a snake dies through starvation.
Definition: ipc_format.h:56
ipc_real_t snake_boost_loss_factor
Multiplied with the snakes mass to determine how much mass is lost per frame while boosting.
Definition: ipc_format.h:53
ipc_real_t food_decay_step
Food decays by this value each frame.
Definition: ipc_format.h:58
ipc_real_t snake_segment_distance_factor
segment distance = (mass * factor)^exponent
Definition: ipc_format.h:48
ipc_real_t log_max_credits
You can send at most this many messages in a row.
Definition: ipc_format.h:62
ipc_real_t snake_pull_factor
Pull-together factor (determines how fast segments move to the center of a loop)
Definition: ipc_format.h:44
ipc_real_t snake_consume_range
consume range multiplier (multiplied with segment radius)
Definition: ipc_format.h:51
ipc_real_t snake_conversion_factor
how much of a snake's mass is converted to food when it dies
Definition: ipc_format.h:46
ipc_real_t log_credits_per_frame
How many log messages you can send per frame.
Definition: ipc_format.h:60
ipc_real_t snake_survival_loss_factor
This part of your mass is dropped every frame (to limit snake growth)
Definition: ipc_format.h:54
Shared memory structure.
Definition: ipc_format.h:129
uint32_t faceID
Select a face for your snake (not used yet).
Definition: ipc_format.h:148
struct IpcSelfInfo selfInfo
Information about your snake (updated every frame).
Definition: ipc_format.h:132
uint32_t dogTagID
Select a dog tag for your snake (not used yet).
Definition: ipc_format.h:149
struct IpcBotInfo botInfo[IPC_BOT_MAX_COUNT]
List of bots related to segments in segmentInfo.
Definition: ipc_format.h:138
uint8_t persistentData[IPC_PERSISTENT_MAX_BYTES]
Persistent data: will be saved after your snake dies and restored when it respawns.
Definition: ipc_format.h:151
struct IpcSegmentInfo segmentInfo[IPC_SEGMENT_MAX_COUNT]
List of segments seen by the snake.
Definition: ipc_format.h:141
uint32_t segmentCount
Number of items used in segmentInfo.
Definition: ipc_format.h:140
struct IpcColor colors[IPC_COLOR_MAX_COUNT]
Colors to set for this snake.
Definition: ipc_format.h:144
struct IpcFoodInfo foodInfo[IPC_FOOD_MAX_COUNT]
List of food items seen by the snake.
Definition: ipc_format.h:135
uint32_t botCount
Number of items used in botInfo.
Definition: ipc_format.h:137
uint32_t colorCount
Number of items used in colors.
Definition: ipc_format.h:143
char logData[IPC_LOG_MAX_BYTES]
Log data for the current frame.
Definition: ipc_format.h:146
uint32_t foodCount
Number of items used in foodInfo.
Definition: ipc_format.h:134
struct IpcServerConfig serverConfig
Information about the world and server configuration.
Definition: ipc_format.h:130
Definition: ipc_format.h:187