This 2D football simulation allows you to write custom strategies for a team and see how they perform against another team. Below are the key guidelines and rules you need to follow:
- To participate in the simulation, you need to implement the
play
method. This method should be defined in eitherteam1.py
orteam2.py
. - The
play
method will be executed in each cycle of the game, and it's responsible for making decisions based on the current state of the game.
- You should always assume that your team is the red team and that you are attacking from left to right. This means that you can copy and paste the exact same code from
team1.py
toteam2.py
, and the runner code will handle the rest. - If you place your code in
team1.py
, you will be the red team. If you place your code inteam2.py
, you will be the blue team. However, regardless of where you place your code, you should always write your strategy with the assumption that you are the red team.
- The game consists of 500 cycles. In each cycle, your
play
method will be executed, and you must make decisions for that cycle. These decisions will affect the behavior of your players and potentially the outcome of the game.
- In each cycle, the decisions from both teams will be executed in the order you specify in your decision list.
- However, there is a randomness factor in how the decisions from both teams are merged within that cycle. This randomness determines the order in which actions from each team are executed, simulating the unpredictability of real-world football.
- Your
play
method must complete its execution within 0.5 seconds. If your code takes longer than this to run, it will be timed out and ignored for that cycle, which could negatively impact your team's performance.
- Penalty Area Rule: If more than 3 players from the same team are in their penalty area, the extra players will be kicked out of the game and banned for 20 cycles. Banned players cannot make any decisions during their ban.
- Ball Proximity Rule: If more than 2 players from the same team are within a distance of 54 units from the ball, the extra players will be kicked out of the game and banned for 25 cycles. Banned players cannot make any decisions during their ban.
- To start the game, run the
main.py
script.
ALLOWED_PLAYERS_IN_PENALTY_AREA_NUMBER = 3
ALLOWED_PLAYERS_AROUND_BALL_NUMBER = 1
ALLOWED_PLAYERS_AROUND_BALL_RADIUS = make_even_number(3 * (PLAYER_RADIUS + BALL_RADIUS)) # 54
BALL_CROWDED_BAN_CYCLES = 25
PENALTY_ARIA_BAN_CYCLES = 20
-
Input: In each execution of the
play
method, you will receive input variables representing the current state of the game. The examples below use sample numbers for illustration:- red_players: (Example)
[ {'x': -428, 'y': 0, 'name': 'Player0', 'number': 0, 'radius': 18, 'ban_cycles': 0}, {'x': -334, 'y': 216, 'name': 'Player1', 'number': 1, 'radius': 10, 'ban_cycles': 0}, {'x': -250, 'y': -217, 'name': 'Player2', 'number': 2, 'radius': 10, 'ban_cycles': 0}, {'x': -167, 'y': 216, 'name': 'Player3', 'number': 3, 'radius': 10, 'ban_cycles': 0}, {'x': -83, 'y': -217, 'name': 'Player4', 'number': 4, 'radius': 10, 'ban_cycles': 0}, {'x': 0, 'y': 216, 'name': 'Player5', 'number': 5, 'radius': 10, 'ban_cycles': 0}, ]
- blue_players: (Example)
[ {'x': 428, 'y': 0, 'name': 'Player0', 'number': 0, 'radius': 18, 'ban_cycles': 0}, {'x': 334, 'y': -216, 'name': 'Player1', 'number': 1, 'radius': 10, 'ban_cycles': 0}, {'x': 250, 'y': 217, 'name': 'Player2', 'number': 2, 'radius': 10, 'ban_cycles': 0}, {'x': 167, 'y': -216, 'name': 'Player3', 'number': 3, 'radius': 10, 'ban_cycles': 0}, {'x': 83, 'y': 217, 'name': 'Player4', 'number': 4, 'radius': 10, 'ban_cycles': 0}, {'x': 0, 'y': -216, 'name': 'Player5', 'number': 5, 'radius': 10, 'ban_cycles': 0}, ]
- ball: (Example)
{'x': 0, 'y': 0, 'radius': 8, 'owner_color': None, 'owner_number': None, 'speed': 0, 'direction': None}
owner_color
choices:red
,blue
owner_number
choices:0,1,2,3,4,5
- scoreboard: (Example)
{'red_score': 0, 'blue_score': 0, 'cycle_number': 1}
- max
cycle_number
: 500
- max
- red_players: (Example)
-
Output: The output of your
play
method must be a decision list. This list should contain the actions your players will take in that cycle. The available decisions are:- Move Decision: (Example)
{ 'type': 'move', 'player_number': 3, 'destination': {'x': 190, 'y': 30}, 'speed': 10, }
player_number
: from 0 to 5destination
must be inside the football screenspeed
: from 1 to 10
- Grab Decision: (Example)
{ 'type': 'grab', 'player_number': 3, }
- The distance between the player and the ball must be less than 18 units to catch the ball (26 units for player number 0)
- If the ball is not owned by any other player, the grab request will be successful with 100% probability
- If the ball is owned by any other player, the grab request will be successful with 50% probability
- Kick Decision: (Example)
{ 'type': 'kick', 'player_number': 3, 'direction': 20, 'power': 60, }
- The player must be the owner of the ball
direction
: from 0 to 360- You can use the
get_direction
function to obtain the direction power
: from 1 to 60- friction: 5
- Move Decision: (Example)
By following these guidelines and rules, you can develop a strategy and see how it performs in the simulation. Good luck, and may the best strategy win!