Project 4
Project 4
Project 4 - EuroLeague
In this project, you are asked to
implement functions that will enable you
to create, organize, play, and get
statistics for a basketball tournament.
In a league, there are several teams (numbers vary between leagues or even seasons), but let's
assume there are 20 teams. In the beginning of the season a fixture is prepared where each team
plays against all other teams twice. One in their home court, and one in the away court.
First half of the season has 3 weeks (number of teams - 1) and all teams complete their games
against all others once.
Week 1:
team1 vs. team2
team3 vs. team4
Week 2:
team1 vs. team3
team4 vs. team2
Week 3:
team1 vs. team4
team2 vs. team3
Second half of the season may create a new schedule or just copy this schedule with teams
swapping homes.
1
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
Week 4:
team2 vs. team1
team4 vs. team3
Week 5:
team3 vs. team1
team2 vs. team4
Week 6:
team4 vs. team1
team3 vs. team2
After each week, teams will score baskets, concede baskets, and there will be winners and losers.
At the end of the season, the team with the most wins will be the champion. If the wins are
equal, the team with the biggest score difference (scored - conceded) will be the champion.
2
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
Person class:
This is a base class that will hold the basic information about a person, and basic methods for
printing and comparison.
Methods Explanation
init (name, lastname) init method should take name and lastname
as parameters.
get_name() This method will return the full name of the player
with space in between. (name + ' '+ lastname).
>>> inst.get_name()
'Dimitris Diamantidis'
str () This method will return the full name of the player
with space in between. (name +' '+ lastname)
(same as the get_fullname method.)
>>> print(inst)
'Dimitris Diamantidis'
This method will implement less than operation between
lt ()
two Person instances. It will compare against their last
names, and if the last names are the same it will
compare against their names.
3
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
Player class:
This is a subclass that inherits from Person class and will hold information about the player, his
match contributions for each week and total performance.
● Each player will have a shooting power associated with him, and this number will be
randomly chosen when creating a new player using the given limits. This number
indicates how many shots a player will make for a total of 10 shots for a given
quarter.
● Each player will contribute to a match based on this shooting power, and each match is at
least 4 periods, so the player will contribute to the score at least 4 times. Each time he
contributes. The contribution score is explained in the Match class.
○ For example, a player with 6 shooting power can contribute 3 points in the first
period, 9 points in the second period, 5 points in the third period and 7 points in the
last period for a total of 24 points.
Methods Explanation
init (name, lastname) init method should take name and lastname as
parameters. It should set the internal variables for
name and last name. Additionally, It should
generate a shooting power randomly with an
integer value between [4,8] (both included).
>>> inst.get_points()
162
>>> inst.get_name()
'Dimitris Diamantidis'
>>> inst.get_power()
8
>>> inst.reset()
>>> inst.get_points()
0
>>> inst.get_name()
'Dimitris Diamantidis'
>>> inst.get_power()
8
4
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
get_id() This method will return the unique player ID. This
ID should be an internal instance counter that gets
assigned to the next player that is created. The
player ID should start from 1. (Note that this is the
counter for Player class)
>>> inst.get_id()
1
>>> inst2.get_id()
2
get_power() This method will return the player's shooting power
as an integer.
>>> inst.get_power()
8
set_team(t) This method will set the player's team to the given
Team instance.
>>> a = inst.get_team()
>>> print(a)
'Fenerbahce'
>>> inst.get_points()
110
>>> inst.add_to_points( 34 )
>>> inst.get_points()
144
get_points_detailed() This method will return the players' all
performances for all played weeks as a list.
>>> inst.get_points_detailed()
[30, 35, 32, 32, 33]
>>> inst.get_points_detailed() []
>>> inst.get_points()
162
>>> inst2.get_points()
166
lt () This method will implement less than operation
between two Player instances. It will compare
against their total points. If their points are the
same, it will compare against their last names, and
if the last names are the same it will compare
against their names.
Manager class:
This is a subclass that inherits from Person class and will hold information about the manager and
his influence weekly. Manager influence happens each week before the 1st period is played. A
random number is generated and this gets added to the score. This number should be added as
the manager's influence point for that week.
Methods Explanation
init (name, lastname) init method should take name and lastname as
parameters. It should set the internal variables for
name and last name.
>>> inst.get_influence()
35
6
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
>>> inst.get_name()
'Zeljko Obradovic'
>>> inst.reset()
>>> inst.get_influence()
0
>>> inst.get_name()
'Zeljko Obradovic'
get_id() This method will return the unique manager ID.
This ID should be an internal instance counter that
gets assigned to the next manager that is created.
The manager ID should start from 1.
>>> inst.get_id()
1
set_team(t) This method will set the manager's team to the
given Team instance.
>>> a = inst.get_team()
>>> print(a)
'Fenerbahce'
>>> inst.get_influence_detailed()
[10, 3, -5, -4]
>>> inst.get_influence_detailed()
[]
7
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
>>> inst.get_influence()
4
>>> inst2.get_influence()
-14
lt () This method will implement less than operation
between two Manager instances. It will compare
against their total influence points. If their points
are the same, it will compare against their last
names, and if the last names are the same it will
compare against their names.
8
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
Team class:
This class will hold information about the team, its players, its matches and its results. A team's
points is the number of wins.
Methods Explanation
9
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
>>> team1.reset()
get_id() This method will return the unique team ID. This ID
should be an internal instance counter that gets
assigned to the next team that is created. The team ID
should start from 1.
>>> team1.get_id()
1
>>> team1.get_name()
'Fenerbahce Beko Istanbul'
>>> a = team1.get_roster()
>>> print(a)
[< main .Player object at 0x10315ec40>,
< main .Player object at 0x10315eca0>,
...]
>>> a = team1.get_manager()
>>> print(a)
'Sasa Dordevic'
get_fixture() This method will return the team's own fixture as a list of
Match instances.
10
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
add_result(s) This method will add the given result to its results
and update the relevant internal lists / counters (i.e.
wins / losses / conceded / scored, etc.)
>>> team1.get_scored()
1301
>>> team1.get_conceded()
870
>>> team1.get_wins()
31
>>> team1.get_losses()
2
>>> team1.add_result( (102, 95) )
>>> team1.get_scored()
1403
>>> team1.get_conceded()
965
>>> team1.get_wins()
32
>>> team1.get_losses()
2
get_scored() This method will return the team's total scored
baskets as an integer.
>>> team1.get_scored()
1403
get_conceded() This method will return the team's total conceded
baskets as an integer.
>>> team1.get_conceded()
965
get_wins() This method will return the team's total wins as an
integer.
>>> team1.get_wins()
32
get_losses() This method will return the team's total losses as
an integer.
>>> team1.get_losses()
2
str () This method will return the name of the team just
like the get_name() method.
11
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
>>> print(inst)
'Fenerbahce Beko Istanbul'
lt () This method will implement less than operation
between two Team instances.
● It will compare against their total points.
● If their total points are equal, it will compare
against their score difference total.
● If that is equal as well, return either True or
False (does not matter).
Match class:
This class will hold information about a match between two teams. Matches should be generated
in the beginning of the season, and will be played according to the given rules.
Note that when adding match instances to the relevant lists (such as team's own fixture, or
season's fixture) you should not copy or create a new instance. Just add it as an alias so that one
change can appear in other places.
Methods Explanation
12
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
Example:
home_team:
- lion1 - 8
- lion2 - 7
- lion3 - 5
away_team:
- tiger1 - 4
- tiger2 - 8
- tiger3 - 8
13
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
>>> home_manager_point =
random.randint(10, 10)
-5
>>> away_manager_point =
random.randint(10, 10)
8
home_score = -5 + 22 + 20 + 32 + 15 = 84
away_score = 8 + 30 + 12 + 14 + 16 = 80
15
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
>>> print(inst)
'Fenerbahce Beko Istanbul vs. Maccabi Playtika Tel
Aviv'
>>> inst.play()
>>> print(inst)
'Fenerbahce Beko Istanbul (90) vs. (79) Maccabi
Playtika Tel Aviv'
Season class:
This is the class where everything is tied together. Its purpose is to create teams, assign players
and managers to the teams, create the season fixture, play the season matches and get statistics
about the season.
Methods Explanation
init (teams, managers, players) init method should take the filenames for the
teams, managers and the players.
https://en.wikipedia.org/wiki/Round-robin
_tournament
>>> inst.build_fixture()
get_week_fixture(week_no) This function should get the list of matches that will
be played on the given week. It should return as a
list of Match instances. If the week_no is 0 or more
than the number of weeks in a season, it should
return None
>>> a = inst.get_week_fixture(0)
>>> print(a)
None
>>> a = inst.get_week_fixture(1)
>>> print(a)
[< main .Match object at 0x10315ec40>,
< main .Match object at 0x10315eca0>]
17
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
>>> print(a[0])
team1 vs. team2
>>> print(a[1])
team3 vs. team4
>>> inst.play_week()
>>> a = inst.get_week_fixture(1)
>>> print(a)
[< main .Match object at 0x10315ec40>,
< main .Match object at 0x10315eca0>]
>>> print(a[0])
team1 vs. team2
>>> print(a[1])
team3 vs. team4
>>> inst.play_week()
18
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
>>> a = inst.get_players()
>>> print(a)
[< main .Player object at 0x10315ec40>,
< main .Player object at 0x10315eca0>,
...]
get_managers() This method will return a list of all managers in the
league as Manager instances.
>>> a = inst.get_managers()
>>> print(a)
[< main .Manager object at 0x10315ec40>, < main
.Manager object at 0x10315eca0>, ...]
>>> a = inst.get_teams()
>>> print(a)
[< main .Team object at 0x10315ec40>,
< main .Team object at 0x10315eca0>,
...]
get_season_length() This method will return the number of weeks that
the matches will be played in a season. For a 10
team season, it should return 18. (9 weeks first
half, 9 weeks second half)
>>> inst.get_season_length()
18
get_best_player() This method returns the best player at that week
as a Player instance.
>>> a = inst.get_best_player()
>>> print(a)
Name Lastname
>>> a = inst.get_best_manager()
>>> print(a)
Name Lastname
19
INF 211 - Algorithms and Programming I - Electronics Engineering - Gebze Technical University - Fall 2024
>>> a = inst.get_most_scoring_team()
>>> print(a)
team1
get_champion() This method returns the champion team as a Team
instance at the end of the season, If the season is
not complete, it should return None.
General Notes:
You should start implementing your classes one-by-one and test them individually before moving
to the next class.
● Person, Player, Manager classes should be very straight-forward as they are mostly
similar to what we worked on in the class.
● Team class is a little more involved such as
○ when we pass the players, we need to set each player's teams
○ we need to keep track of our wins and losses from game scores and game scores
should be in proper order.
● Match class requires extra attention because we play the match there with 4 periods and
keep track of the final score, team's score, player's score and manager's influence.
● Season class, while most of the stuff is easy to implement, building fixtures requires an
implementation of the given algorithms, and you need to be careful to get it right.
● The rest of the stuff is figuring out how things are connected and making sure using the
right methods for calculations.
● In general, you return the instance, instead of a string. Do not clone or copy the instance,
return it as is.
● In general, you should NOT access internal class variables directly. We tried to include as
many getters as possible. If you need and want, you can implement and add your own
methods. These list are the only ones that we will be testing.
20