Soccer game simulation

Problem description

A playing area is 100m x 100m. A game has a referee and 10 players. A player moves 1m every second and starts out in a random place on the playing area. A referee gives a yellow card to a player if that player moves within 2m of another player. It is the player that moves to within 2m of another player, that gets the yellow card. If a player gets 2 yellow cards, the player is ejected from the game for 10 seconds. When a player is sent off the player needs to ask the referee if they are eligible to play again. The referee will let the player return to playing the first time this happens, but not subsequent times. The last player left playing is the winner.


  • Install python development packages, geos lib with development packages
  • clone mercurial repo from
  • go to repo directory
  • type python
  • wait until buildout is generated
  • run bin/buildout to set up local run environment with all dependencies.


  • Go to cloned repo
  • type bin/soccer -h to get detailed command call help (you can run game simulation with different params than from problem description)
  • type bin/soccer to run game simulation with default params.

Implementation details

Game simulation is written in Python, with minimal dependencies. I've used Shapely ( library for geometry calculations. Game is run with small CLI wrapper (see soccer/game/ for details). Main point of simulation is class, which inits game and performs round-by-round actions. There are two actor classes: Referee and Player. Referee checks if player moves correctly, Player performs move within field and keeps bookkeeping of it's yellow cards and come backs count. Referee will check those values and remove player from field (or from game) on certain conditions.

Game simulation may takes some time to complete. To make simulation quicker, consider shrinking playable area and increasing min allowed distance.


  • Players start within playable field, on random positions, but with distance greater than allowed between themselves.
  • Game is run in rounds, each round is 1 second of gameplay.
  • Players can move in any direction with constant speed.
  • Players must move straigh (more complex movement path requires more time for implementation).
  • When player is back on field, he has to move. Then, move is evaluated by Referee, after regular movement of other players.