Giter Club home page Giter Club logo

2d_soccer_simulation's Introduction

How to Play the 2D Football Simulation

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:

Implementing the play Method

  • To participate in the simulation, you need to implement the play method. This method should be defined in either team1.py or team2.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.

Team Assignment

  • 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 to team2.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 in team2.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.

Game Cycles

  • 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.

Execution of Decisions

  • 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.

Execution Time Limit

  • 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.

Ban Rules

  • 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.

Starting the Game

  • To start the game, run the main.py script.

Constants

  • 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 and Output of the play Method

  • 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
  • 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 5
      • destination must be inside the football screen
      • speed: 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

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!

2d_soccer_simulation's People

Contributors

mojtaba1996 avatar

Stargazers

 avatar  avatar Ali Shamakhi avatar Roozbeh Sharifnasab avatar _hazed avatar  avatar asalehe avatar Hossein avatar  avatar Radin Jarireh avatar Mahdi Abedini avatar Amir Mirzaei avatar Ali Jomeiy avatar Pooya Shams kolahi avatar  avatar  avatar

Watchers

 avatar  avatar

2d_soccer_simulation's Issues

the_map.check_if_ball_is_crowded()

the_map.check_if_ball_is_crowded() will result in movement of the ball to the up-middle
part of the map if the owner of the ball is chosen

Scores

you should print out the scores after the end of the game or at least let us see the map until we close it ourselves.

Asymmetric warfare

Your program doesn't work really well for the blue team. It just does some probably random things. Please correct the code so we could test our AIs with other students.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.