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
58 changes: 58 additions & 0 deletions idl/service.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// version 0

syntax = "proto3";

package protos;
Expand Down Expand Up @@ -758,6 +760,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 @@ -836,6 +839,7 @@ message PlayerAction {
HeliosSetPlay helios_set_play = 62;
HeliosPenalty helios_penalty = 63;
HeliosCommunicaion helios_communication = 64;

}
}

Expand Down Expand Up @@ -1202,6 +1206,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 +1272,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) {}
}
32 changes: 21 additions & 11 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 Down Expand Up @@ -43,7 +42,9 @@ def GetPlayerActions(self, state: pb2.State):
long_dribble=True,
simple_shoot=True,
simple_dribble=True,
cross=True)))
cross=True,
server_side_decision=False
)))
else:
actions.append(pb2.PlayerAction(helios_basic_move=pb2.HeliosBasicMove()))
else:
Expand Down Expand Up @@ -125,15 +126,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 +144,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
146 changes: 80 additions & 66 deletions service_pb2.py

Large diffs are not rendered by default.

108 changes: 106 additions & 2 deletions service_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ class AgentType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
PlayerT: _ClassVar[AgentType]
CoachT: _ClassVar[AgentType]
TrainerT: _ClassVar[AgentType]

class RpcActionCategory(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
__slots__ = ()
AC_Hold: _ClassVar[RpcActionCategory]
AC_Dribble: _ClassVar[RpcActionCategory]
AC_Pass: _ClassVar[RpcActionCategory]
AC_Shoot: _ClassVar[RpcActionCategory]
AC_Clear: _ClassVar[RpcActionCategory]
AC_Move: _ClassVar[RpcActionCategory]
AC_NoAction: _ClassVar[RpcActionCategory]
NARROW: ViewWidth
NORMAL: ViewWidth
WIDE: ViewWidth
Expand Down Expand Up @@ -159,6 +169,13 @@ MODE_MAX: GameModeType
PlayerT: AgentType
CoachT: AgentType
TrainerT: AgentType
AC_Hold: RpcActionCategory
AC_Dribble: RpcActionCategory
AC_Pass: RpcActionCategory
AC_Shoot: RpcActionCategory
AC_Clear: RpcActionCategory
AC_Move: RpcActionCategory
AC_NoAction: RpcActionCategory

class RpcVector2D(_message.Message):
__slots__ = ("x", "y", "dist", "angle")
Expand Down Expand Up @@ -1280,7 +1297,7 @@ class HeliosShoot(_message.Message):
def __init__(self) -> None: ...

class HeliosChainAction(_message.Message):
__slots__ = ("direct_pass", "lead_pass", "through_pass", "short_dribble", "long_dribble", "cross", "simple_pass", "simple_dribble", "simple_shoot")
__slots__ = ("direct_pass", "lead_pass", "through_pass", "short_dribble", "long_dribble", "cross", "simple_pass", "simple_dribble", "simple_shoot", "server_side_decision")
DIRECT_PASS_FIELD_NUMBER: _ClassVar[int]
LEAD_PASS_FIELD_NUMBER: _ClassVar[int]
THROUGH_PASS_FIELD_NUMBER: _ClassVar[int]
Expand All @@ -1290,6 +1307,7 @@ class HeliosChainAction(_message.Message):
SIMPLE_PASS_FIELD_NUMBER: _ClassVar[int]
SIMPLE_DRIBBLE_FIELD_NUMBER: _ClassVar[int]
SIMPLE_SHOOT_FIELD_NUMBER: _ClassVar[int]
SERVER_SIDE_DECISION_FIELD_NUMBER: _ClassVar[int]
direct_pass: bool
lead_pass: bool
through_pass: bool
Expand All @@ -1299,7 +1317,8 @@ class HeliosChainAction(_message.Message):
simple_pass: bool
simple_dribble: bool
simple_shoot: bool
def __init__(self, direct_pass: bool = ..., lead_pass: bool = ..., through_pass: bool = ..., short_dribble: bool = ..., long_dribble: bool = ..., cross: bool = ..., simple_pass: bool = ..., simple_dribble: bool = ..., simple_shoot: bool = ...) -> None: ...
server_side_decision: bool
def __init__(self, direct_pass: bool = ..., lead_pass: bool = ..., through_pass: bool = ..., short_dribble: bool = ..., long_dribble: bool = ..., cross: bool = ..., simple_pass: bool = ..., simple_dribble: bool = ..., simple_shoot: bool = ..., server_side_decision: bool = ...) -> None: ...

class HeliosBasicOffensive(_message.Message):
__slots__ = ()
Expand Down Expand Up @@ -2145,6 +2164,91 @@ class PlayerType(_message.Message):
player_speed_max: float
def __init__(self, register_response: _Optional[_Union[RegisterResponse, _Mapping]] = ..., id: _Optional[int] = ..., stamina_inc_max: _Optional[float] = ..., player_decay: _Optional[float] = ..., inertia_moment: _Optional[float] = ..., dash_power_rate: _Optional[float] = ..., player_size: _Optional[float] = ..., kickable_margin: _Optional[float] = ..., kick_rand: _Optional[float] = ..., extra_stamina: _Optional[float] = ..., effort_max: _Optional[float] = ..., effort_min: _Optional[float] = ..., kick_power_rate: _Optional[float] = ..., foul_detect_probability: _Optional[float] = ..., catchable_area_l_stretch: _Optional[float] = ..., unum_far_length: _Optional[float] = ..., unum_too_far_length: _Optional[float] = ..., team_far_length: _Optional[float] = ..., team_too_far_length: _Optional[float] = ..., player_max_observation_length: _Optional[float] = ..., ball_vel_far_length: _Optional[float] = ..., ball_vel_too_far_length: _Optional[float] = ..., ball_max_observation_length: _Optional[float] = ..., flag_chg_far_length: _Optional[float] = ..., flag_chg_too_far_length: _Optional[float] = ..., flag_max_observation_length: _Optional[float] = ..., kickable_area: _Optional[float] = ..., reliable_catchable_dist: _Optional[float] = ..., max_catchable_dist: _Optional[float] = ..., real_speed_max: _Optional[float] = ..., player_speed_max2: _Optional[float] = ..., real_speed_max2: _Optional[float] = ..., cycles_to_reach_max_speed: _Optional[int] = ..., player_speed_max: _Optional[float] = ...) -> None: ...

class RpcCooperativeAction(_message.Message):
__slots__ = ("category", "index", "sender_unum", "target_unum", "target_point", "first_ball_speed", "first_turn_moment", "first_dash_power", "first_dash_angle_relative", "duration_step", "kick_count", "turn_count", "dash_count", "final_action", "description", "parent_index")
CATEGORY_FIELD_NUMBER: _ClassVar[int]
INDEX_FIELD_NUMBER: _ClassVar[int]
SENDER_UNUM_FIELD_NUMBER: _ClassVar[int]
TARGET_UNUM_FIELD_NUMBER: _ClassVar[int]
TARGET_POINT_FIELD_NUMBER: _ClassVar[int]
FIRST_BALL_SPEED_FIELD_NUMBER: _ClassVar[int]
FIRST_TURN_MOMENT_FIELD_NUMBER: _ClassVar[int]
FIRST_DASH_POWER_FIELD_NUMBER: _ClassVar[int]
FIRST_DASH_ANGLE_RELATIVE_FIELD_NUMBER: _ClassVar[int]
DURATION_STEP_FIELD_NUMBER: _ClassVar[int]
KICK_COUNT_FIELD_NUMBER: _ClassVar[int]
TURN_COUNT_FIELD_NUMBER: _ClassVar[int]
DASH_COUNT_FIELD_NUMBER: _ClassVar[int]
FINAL_ACTION_FIELD_NUMBER: _ClassVar[int]
DESCRIPTION_FIELD_NUMBER: _ClassVar[int]
PARENT_INDEX_FIELD_NUMBER: _ClassVar[int]
category: RpcActionCategory
index: int
sender_unum: int
target_unum: int
target_point: RpcVector2D
first_ball_speed: float
first_turn_moment: float
first_dash_power: float
first_dash_angle_relative: float
duration_step: int
kick_count: int
turn_count: int
dash_count: int
final_action: bool
description: str
parent_index: int
def __init__(self, category: _Optional[_Union[RpcActionCategory, str]] = ..., index: _Optional[int] = ..., sender_unum: _Optional[int] = ..., target_unum: _Optional[int] = ..., target_point: _Optional[_Union[RpcVector2D, _Mapping]] = ..., first_ball_speed: _Optional[float] = ..., first_turn_moment: _Optional[float] = ..., first_dash_power: _Optional[float] = ..., first_dash_angle_relative: _Optional[float] = ..., duration_step: _Optional[int] = ..., kick_count: _Optional[int] = ..., turn_count: _Optional[int] = ..., dash_count: _Optional[int] = ..., final_action: bool = ..., description: _Optional[str] = ..., parent_index: _Optional[int] = ...) -> None: ...

class RpcPredictState(_message.Message):
__slots__ = ("spend_time", "ball_holder_unum", "ball_position", "ball_velocity", "our_defense_line_x", "our_offense_line_x")
SPEND_TIME_FIELD_NUMBER: _ClassVar[int]
BALL_HOLDER_UNUM_FIELD_NUMBER: _ClassVar[int]
BALL_POSITION_FIELD_NUMBER: _ClassVar[int]
BALL_VELOCITY_FIELD_NUMBER: _ClassVar[int]
OUR_DEFENSE_LINE_X_FIELD_NUMBER: _ClassVar[int]
OUR_OFFENSE_LINE_X_FIELD_NUMBER: _ClassVar[int]
spend_time: int
ball_holder_unum: int
ball_position: RpcVector2D
ball_velocity: RpcVector2D
our_defense_line_x: float
our_offense_line_x: float
def __init__(self, spend_time: _Optional[int] = ..., ball_holder_unum: _Optional[int] = ..., ball_position: _Optional[_Union[RpcVector2D, _Mapping]] = ..., ball_velocity: _Optional[_Union[RpcVector2D, _Mapping]] = ..., our_defense_line_x: _Optional[float] = ..., our_offense_line_x: _Optional[float] = ...) -> None: ...

class RpcActionState(_message.Message):
__slots__ = ("action", "predict_state", "evaluation")
ACTION_FIELD_NUMBER: _ClassVar[int]
PREDICT_STATE_FIELD_NUMBER: _ClassVar[int]
EVALUATION_FIELD_NUMBER: _ClassVar[int]
action: RpcCooperativeAction
predict_state: RpcPredictState
evaluation: float
def __init__(self, action: _Optional[_Union[RpcCooperativeAction, _Mapping]] = ..., predict_state: _Optional[_Union[RpcPredictState, _Mapping]] = ..., evaluation: _Optional[float] = ...) -> None: ...

class BestPlannerActionRequest(_message.Message):
__slots__ = ("register_response", "pairs", "state")
class PairsEntry(_message.Message):
__slots__ = ("key", "value")
KEY_FIELD_NUMBER: _ClassVar[int]
VALUE_FIELD_NUMBER: _ClassVar[int]
key: int
value: RpcActionState
def __init__(self, key: _Optional[int] = ..., value: _Optional[_Union[RpcActionState, _Mapping]] = ...) -> None: ...
REGISTER_RESPONSE_FIELD_NUMBER: _ClassVar[int]
PAIRS_FIELD_NUMBER: _ClassVar[int]
STATE_FIELD_NUMBER: _ClassVar[int]
register_response: RegisterResponse
pairs: _containers.MessageMap[int, RpcActionState]
state: State
def __init__(self, register_response: _Optional[_Union[RegisterResponse, _Mapping]] = ..., pairs: _Optional[_Mapping[int, RpcActionState]] = ..., state: _Optional[_Union[State, _Mapping]] = ...) -> None: ...

class BestPlannerActionResponse(_message.Message):
__slots__ = ("index",)
INDEX_FIELD_NUMBER: _ClassVar[int]
index: int
def __init__(self, index: _Optional[int] = ...) -> None: ...

class Empty(_message.Message):
__slots__ = ()
def __init__(self) -> None: ...
43 changes: 43 additions & 0 deletions service_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ def __init__(self, channel):
request_serializer=service__pb2.RegisterResponse.SerializeToString,
response_deserializer=service__pb2.Empty.FromString,
_registered_method=True)
self.GetBestPlannerAction = channel.unary_unary(
'/protos.Game/GetBestPlannerAction',
request_serializer=service__pb2.BestPlannerActionRequest.SerializeToString,
response_deserializer=service__pb2.BestPlannerActionResponse.FromString,
_registered_method=True)


class GameServicer(object):
Expand Down Expand Up @@ -143,6 +148,12 @@ def SendByeCommand(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def GetBestPlannerAction(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_GameServicer_to_server(servicer, server):
rpc_method_handlers = {
Expand Down Expand Up @@ -191,6 +202,11 @@ def add_GameServicer_to_server(servicer, server):
request_deserializer=service__pb2.RegisterResponse.FromString,
response_serializer=service__pb2.Empty.SerializeToString,
),
'GetBestPlannerAction': grpc.unary_unary_rpc_method_handler(
servicer.GetBestPlannerAction,
request_deserializer=service__pb2.BestPlannerActionRequest.FromString,
response_serializer=service__pb2.BestPlannerActionResponse.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'protos.Game', rpc_method_handlers)
Expand Down Expand Up @@ -444,3 +460,30 @@ def SendByeCommand(request,
timeout,
metadata,
_registered_method=True)

@staticmethod
def GetBestPlannerAction(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(
request,
target,
'/protos.Game/GetBestPlannerAction',
service__pb2.BestPlannerActionRequest.SerializeToString,
service__pb2.BestPlannerActionResponse.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)