random
Create a random team i.e. team where each agent takes a random action (used for testing)
RandomAgent Objects
class RandomAgent(Agent)
Agents that move randomly
move
| move(state_prev, state, reward)
Move the agent randomly
RandomTeam Objects
class RandomTeam(Team)
A team of random agents
move
| move(state_prev, state, reward)
Move each player randomly
human
Create a Human team i.e. controlled by the keyboard
HumanAgent Objects
class HumanAgent(Agent)
Agents controlled by humans
draw
| draw(win, cam, team_id, selected=0, debug=False)
Draw the human agent. Also draws a red triangle on top of the selected player
move
| move(state_prev, state, reward)
Move the human agent based on the keyboard
HumanTeam Objects
class HumanTeam(Team)
A team of human players
update
| update(action, ball)
Select a player (based on the Ball's state) and update the team's state based on the received actions and the ball's position
draw
| draw(win, cam, debug)
Draw the human team
select_player
| select_player(ball)
Select the player that is controlled by the keyboard
Working:
- If ball is near the D-area, keeper gets automatic control
- Otherwise the player nearest to the ball has control (ties are broken randomly)
formation_dir
| formation_dir(id)
Send player (with the given ID) to his designated place in the formation
Working:
- If player is in-line (horizontally or vertically), move directly towards original point (U/L/D/R)
- Otherwise choose 2 directions that take you closer to the original point and choose one of them randomly (UL/UR/DL/DR)
move
| move(state_prev, state, reward)
Move a human team
Working:
- Player nearest to the ball moves through keyboard
- All other players return to their original positions (if maintain_formation is set)
network
Create a team that can be controlled over the network
NetworkAgent Objects
class NetworkAgent(Agent)
Agent that can be controlled over the network (online)
Use the register_keystroke()
function to add keys from the server (socket)
__init__
| __init__(id, team_id, pos, dir='L')
Initialize the network agent
The agent maintains a queue of the received keystrokes
register_keystroke
| register_keystroke(key)
Register a keystroke
Use this method within the server's socket
move
| move(state_prev, state, reward)
Move the network agent based on it's internal queue
NetworkTeam Objects
class NetworkTeam(Team)
A team of network players
update
| update(action, ball)
Select a player (based on the Ball's state) and update the team's state based on the received actions and the ball's position
select_player
| select_player(ball)
Select the player that is controlled by the keyboard
Working:
- If ball is near the D-area, keeper gets automatic control
- Otherwise the player nearest to the ball has control (ties are broken randomly)
register_keystroke
| register_keystroke(key)
Register a keystroke for the currently selected player
formation_dir
| formation_dir(id)
Send player (with the given ID) to his designated place in the formation
Working:
- If player is in-line (horizontally or vertically), move directly towards original point (U/L/D/R)
- Otherwise choose 2 directions that take you closer to the original point and choose one of them randomly (UL/UR/DL/DR)
move
| move(state_prev, state, reward)
Move a network team
Working:
- Player nearest to the ball moves through keyboard
- All other players return to their original positions (if maintain_formation is set)
original_ai
Create a hardcoded AI team i.e. actions are determined using simple geometry
OriginalAIAgent Objects
class OriginalAIAgent(Agent)
Harcoded AI agents that play like the original AI (designed in 2013) Takes an additional difficulty arguement
draw
| draw(win, cam, team_id, debug=False)
Draw an AI agent
Also displays circles with AI_FAR_RADIUS
and AI_NEAR_RADIUS
when debug is True
dist_to_line
| dist_to_line(line, pt)
perpendicular of a pt from the given line
Attributes:
line
tuple - A straight line representing xline[0] + yline[1] + line[2] = 0pt
Point - a 2D point
ai_move_with_ball
| ai_move_with_ball(enemy_players, goal_x)
How AI players move when they have the ball
Attributes:
enemy_players
list - A list of the positions (coordinates) of the enemy playersgoal_x
int - The x-coordinate of the enemy's goal post
Returns an ACT
Working:
- If this player has the ball
- Calculate vectors towards the goal and away from nearby players of the opposite team
- Add up all these vectors and move in that direction (probabilistically)
- enemy_players: positions of all of the enemy team
ai_move_without_ball
| ai_move_without_ball(ball)
How AI players move when they do not have the ball
Attributes:
ball
Point - position of the ball
Returns an ACT
Working:
- If the ball is within its
AI_FAR_RADIUS
, move towards the ball (probabilistically) - Otherwise, do
NOTHING
ai_pass
| ai_pass(team_players, enemy_team_players)
How AI players pass the ball
Attributes:
team_players
list - A list of the positions (coordinates) of the team playersenemy_team_players
list - A list of the positions (coordinates) of the enemy team players
Returns an ACT
Working:
- Pass the ball such that the perpendicular distance to the pass line is less than
AI_MIN_PASS_DIST
- Pass is valid if no enemy is nearer than a team player in that direction
Note
- The origin is at top-left instead of the standard bottom-left so we map y to H-y
ai_shoot
| ai_shoot(gk, goal_x)
How AI players shoot the ball
Attributes:
gk
Agent - The enemy's goalkeeper agentgoal_x
int - the x-coordinate of the enemy's
Returns an ACT
Working:
- Only shoots if within
AI_SHOOT_RADIUS
of the enemy goal - Shoots to maximize distance between keeper and shot while keeping the shot within goal boundaries
Note
- The origin is at top-left instead of the standard bottom-left so we map y to H-y
gk_move
| gk_move(goal_x, ball)
How the AI goalkeeper moves
Attributes:
goal_x
int - the x-coordinate of the enemy'sball
Ball - The football object
Returns an ACT
Working:
- Moves towards the ball (tracks the y coordinate)
- Does not go outside the goals boundary
gk_pass
| gk_pass(enemy_players, goal_x)
How the AI goalkeeper passes
Attributes:
enemy_players
list - A list of the positions (coordinates) of the enemy playersgoal_x
int - The x-coordinate of the team's goal post
Returns an ACT
Working:
- Pass such that enemy players in AI_SHOOT_RADIUS do not get the ball
move
| move(state_prev, state, reward, selected)
Umbrella function that is used to move the player. Overrides the Agent's move()
method
Returns an ACT
Working:
- if the selected player is the goal keeper and it has the ball: call
ai_gk_pass()
- else if the selected player is the goal keeper and it does not have the ball: call
ai_gk_move()
- else If the selected player is within
AI_SHOOT_RADIUS
of the enemy's goal post and it has the ball: callai_shoot()
- else If the selected player has the ball: call
ai_pass()
orai_move()
based on thePASS_PROB
- else call
ai_move_without_ball()
orai_move_with_ball()
OriginalAITeam Objects
class OriginalAITeam(Team)
The AI team used in the original (C++) version
select_player
| select_player(ball)
Select a player based on the balls position
Working:
- If ball is near the D-area, keeper gets automatic control
- Otherwise the player nearest to the ball has control (ties are broken randomly)
formation_dir
| formation_dir(id)
Send player (with the given ID) to his designated place in the formation
Working:
- If player is in-line (horizontally or vertically), move directly towards original point (U/L/D/R)
- Otherwise choose 2 directions that take you closer to the original point and choose one of them randomly (UL/UR/DL/DR)
move
| move(state_prev, state, reward)
Move each player in the team. Call this method to move the team