Skip to content

Commit

Permalink
API and class hierarchy changes
Browse files Browse the repository at this point in the history
This commit adds automated walkover detection and read-only generic
competitor fields for both player-based and team-based matches.
A modified class hierarchy has been established below Match.

Due to the significant class hierarchy and API changes relative to
the existing API, the version has been bumped to 0.2.
  • Loading branch information
happy5214 committed Jul 5, 2016
1 parent a0d436a commit fab1baa
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 9 deletions.
7 changes: 7 additions & 0 deletions README.rst
Expand Up @@ -7,6 +7,13 @@ competitions series of packages.
This package will include simple default match simulators to support basic usage
of this system with competitions-cup and competitions-league, among others.

Changes in v0.2
---------------

- Generic competitor fields
- Walkover detection for two-competitor matches
- Modified class hierarchy

.. image:: https://travis-ci.org/happy5214/competitions-match.svg?branch=master
:alt: Build status
:target: https://travis-ci.org/happy5214/competitions-match
Expand Down
72 changes: 72 additions & 0 deletions competitions/match/Match.py
Expand Up @@ -26,3 +26,75 @@ class Match(object):
def play(self):
"""Play the match."""
raise NotImplementedError


class TwoCompetitorMatch(Match):

"""Base class for matches with exactly two competitors."""

@property
def competitor1(self):
"""The first (usually home) competitor."""
raise NotImplementedError

@property
def competitor2(self):
"""The second (usually away) competitor."""
raise NotImplementedError

@property
def is_walkover(self):
"""Whether or not this match is a walkover/bye."""
return self.competitor1 is None or self.competitor2 is None


class TwoTeamMatch(TwoCompetitorMatch):

"""Base class for two-team matches."""

def __init__(self, team1, team2):
"""Constructor.
@param team1: The first (home) team
@type team1: An object that can be converted to a string
@param team2: The second (away) team
@type team2: An object that can be converted to a string
"""
self.team1 = team1
self.team2 = team2

@property
def competitor1(self):
"""The first (usually home) competitor."""
raise self.team1

@property
def competitor2(self):
"""The second (usually away) competitor."""
raise self.team2


class TwoPlayerMatch(TwoCompetitorMatch):

"""Base class for two-player matches."""

def __init__(self, player1, player2):
"""Constructor.
@param player1: The first (home) player
@type player1: An object that can be converted to a string
@param player2: The second (away) player
@type player2: An object that can be converted to a string
"""
self.player1 = player1
self.player2 = player2

@property
def competitor1(self):
"""The first (usually home) competitor."""
raise self.player1

@property
def competitor2(self):
"""The second (usually away) competitor."""
raise self.player2
7 changes: 3 additions & 4 deletions competitions/match/default/SimpleMatch.py
Expand Up @@ -20,10 +20,10 @@

import random

from competitions.match.Match import Match
from competitions.match.Match import TwoTeamMatch


class SimpleMatch(Match):
class SimpleMatch(TwoTeamMatch):

"""A simple default match simulator based on the card game "War"."""

Expand All @@ -35,8 +35,7 @@ def __init__(self, team1, team2):
@param team2: The second (away) team
@type team2: An object that can be converted to a string
"""
self.team1 = team1
self.team2 = team2
super(SimpleMatch, self).__init__(team1, team2)
self.score1 = ''
"""The score for team1."""
self.score2 = ''
Expand Down
7 changes: 3 additions & 4 deletions competitions/match/default/TestMatch.py
Expand Up @@ -18,10 +18,10 @@

from __future__ import unicode_literals

from competitions.match.Match import Match
from competitions.match.Match import TwoTeamMatch


class TestMatch(Match):
class TestMatch(TwoTeamMatch):

"""A match simulator for tests."""

Expand All @@ -33,8 +33,7 @@ def __init__(self, team1, team2):
@param team2: The second (away) team
@type team2: An object that can be converted to a string
"""
self.team1 = team1
self.team2 = team2
super(TestMatch, self).__init__(team1, team2)
self.score1 = ''
"""The score for team1."""
self.score2 = ''
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -13,7 +13,7 @@

setup(
name='competitions-match',
version='0.1.3',
version='0.2',

description='competitions support library for matches',
long_description=long_description,
Expand Down

0 comments on commit fab1baa

Please sign in to comment.