Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 86 additions & 2 deletions idl/service.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// version 1

syntax = "proto3";

package protos;
Expand All @@ -19,13 +21,26 @@ message RegisterRequest {
AgentType agent_type = 1;
string team_name = 2;
int32 uniform_number = 3;
int32 rpc_version = 4;
}

enum RpcServerLanguageType {
UNKNOWN_LANGUAGE = 0;
PYThON = 1;
JAVA = 2;
CPP = 3;
CSHARP = 4;
RUBY = 5;
JAVE_SCRIPT = 6;
GO = 7;
}

message RegisterResponse {
int32 client_id = 1;
AgentType agent_type = 2;
string team_name = 3;
int32 uniform_number = 4;
RpcServerLanguageType rpc_server_language_type = 5;
}

message Ball {
Expand Down Expand Up @@ -81,6 +96,12 @@ enum LoggerLevel{
// LEVEL_ANY = 0xffffffff;
}

enum CardType {
NO_CARD = 0;
YELLOW = 1;
RED = 2;
}

message Player {
RpcVector2D position = 1;
RpcVector2D seen_position = 2;
Expand Down Expand Up @@ -151,6 +172,9 @@ message Self {
ViewWidth view_width = 34;
int32 type_id = 35;
float kick_rate = 36;
float recovery = 37;
float stamina_capacity = 38;
CardType card = 39;
}

enum InterceptActionType {
Expand Down Expand Up @@ -254,6 +278,10 @@ message WorldModel {
int32 their_team_score = 29;
bool is_penalty_kick_mode = 30;
map<int32, RpcVector2D> helios_home_positions = 31;
double our_defense_line_x = 32;
double their_defense_line_x = 33;
double our_defense_player_line_x = 34;
double their_defense_player_line_x = 35;
}

message State {
Expand Down Expand Up @@ -748,7 +776,7 @@ message HeliosGoalieKick {}

message HeliosShoot {}

message HeliosChainAction {
message HeliosOffensivePlanner {
bool direct_pass = 1;
bool lead_pass = 2;
bool through_pass = 3;
Expand All @@ -758,6 +786,7 @@ message HeliosChainAction {
bool simple_pass = 7;
bool simple_dribble = 8;
bool simple_shoot = 9;
bool server_side_decision = 10;
}

message HeliosBasicOffensive {}
Expand Down Expand Up @@ -830,12 +859,13 @@ message PlayerAction {
HeliosGoalieMove helios_goalie_move = 56;
HeliosGoalieKick helios_goalie_kick = 57;
HeliosShoot helios_shoot = 58;
HeliosChainAction helios_chain_action = 59;
HeliosOffensivePlanner helios_offensive_planner = 59;
HeliosBasicOffensive helios_basic_offensive = 60;
HeliosBasicMove helios_basic_move = 61;
HeliosSetPlay helios_set_play = 62;
HeliosPenalty helios_penalty = 63;
HeliosCommunicaion helios_communication = 64;

}
}

Expand Down Expand Up @@ -1202,6 +1232,59 @@ message PlayerType {
float player_speed_max = 34;
}

enum RpcActionCategory {
AC_Hold = 0;
AC_Dribble = 1;
AC_Pass = 2;
AC_Shoot = 3;
AC_Clear = 4;
AC_Move = 5;
AC_NoAction = 6;
}
message RpcCooperativeAction {
RpcActionCategory category = 1;
int32 index = 2;
int32 sender_unum = 3;
int32 target_unum = 4;
RpcVector2D target_point = 5;
double first_ball_speed = 6;
double first_turn_moment = 7;
double first_dash_power = 8;
double first_dash_angle_relative = 9;
int32 duration_step = 10;
int32 kick_count = 11;
int32 turn_count = 12;
int32 dash_count = 13;
bool final_action = 14;
string description = 15;
int32 parent_index = 16;
}

message RpcPredictState {
int32 spend_time = 1;
int32 ball_holder_unum = 2;
RpcVector2D ball_position = 3;
RpcVector2D ball_velocity = 4;
double our_defense_line_x = 5;
double our_offense_line_x = 6;
}

message RpcActionState {
RpcCooperativeAction action = 1;
RpcPredictState predict_state = 2;
double evaluation = 3;
}

message BestPlannerActionRequest {
RegisterResponse register_response = 1;
map<int32, RpcActionState> pairs = 2;
State state = 3;
}

message BestPlannerActionResponse {
int32 index = 1;
}

message Empty {
}

Expand All @@ -1215,4 +1298,5 @@ service Game {
rpc SendPlayerType(PlayerType) returns (Empty) {} //should be PlayerTypes
rpc Register(RegisterRequest) returns (RegisterResponse) {}
rpc SendByeCommand(RegisterResponse) returns (Empty) {}
rpc GetBestPlannerAction(BestPlannerActionRequest) returns (BestPlannerActionResponse) {}
}
35 changes: 23 additions & 12 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

logging.basicConfig(level=logging.DEBUG)


class GrpcAgent:
def __init__(self, agent_type, uniform_number) -> None:
self.agent_type: pb2.AgentType = agent_type
Expand All @@ -35,15 +34,18 @@ def GetPlayerActions(self, state: pb2.State):
if state.world_model.self.is_goalie:
actions.append(pb2.PlayerAction(helios_goalie=pb2.HeliosGoalie()))
elif state.world_model.self.is_kickable:
actions.append(pb2.PlayerAction(helios_chain_action=pb2.HeliosChainAction(lead_pass=True,
actions.append(pb2.PlayerAction(helios_offensive_planner=pb2.HeliosOffensivePlanner(lead_pass=True,
direct_pass=True,
through_pass=True,
simple_pass=True,
short_dribble=True,
long_dribble=True,
simple_shoot=True,
simple_dribble=True,
cross=True)))
cross=True,
server_side_decision=False
)))
actions.append(pb2.PlayerAction(helios_shoot=pb2.HeliosShoot()))
else:
actions.append(pb2.PlayerAction(helios_basic_move=pb2.HeliosBasicMove()))
else:
Expand Down Expand Up @@ -125,15 +127,15 @@ def Register(self, register_request: pb2.RegisterRequest, context):
f"agent_type: {register_request.agent_type}")
with self.shared_lock:
self.shared_number_of_connections.value += 1
logging.debug(f"Number of connections {self.shared_number_of_connections.value}")
team_name = register_request.team_name
uniform_number = register_request.uniform_number
agent_type = register_request.agent_type
self.agents[self.shared_number_of_connections.value] = GrpcAgent(agent_type, uniform_number)
res = pb2.RegisterResponse(client_id=self.shared_number_of_connections.value,
team_name=team_name,
uniform_number=uniform_number,
agent_type=agent_type)
logging.debug(f"Number of connections {self.shared_number_of_connections.value}")
team_name = register_request.team_name
uniform_number = register_request.uniform_number
agent_type = register_request.agent_type
self.agents[self.shared_number_of_connections.value] = GrpcAgent(agent_type, uniform_number)
res = pb2.RegisterResponse(client_id=self.shared_number_of_connections.value,
team_name=team_name,
uniform_number=uniform_number,
agent_type=agent_type)
return res

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

res = pb2.Empty()
return res

def GetBestPlannerAction(self, pairs: pb2.BestPlannerActionRequest, context):
logging.debug(f"GetBestPlannerAction cycle:{pairs.state.world_model.cycle} pairs:{len(pairs.pairs)} unum:{pairs.state.register_response.uniform_number}")
pairs_list: list[int, pb2.RpcActionState] = [(k, v) for k, v in pairs.pairs.items()]
pairs_list.sort(key=lambda x: x[0])
best_action = max(pairs_list, key=lambda x: -1000 if x[1].action.parent_index != -1 else x[1].predict_state.ball_position.x)
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)}")
res = pb2.BestPlannerActionResponse(index=best_action[0])
return res

def serve(port, shared_lock, shared_number_of_connections):
server = grpc.server(futures.ThreadPoolExecutor(max_workers=22))
Expand Down
558 changes: 288 additions & 270 deletions service_pb2.py

Large diffs are not rendered by default.

Loading