Skip to content

Build a database backed application that determines the winner of a swiss-style game tournament.

Notifications You must be signed in to change notification settings

MomokoXu/Project-Tournament-Database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 

Repository files navigation

Swiss Tournament Planner

Introduction

This project aims to implement a game tournament planner which uses the Swiss system for pairing up players in each round. Players are not eliminated, and each player is paired with another player with the same number of wins, or as close as possible. Python is the main development language used to create module that uses PostrgreSQL database to kepp track of players and matches in a game tournament. More Information

Prerequisites and Installation

Prerequisites

  1. Git
  2. VirtualBox: You do not need the extension pack or the SDK. You do not need to launch VirtualBox after installing it; Vagrant will do that.
  3. Vagrant: Install the version for your operating system.

Installation steps

  1. Open your terminal:
    • Mac or Linux system: regular terminal program will do just fine.
    • Windows: use the Git Bash terminal that comes with the Git software, if you don't have Git installed, download Git from the link above.
  2. Install VirtualBox
  3. Install Vagrant
  4. Clone the VM configuration:
    • Change to the desired directory for you to run this project
      • eg. Run: cd ~/Desktop
    • Run: git clone https://github.com/udacity/fullstack-nanodegree-vm. fullstack in your terminal
  5. Clone this project:
    • Change to vagrant folder:
      • Run: cd fullstack/vagrant/
    • Clone this project:
      • Run: git clone https://github.com/MomokoXu/Project-Tournament-Database.git tournament
  6. Start the virtual machine:
    • Run: vagrant up

How to use it

  1. Log into the VM:
    • Run: vagrant ssh
  2. Change directory for the files of this project:
    • Run: cd /vagrant/tournament/project/tournament
  3. Create the tournament database:
    • Run: psql -f tournament.sql
  4. Test the whole application using Udacity test style:
    • Run: python tournament_test.py
  5. Test the database and application as you like:
    1. Enter Python:
      • run: python
    2. Import application in python:
      • run: import tournament
    3. Test individual function as you like:
      • eg. run: tournament.registerPlayer('Momoko')
  6. To clear the database, you can run step 3 or manually call functions deleteMatches() and then deletePlayers().

Functions in tournament.py

(From Udacity project Description)

  • registerPlayer(name):

    • Adds a player to the tournament by putting an entry in the database. The database should assign an ID number to the player. Different players may have the same names but will receive different ID numbers.
    • Example:
      >>> tournament.registerPlayer("momoko")
      Player: momoko has been added!
      >>> tournament.registerPlayer("Cherry")
      Player: Cherry has been added!
      >>> tournament.registerPlayer("Kitten")
      Player: Kitten has been added!
      >>> tournament.registerPlayer("Puppy")
      Player: Puppy has been added!
  • countPlayers():

    • Returns the number of currently registered players.
    • Example:
      >>> tournament.countPlayers()
      There are 4 players now.
  • reportMatch(winner, loser):

    • Stores the outcome of a single match between two players in the database.
    • Example:
      >>> tournament.reportMatch(1, 2)
      Match has been recorded.
      >>> tournament.reportMatch(3, 4)
      Match has been recorded.
  • playerStandings():

    • Returns a list of (id, name, wins, matches) for each player, sorted by the number of wins each player has.
    • Example:
      >>> tournament.playerStandings()
      [(1, 'Momoko', 1L, 1L), (3, 'Kitten', 1L, 1L),
      (2, 'Cherry', 0L, 1L), (4, 'Puppy', 0L, 1L)]
  • swissPairings():

    • Given the existing set of registered players and the matches they have played, generates and returns a list of pairings according to the Swiss system. Each pairing is a tuple (id1, name1, id2, name2), giving the ID and name of the paired players. For instance, if there are eight registered players, this function will return four pairings. This function uses playerStandings to find the ranking of players
    • Example:
      >>> tournament.swissPairings()
      [(1, 'Momoko', 3, 'Kitten'), (2, 'Cherry', 4, 'Puppy')]
  • deleteMatches():

    • Clear out all the match records from the database.
    • Example:
      >>> tournament.deleteMatches()
      All matches have been deleted!
  • deletePlayers():

    • Clear out all the player records from the database.
    • Example:
      >>> tournament.deletePlayers()
      All players have been removed!

Future work

This project currently only supports to plan single tournament, in the future it is supposed to be extended to support multiple tournaments.

Author

Yingtao Xu

Copyright

This is a project for practicing skills in databses and backend courses not for any business use. Some templates and file description are used from Udacity FSND program. Please contact me if you think it violates your rights.

About

Build a database backed application that determines the winner of a swiss-style game tournament.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages