Class ConsolePlayer

java.lang.Object
castle.comp3021.assignment.protocol.Player
castle.comp3021.assignment.player.ConsolePlayer
All Implemented Interfaces:
java.lang.Cloneable

public class ConsolePlayer
extends Player
The player that makes move according to user input from console.
  • Field Summary

    Fields inherited from class castle.comp3021.assignment.protocol.Player

    color, name, score
  • Constructor Summary

    Constructors 
    Constructor Description
    ConsolePlayer​(java.lang.String name)  
    ConsolePlayer​(java.lang.String name, Color color)  
  • Method Summary

    Modifier and Type Method Description
    @NotNull Move nextMove​(Game game, Move[] availableMoves)
    Choose a move from available moves.

    Methods inherited from class castle.comp3021.assignment.protocol.Player

    clone, equals, getColor, getName, getScore, hashCode, setScore, toString

    Methods inherited from class java.lang.Object

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

  • Method Details

    • nextMove

      @NotNull public @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.

      ConsolePlayer returns a move according to user's input in the console. The console input format should conform the format described in the assignment description. (e.g. a1->b3 means move the Piece at Place(x=0,y=0) to Place(x=1,y=2)) Note that in the Game.board, the index starts from 0 in both x and y dimension, while in the console display, x dimension index starts from 'a' and y dimension index starts from 1.

      Hint: be sure to handle invalid input to avoid invalid Moves.

      Attention: Student should make sure the Move returned is valid.

      Attention: Place object uses integer as index of x and y-axis, both starting from 0 to facilitate programming. This is VERY different from the coordinate used in console display.

      Specified by:
      nextMove in class Player
      Parameters:
      game - the current game object
      availableMoves - available moves for this player to choose from.
      Returns:
      the chosen move