Skip to content

amrod/swiss-tournament

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 

Repository files navigation

Swiss-system Tournament

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.

Setup

  1. If using Vagrant:
  2. Install Vagrant and VirtualBox.
  3. Launch the Vagrant VM. A Vagrantfile and accompanying shell script are provided to setup all necessary software.
  4. If not using Vagrant, you can just run the provided pg_config.sh script to setup all necessary software.
  5. 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

Using tournament.py

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.

Register the players

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")

Generate pairings

To determine which player will play with which player using the Swiss pairings system, use the swissPairings method:

pairs = t1.swissPairings()

Reporting matches

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])

About

Udacity Full Stack Nanodegree Project #2

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published