Skip to content

Commit 0594534

Browse files
authored
Merge pull request #6 from CLSFramework/develop
Develop
2 parents adb4eb6 + c4a84fa commit 0594534

File tree

5 files changed

+605
-299
lines changed

5 files changed

+605
-299
lines changed

idl/service.proto

Lines changed: 86 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// version 1
2+
13
syntax = "proto3";
24

35
package protos;
@@ -19,13 +21,26 @@ message RegisterRequest {
1921
AgentType agent_type = 1;
2022
string team_name = 2;
2123
int32 uniform_number = 3;
24+
int32 rpc_version = 4;
25+
}
26+
27+
enum RpcServerLanguageType {
28+
UNKNOWN_LANGUAGE = 0;
29+
PYThON = 1;
30+
JAVA = 2;
31+
CPP = 3;
32+
CSHARP = 4;
33+
RUBY = 5;
34+
JAVE_SCRIPT = 6;
35+
GO = 7;
2236
}
2337

2438
message RegisterResponse {
2539
int32 client_id = 1;
2640
AgentType agent_type = 2;
2741
string team_name = 3;
2842
int32 uniform_number = 4;
43+
RpcServerLanguageType rpc_server_language_type = 5;
2944
}
3045

3146
message Ball {
@@ -81,6 +96,12 @@ enum LoggerLevel{
8196
// LEVEL_ANY = 0xffffffff;
8297
}
8398

99+
enum CardType {
100+
NO_CARD = 0;
101+
YELLOW = 1;
102+
RED = 2;
103+
}
104+
84105
message Player {
85106
RpcVector2D position = 1;
86107
RpcVector2D seen_position = 2;
@@ -151,6 +172,9 @@ message Self {
151172
ViewWidth view_width = 34;
152173
int32 type_id = 35;
153174
float kick_rate = 36;
175+
float recovery = 37;
176+
float stamina_capacity = 38;
177+
CardType card = 39;
154178
}
155179

156180
enum InterceptActionType {
@@ -254,6 +278,10 @@ message WorldModel {
254278
int32 their_team_score = 29;
255279
bool is_penalty_kick_mode = 30;
256280
map<int32, RpcVector2D> helios_home_positions = 31;
281+
double our_defense_line_x = 32;
282+
double their_defense_line_x = 33;
283+
double our_defense_player_line_x = 34;
284+
double their_defense_player_line_x = 35;
257285
}
258286

259287
message State {
@@ -748,7 +776,7 @@ message HeliosGoalieKick {}
748776

749777
message HeliosShoot {}
750778

751-
message HeliosChainAction {
779+
message HeliosOffensivePlanner {
752780
bool direct_pass = 1;
753781
bool lead_pass = 2;
754782
bool through_pass = 3;
@@ -758,6 +786,7 @@ message HeliosChainAction {
758786
bool simple_pass = 7;
759787
bool simple_dribble = 8;
760788
bool simple_shoot = 9;
789+
bool server_side_decision = 10;
761790
}
762791

763792
message HeliosBasicOffensive {}
@@ -830,12 +859,13 @@ message PlayerAction {
830859
HeliosGoalieMove helios_goalie_move = 56;
831860
HeliosGoalieKick helios_goalie_kick = 57;
832861
HeliosShoot helios_shoot = 58;
833-
HeliosChainAction helios_chain_action = 59;
862+
HeliosOffensivePlanner helios_offensive_planner = 59;
834863
HeliosBasicOffensive helios_basic_offensive = 60;
835864
HeliosBasicMove helios_basic_move = 61;
836865
HeliosSetPlay helios_set_play = 62;
837866
HeliosPenalty helios_penalty = 63;
838867
HeliosCommunicaion helios_communication = 64;
868+
839869
}
840870
}
841871

@@ -1202,6 +1232,59 @@ message PlayerType {
12021232
float player_speed_max = 34;
12031233
}
12041234

1235+
enum RpcActionCategory {
1236+
AC_Hold = 0;
1237+
AC_Dribble = 1;
1238+
AC_Pass = 2;
1239+
AC_Shoot = 3;
1240+
AC_Clear = 4;
1241+
AC_Move = 5;
1242+
AC_NoAction = 6;
1243+
}
1244+
message RpcCooperativeAction {
1245+
RpcActionCategory category = 1;
1246+
int32 index = 2;
1247+
int32 sender_unum = 3;
1248+
int32 target_unum = 4;
1249+
RpcVector2D target_point = 5;
1250+
double first_ball_speed = 6;
1251+
double first_turn_moment = 7;
1252+
double first_dash_power = 8;
1253+
double first_dash_angle_relative = 9;
1254+
int32 duration_step = 10;
1255+
int32 kick_count = 11;
1256+
int32 turn_count = 12;
1257+
int32 dash_count = 13;
1258+
bool final_action = 14;
1259+
string description = 15;
1260+
int32 parent_index = 16;
1261+
}
1262+
1263+
message RpcPredictState {
1264+
int32 spend_time = 1;
1265+
int32 ball_holder_unum = 2;
1266+
RpcVector2D ball_position = 3;
1267+
RpcVector2D ball_velocity = 4;
1268+
double our_defense_line_x = 5;
1269+
double our_offense_line_x = 6;
1270+
}
1271+
1272+
message RpcActionState {
1273+
RpcCooperativeAction action = 1;
1274+
RpcPredictState predict_state = 2;
1275+
double evaluation = 3;
1276+
}
1277+
1278+
message BestPlannerActionRequest {
1279+
RegisterResponse register_response = 1;
1280+
map<int32, RpcActionState> pairs = 2;
1281+
State state = 3;
1282+
}
1283+
1284+
message BestPlannerActionResponse {
1285+
int32 index = 1;
1286+
}
1287+
12051288
message Empty {
12061289
}
12071290

@@ -1215,4 +1298,5 @@ service Game {
12151298
rpc SendPlayerType(PlayerType) returns (Empty) {} //should be PlayerTypes
12161299
rpc Register(RegisterRequest) returns (RegisterResponse) {}
12171300
rpc SendByeCommand(RegisterResponse) returns (Empty) {}
1301+
rpc GetBestPlannerAction(BestPlannerActionRequest) returns (BestPlannerActionResponse) {}
12181302
}

server.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
logging.basicConfig(level=logging.DEBUG)
1313

14-
1514
class GrpcAgent:
1615
def __init__(self, agent_type, uniform_number) -> None:
1716
self.agent_type: pb2.AgentType = agent_type
@@ -35,15 +34,18 @@ def GetPlayerActions(self, state: pb2.State):
3534
if state.world_model.self.is_goalie:
3635
actions.append(pb2.PlayerAction(helios_goalie=pb2.HeliosGoalie()))
3736
elif state.world_model.self.is_kickable:
38-
actions.append(pb2.PlayerAction(helios_chain_action=pb2.HeliosChainAction(lead_pass=True,
37+
actions.append(pb2.PlayerAction(helios_offensive_planner=pb2.HeliosOffensivePlanner(lead_pass=True,
3938
direct_pass=True,
4039
through_pass=True,
4140
simple_pass=True,
4241
short_dribble=True,
4342
long_dribble=True,
4443
simple_shoot=True,
4544
simple_dribble=True,
46-
cross=True)))
45+
cross=True,
46+
server_side_decision=False
47+
)))
48+
actions.append(pb2.PlayerAction(helios_shoot=pb2.HeliosShoot()))
4749
else:
4850
actions.append(pb2.PlayerAction(helios_basic_move=pb2.HeliosBasicMove()))
4951
else:
@@ -125,15 +127,15 @@ def Register(self, register_request: pb2.RegisterRequest, context):
125127
f"agent_type: {register_request.agent_type}")
126128
with self.shared_lock:
127129
self.shared_number_of_connections.value += 1
128-
logging.debug(f"Number of connections {self.shared_number_of_connections.value}")
129-
team_name = register_request.team_name
130-
uniform_number = register_request.uniform_number
131-
agent_type = register_request.agent_type
132-
self.agents[self.shared_number_of_connections.value] = GrpcAgent(agent_type, uniform_number)
133-
res = pb2.RegisterResponse(client_id=self.shared_number_of_connections.value,
134-
team_name=team_name,
135-
uniform_number=uniform_number,
136-
agent_type=agent_type)
130+
logging.debug(f"Number of connections {self.shared_number_of_connections.value}")
131+
team_name = register_request.team_name
132+
uniform_number = register_request.uniform_number
133+
agent_type = register_request.agent_type
134+
self.agents[self.shared_number_of_connections.value] = GrpcAgent(agent_type, uniform_number)
135+
res = pb2.RegisterResponse(client_id=self.shared_number_of_connections.value,
136+
team_name=team_name,
137+
uniform_number=uniform_number,
138+
agent_type=agent_type)
137139
return res
138140

139141
def SendByeCommand(self, register_response: pb2.RegisterResponse, context):
@@ -143,6 +145,15 @@ def SendByeCommand(self, register_response: pb2.RegisterResponse, context):
143145

144146
res = pb2.Empty()
145147
return res
148+
149+
def GetBestPlannerAction(self, pairs: pb2.BestPlannerActionRequest, context):
150+
logging.debug(f"GetBestPlannerAction cycle:{pairs.state.world_model.cycle} pairs:{len(pairs.pairs)} unum:{pairs.state.register_response.uniform_number}")
151+
pairs_list: list[int, pb2.RpcActionState] = [(k, v) for k, v in pairs.pairs.items()]
152+
pairs_list.sort(key=lambda x: x[0])
153+
best_action = max(pairs_list, key=lambda x: -1000 if x[1].action.parent_index != -1 else x[1].predict_state.ball_position.x)
154+
logging.debug(f"Best action: {best_action[0]} {best_action[1].action.description} to {best_action[1].action.target_unum} in ({round(best_action[1].action.target_point.x, 2)},{round(best_action[1].action.target_point.y, 2)}) e:{round(best_action[1].evaluation,2)}")
155+
res = pb2.BestPlannerActionResponse(index=best_action[0])
156+
return res
146157

147158
def serve(port, shared_lock, shared_number_of_connections):
148159
server = grpc.server(futures.ThreadPoolExecutor(max_workers=22))

service_pb2.py

Lines changed: 288 additions & 270 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)