GithubHelp home page GithubHelp logo

ladder's Introduction

Warning: this is highly WIP! Please don't use if you're afraid of losing functionality or data!

Ladder

A real simulator for fake sports. Teams can be defined using arbitrary values, and are then played off against each other in a league, including a main season and finals series. A summary of results is outputted in the interface, and a CSV file named out.csv is created detailing the outcomes of all games played.

An example session

Installation Instructions

  1. Clone the repository with git clone https://github.com/kdelwat/Ladder.git.
  2. Ensure the dependencies are installed.
  3. Navigate to the repository folder and run python main.py.
  4. Open http://127.0.0.1:8081/ in your browser.

Dependencies

Usage

The GUI itself should be fairly self-explanatory. The "Load Teams" button accepts a CSV file describing the league's teams in the following format:

Name,Strength
Melbourne Stars,8
Melbourne Renegades,5
Sydney Thunder,10
Sydney Sixers,6
Adelaide Strikers,7
Hobart Hurricanes,4
Brisbane Heat,5
Perth Scorchers,7

It is important to note that, apart from name, any field can be used to provide information about teams, as long as the chosen sport supports that field.

Extending

The main benefit of using Ladder is its extensibility. New sports can be created quickly.

In sports.py, the sport is defined as a function. The basic template for a sport is as follows:

def basic_game(team1, team2, teams, settings):
    # A template for all games. The game must take two team dictionaries.

    # If the game is won by a team, the result is set to the WIN constant.
    # If the game is drawn, the result is set to the DRAW constant.
    result = WIN

    # If the game has a winner, the winner is set to the name of the winning
    # team and the loser to the name of the losing team. In the event of a
    # draw, order does not matter, but both variables must still be filled.
    winner = team1
    loser = team2

    # All extra game statistics are stored in the stats dictionary. The key for
    # each entry is the name of the statistic.
    stats = {}

    # The game must return this information in the following tuple format.
    return (result, winner, loser, stats)

The new function must then be added to the games dictionary at the bottom of the file, in the following form:

'Name': {'parameters': [],
         'function_name': fn,
         'settings': {}}

In this form,

  • Name is the human-readable name of the sport which will be automatically added to the selection dropdown.
  • parameters is a list of parameters included for each team. For cricket, the default is ['Name', 'Strength'], but this can be changed to suit any data.
  • function_name is the simulation function itself.
  • settings is a dictionary, where each key-value pair is an option and its value.

A simple example of a full sport is displayed below.

def football(team1, team2, teams, settings):
    '''Simulate a game of football (soccer).'''

    if teams[team1]['Strength'] == teams[team2]['Strength']:
        result = DRAW
        winner = team1
        loser = team2
    else:
        result = WIN
        if teams[team1]['Strength'] > teams[team2]['Strength']:
            winner = team1
            loser = team2
        else:
            winner = team2
            loser = team1

    # Generate winner statistics
    winning_goals = random.randint(1, 3)

    if result == DRAW:
        losing_goals = winning_goals
    else:
        losing_goals = random.randint(0, winning_goals - 1)

    stats = {'Winning Score': winning_goals,
             'Losing Score': losing_goals}

    return ((result, winner, loser, stats), teams)

games = {'Football (soccer)': {'parameters': ['Name', 'Strength', 'Goals'],
                               'function_name': football,
                               'settings': {'max_goals': '3',
                                            'min_goals': '1'}}}

ladder's People

Contributors

kdelwat avatar

Watchers

 avatar

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.