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

    Fields 
    Modifier and Type Field Description
    protected Color color
    The color representing this player
    protected java.lang.String name
    The name of a player.
    protected int score
    The game score of this player.
  • Constructor Summary

    Constructors 
    Constructor Description
    Player​(java.lang.String name, Color color)  
  • 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()  

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • name

      protected final java.lang.String name
      The name of a player. By default, name is a unique identifier to distinguish different players. But this can be overrided by overriding equals(Object) method.
    • score

      protected int score
      The game score of this player. Score will be updated whenever the player makes a move through Game.updateScore(Player, Piece, Move) and setScore(int)
    • color

      protected final Color color
      The color representing this player
  • Constructor Details

    • Player

      public Player​(java.lang.String name, Color color)
  • Method Details

    • equals

      public boolean equals​(java.lang.Object o)
      Overrides:
      equals in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.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 class java.lang.Object
    • getColor

      public final Color getColor()
      Get color used to represent this player.
      Returns:
      color of this player
    • clone

      public Player clone() throws java.lang.CloneNotSupportedException
      Overrides:
      clone in class java.lang.Object
      Throws:
      java.lang.CloneNotSupportedException
    • nextMove

      @NotNull public abstract @NotNull Move nextMove​(Game game, Move[] availableMoves)
      Choose a move from available moves. This method will be called by Game object to get the move that the player wants to make when it is the player's turn.
      Parameters:
      game - the current game object
      availableMoves - available moves for this player to choose from.
      Returns:
      the chosen move