ColorShapeLinks
An assignment for the AI course unit of the Bachelor in Videogames at Lusófona University
Match Struct Reference

Represents one match in a session. More...

Inherits IComparable< Match >.

Collaboration diagram for Match:
Collaboration graph

Public Member Functions

 Match (IPlayer player1, IPlayer player2)
 Create a new match. More...
 
override string ToString ()
 A string representation of this match. More...
 
int CompareTo (Match other)
 Compares this match with another match. Comparisons are made using an internal ID, except if the players are the same and in the same order, in which case matches are considered equal, even if they have different internal IDs. More...
 
override int GetHashCode ()
 Returns a hash code for this match. More...
 
override bool Equals (object obj)
 Is the current match equal to the given object? Equality is verified if obj is a Match object, and if it contains the same players in the same positions. More...
 

Public Attributes

readonly IPlayer player1
 First player in this match (white). More...
 
readonly IPlayer player2
 Second player in this match (ref). More...
 
IPlayer this[PColor color]
 Indexer for getting a player based on his color. More...
 
Match Swapped => new Match(player2, player1)
 A match with the players swapped. More...
 

Detailed Description

Represents one match in a session.

Definition at line 13 of file Match.cs.

Constructor & Destructor Documentation

◆ Match()

Match ( IPlayer  player1,
IPlayer  player2 
)
inline

Create a new match.

Parameters
player1First player in match (white).
player2Second player in match (red).

Definition at line 45 of file Match.cs.

Member Function Documentation

◆ CompareTo()

int CompareTo ( Match  other)

Compares this match with another match. Comparisons are made using an internal ID, except if the players are the same and in the same order, in which case matches are considered equal, even if they have different internal IDs.

Parameters
otherThe match to compare the current match with.
Returns
  • Zero if players are the same and are in the same order.
  • Negative value if current match was created before match given in other .
  • Positive value if current match was created after match given in other .

◆ Equals()

override bool Equals ( object  obj)
inline

Is the current match equal to the given object? Equality is verified if obj is a Match object, and if it contains the same players in the same positions.

Parameters
objObject to check for equality with this match.
Returns
true if this match is equal to obj , false otherwise.

Definition at line 91 of file Match.cs.

◆ GetHashCode()

override int GetHashCode ( )

Returns a hash code for this match.

Returns
Hash code obtain from the string concatenation of the player's names.

◆ ToString()

override string ToString ( )

A string representation of this match.

Returns
A string representation of this match.

Member Data Documentation

◆ player1

readonly IPlayer player1

First player in this match (white).

Definition at line 22 of file Match.cs.

◆ player2

readonly IPlayer player2

Second player in this match (ref).

Definition at line 25 of file Match.cs.

◆ Swapped

Match Swapped => new Match(player2, player1)

A match with the players swapped.

A new match instance.

Definition at line 40 of file Match.cs.

◆ this[PColor color]

IPlayer this[PColor color]
Initial value:
=> color == PColor.White ? player1
: color == PColor.Red ? player2
: throw new InvalidOperationException(
$"Invalid player color")

Indexer for getting a player based on his color.

Parameters
colorPlayer color.
Returns
The player associated with the given color.
Exceptions
System.InvalidOperationExceptionThrown when an invalid color is given.

Definition at line 33 of file Match.cs.


The documentation for this struct was generated from the following file:
Match.player1
readonly IPlayer player1
First player in this match (white).
Definition: Match.cs:22
PColor
PColor
Piece colors.
Definition: PColor.cs:9
Match.player2
readonly IPlayer player2
Second player in this match (ref).
Definition: Match.cs:25