Match

class Match(val home: Club, val away: Club, val homeScorers: Vector[Player], val awayScorers: Vector[Player])

Each object of the class Match represents a state of a football match. A match is played between teams from two clubs: a home club and an away club. Goals scored by players of either team can be added to the match object with the method addGoal, which produces a new Match object representing the updated state of the match. Each Match object is immutable.

Value parameters:
away

the club whose team plays away in the match

awayScorers

the players who have scored goals for the away team so far (in order for each goal; the same player appears multiple times if they have scored multiple goals)

home

the club whose team plays at home in the match

homeScorers

the players who have scored goals for the home team so far (in order for each goal; the same player appears multiple times if they have scored multiple goals)

class Object
trait Matchable
class Any

Value members

Concrete methods

def addGoal(scorer: Player): Match

Records a goal as having been scored by the given player and produces a match object that represents the updated state of the match. This assumes that the given player plays for one of the participating clubs; if not, this method simply returns unmodified match object itself.

Records a goal as having been scored by the given player and produces a match object that represents the updated state of the match. This assumes that the given player plays for one of the participating clubs; if not, this method simply returns unmodified match object itself.

Value parameters:
scorer

the goalscoring player (who scores the goal for his or her own team)

Returns:

a new match object that is otherwise the same as this one, but has one more goal

Returns a vector that contains all the players who scored in the match. In the vector, all the players who scored for the home team appear (in the order in which they scored) before the players who scored for the away team (also in scoring order amongst themselves). A player will appear in the vector as many times as they scored.

Returns a vector that contains all the players who scored in the match. In the vector, all the players who scored for the home team appear (in the order in which they scored) before the players who scored for the away team (also in scoring order amongst themselves). A player will appear in the vector as many times as they scored.

Returns the number of goals that have been scored (so far) by the away team.

Returns the number of goals that have been scored (so far) by the away team.

Returns the goal difference of the match. The sign of the number indicates which team scored more goals.

Returns the goal difference of the match. The sign of the number indicates which team scored more goals.

Returns:

the goal difference as a positive number if the home team won, a negative number if the away team won, or zero in case of a tied match

def hasScorer(possibleScorer: Player): Boolean

Returns a Boolean value indicating whether the given player scored in this match.

Returns a Boolean value indicating whether the given player scored in this match.

Returns the number of goals that have been scored (so far) by the home team.

Returns the number of goals that have been scored (so far) by the home team.

Returns a Boolean value indicating whether the away team won (or would win if the match ended with the current score). Tied scores produce false.

Returns a Boolean value indicating whether the away team won (or would win if the match ended with the current score). Tied scores produce false.

Determines whether this match is entirely goalless, that is, whether neither team has scored a single goal.

Determines whether this match is entirely goalless, that is, whether neither team has scored a single goal.

def isHigherScoringThan(anotherMatch: Match): Boolean

Determines whether this match has a higher total score than another given match.

Determines whether this match has a higher total score than another given match.

Returns:

true if more goals were scored in total in this match than in the given match, false otherwise

Returns a Boolean value indicating whether the home team won (or would win if the match ended with the current score). Tied scores produce false.

Returns a Boolean value indicating whether the home team won (or would win if the match ended with the current score). Tied scores produce false.

Returns a Boolean value indicating whether the game ended in a draw (or would do so if the match ended with the current score).

Returns a Boolean value indicating whether the game ended in a draw (or would do so if the match ended with the current score).

Returns the name of the stadium where the match is played. That is, returns the name of the home team’s stadium.

Returns the name of the stadium where the match is played. That is, returns the name of the home team’s stadium.

override def toString: String

Produces a textual description of the match’s current state, in a format illustrated by the examples below. In these examples, Liverpool is the name of the home team, Everton the name of the away team, and Anfield the name of the home team’s stadium.

Produces a textual description of the match’s current state, in a format illustrated by the examples below. In these examples, Liverpool is the name of the home team, Everton the name of the away team, and Anfield the name of the home team’s stadium.

Goalless draw (no goals for either side):

Liverpool vs. Everton at Anfield: tied at nil-nil

Other tied score (e.g., 2–2):

Liverpool vs. Everton at Anfield: tied at 2-all

Home score higher (e.g., 4–0):

Liverpool vs. Everton at Anfield: 4-0 to Liverpool

Away score higher (e.g., 2–4):

Liverpool vs. Everton at Anfield: 4-2 to Everton

Note that although the name of the home team is always listed first, but the leader’s score is shown first, even if the away team is leading.

Definition Classes

Returns the total number of goals scored by the two teams.

Returns the total number of goals scored by the two teams.

Returns the club whose team won the match (or is about to win it, assuming the current result stands). That is, returns the club who has scored more goals than the other one. The club is wrapped in an Option; None is returned if the game is tied.

Returns the club whose team won the match (or is about to win it, assuming the current result stands). That is, returns the club who has scored more goals than the other one. The club is wrapped in an Option; None is returned if the game is tied.

Returns the name of the club whose team won the match (or is about to win it, assuming the current result stands). If the game is tied, returns the string "no winner".

Returns the name of the club whose team won the match (or is about to win it, assuming the current result stands). If the game is tied, returns the string "no winner".

Returns the player who scored the so-called “winning goal”. The winning goal of a match is the earliest goal for the winning team that is “necessary for the win” in the light of the scoreline.

Returns the player who scored the so-called “winning goal”. The winning goal of a match is the earliest goal for the winning team that is “necessary for the win” in the light of the scoreline.

For instance, if the score is 4–2 to the home team, then the third goal scored by the home team is the winning goal, because the winning team needed to score at least three goals to beat the losing team’s score of two.

More examples: if the losing team has scored 0 goals, the winning goal is the winning team’s first goal; if the losing team has scored 1 goal, the winning goal is the winning team’s second goal; and so on. In other words, if the losing team has scored X goals, the winning goal is the (X+1)th goal scored by the winning team.

If scores are even, there is no winning goal or winning goal scorer.

Returns:

the scorer of the winning goal, wrapped in an Option; None if there is no winning goal

Concrete fields

val away: Club
val home: Club