-
Notifications
You must be signed in to change notification settings - Fork 0
/
Match.py
100 lines (74 loc) · 2.77 KB
/
Match.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# -*- coding: utf-8 -*-
"""Base class for matches."""
# Copyright (C) 2015 Alexander Jones
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
class Match(object):
"""Base class for matches."""
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