Class Game<T>

Type Parameters:
T - represents the moves that can be applied to the states

public class Game<T> extends AbstractGame<State<T>,T>
Conducts a two-player game whose moves are described by a single object.
  • Constructor Details

    • Game

      public Game(State<T> state, Function<String,T> parser)
      Creates a Game instance to conduct a two-player game whose moves are described by a single object on the console.
      Parameters:
      state - the state from which the game is started
      parser - a function that converts a line read from the console to a move
      Throws:
      AssertionError - if the console is not available
  • Method Details

    • makeMoveIfPossible

      protected void makeMoveIfPossible(T move)
      Description copied from class: AbstractGame
      Applies the move specified to the state of the game if the move is a legal one. In case of a legal move, it should also print the updated state on the console with the AbstractGame.printState() method.
      Specified by:
      makeMoveIfPossible in class AbstractGame<State<T>,T>
      Parameters:
      move - the move to be made