Skip to content
Merged
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
30 changes: 15 additions & 15 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def __init__(self, agent_type, uniform_number) -> None:
self.debug_mode: bool = False

def GetAction(self, state: pb2.State):
if self.agent_type == pb2.AgentType.Player:
if self.agent_type == pb2.AgentType.PlayerT:
return self.GetPlayerActions(state)
elif self.agent_type == pb2.AgentType.Coach:
elif self.agent_type == pb2.AgentType.CoachT:
return self.GetCoachActions(state)
elif self.agent_type == pb2.AgentType.Trainer:
elif self.agent_type == pb2.AgentType.TrainerT:
return self.GetTrainerActions(state)

def GetPlayerActions(self, state: pb2.State):
Expand Down Expand Up @@ -124,21 +124,21 @@ def Register(self, register_request: pb2.RegisterRequest, context):
f"agent_type: {register_request.agent_type}")
with shared_lock:
shared_number_of_connections.value += 1
logging.debug(f"Number of connections {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.append(shared_number_of_connections.value, GrpcAgent(agent_type, uniform_number))
res = pb2.RegisterResponse(client_id=shared_number_of_connections.value,
team_name=team_name,
uniform_number=uniform_number,
agent_type=agent_type)
logging.debug(f"Number of connections {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[shared_number_of_connections.value] = GrpcAgent(agent_type, uniform_number)
res = pb2.RegisterResponse(client_id=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):
def SendByeCommand(self, register_response: pb2.RegisterResponse, context):
logging.debug(f"Bye command received unum {register_response.uniform_number}")
with shared_lock:
self.agents.pop(register_response.client_id)
# with shared_lock:
self.agents.pop(register_response.client_id)

res = pb2.Empty()
return res
Expand Down