Class Player
java.lang.Object
castle.comp3021.assignment.protocol.Player
- All Implemented Interfaces:
java.lang.Cloneable
- Direct Known Subclasses:
ConsolePlayer,RandomPlayer
public abstract class Player
extends java.lang.Object
implements java.lang.Cloneable
Player interface for the game.
Implementations could be computer player or human player.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and Type Method Description Playerclone()booleanequals(java.lang.Object o)ColorgetColor()Get color used to represent this player.java.lang.StringgetName()intgetScore()inthashCode()abstract @NotNull MovenextMove(Game game, Move[] availableMoves)Choose a move from available moves.voidsetScore(int score)java.lang.StringtoString()
-
Field Details
-
name
protected final java.lang.String nameThe name of a player. By default, name is a unique identifier to distinguish different players. But this can be overrided by overridingequals(Object)method. -
score
protected int scoreThe game score of this player. Score will be updated whenever the player makes a move throughGame.updateScore(Player, Piece, Move)andsetScore(int) -
color
The color representing this player
-
-
Constructor Details
-
Method Details
-
equals
public boolean equals(java.lang.Object o)- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCodein classjava.lang.Object
-
getName
public final java.lang.String getName() -
getScore
public final int getScore() -
setScore
public final void setScore(int score) -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
getColor
Get color used to represent this player.- Returns:
- color of this player
-
clone
- Overrides:
clonein classjava.lang.Object- Throws:
java.lang.CloneNotSupportedException
-
nextMove
Choose a move from available moves. This method will be called byGameobject to get the move that the player wants to make when it is the player's turn.- Parameters:
game- the current game objectavailableMoves- available moves for this player to choose from.- Returns:
- the chosen move
-