This is a Python module that uses a PostgreSQL database to keep track of players and matches in a game tournament. Player matching is done using the Swiss system. This is project number 2 in Udacity's Fullstack Nanodegree program.
- If using Vagrant:
- Install Vagrant and VirtualBox.
- Launch the Vagrant VM. A Vagrantfile and accompanying shell script are provided to setup all necessary software.
- If not using Vagrant, you can just run the provided
pg_config.sh
script to setup all necessary software. - Execute the SQL script
tournament.sql
to create the database. You can do this from the command line with:
psql -f tournament.sql
Or start psql and then load the script:
\i tournament.sql
The module tournament.py contains the class Tournament. Each instance of Tournament represents a tournament. To run multiple tournaments simply create multiple instances.
from tournament import Tournament
t1 = Tournament("Chess Finals")
t2 = Tournament("Otello Finals")
The Tournament class handles its connection to the database. The connection is closed as soon as the instance is destroyed.
Before matches can start, players must be registered for the tournament. Registering a player also enrolls them to the current tournament.
t1.registerPlayer("Guido")
t1.registerPlayer("Mark")
To determine which player will play with which player using the Swiss pairings system, use the swissPairings
method:
pairs = t1.swissPairings()
After the players have matches in pairs as generated by swissPairings
, report the winners and losers:
p = pairs[0]
ti.reportMatch(p[0], p[2])