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 Player
clone()
boolean
equals(java.lang.Object o)
Color
getColor()
Get color used to represent this player.java.lang.String
getName()
int
getScore()
int
hashCode()
abstract @NotNull Move
nextMove(Game game, Move[] availableMoves)
Choose a move from available moves.void
setScore(int score)
java.lang.String
toString()
-
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:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()- Overrides:
hashCode
in 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:
toString
in classjava.lang.Object
-
getColor
Get color used to represent this player.- Returns:
- color of this player
-
clone
- Overrides:
clone
in classjava.lang.Object
- Throws:
java.lang.CloneNotSupportedException
-
nextMove
Choose a move from available moves. This method will be called byGame
object 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
-