Class RandomPlayer

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

public class RandomPlayer
extends Player
A computer player that makes a move randomly.
  • Field Summary

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

    color, name, score
  • Constructor Summary

    Constructors 
    Constructor Description
    RandomPlayer​(java.lang.String name)  
    RandomPlayer​(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.

      RandomPlayer chooses a move from available ones randomly.

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

      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