Package a5.logic

Class Pente


public class Pente extends MNKGame
A Pente game, where players take turns to place stones on board. When consecutive two stones are surrounded by the opponent's stones on two ends, these two stones are removed (captured). A player wins by placing 5 consecutive stones or capturing stones 5 times.
  • Constructor Details

    • Pente

      public Pente()
      Create an 8-by-8 Pente game.
    • Pente

      public Pente(Pente game)
      Creates: a copy of the game state.
  • Method Details

    • makeMove

      public boolean makeMove(Position p)
      Description copied from class: MNKGame
      Effect: place a stone as the current player at p, and advance to the next turn Checks: p is a valid position to place a stone, that is, 0 <= p.rowNo() < rowSize(), 0 <= p.colNo() < colSize(), and p is empty on board. on board.
      Specified by:
      makeMove in class MNKGame
      Parameters:
      p - the position to place a stone
      Returns:
      true if the action is valid, false otherwise
    • applyMove

      public Pente applyMove(Position p)
      Returns: a new game state representing the state of the game after the current player takes a move p.
    • capturedPairsNo

      public int capturedPairsNo(PlayerRole playerRole)
      Returns: the number of captured pairs by playerRole.
    • hasEnded

      public boolean hasEnded()
      Description copied from class: MNKGame
      Checks if there are enough consecutive stones in a row so that the game ends. Returns: whether this game has ended. Effect: if the game has ended, determines the result of the game.
      Overrides:
      hasEnded in class MNKGame
    • gameType

      public GameType gameType()
      Description copied from class: MNKGame
      Returns: the type of this game.
      Specified by:
      gameType in class MNKGame
    • toString

      public String toString()
      Overrides:
      toString in class MNKGame
    • equals

      public boolean equals(Object o)
      Description copied from class: MNKGame
      Although MNKGame is a mutable abstraction, equality is defined in terms of the state of the object. This goes against our usual advice on how to implement equals(), but is needed to support use in the transposition table.
      Overrides:
      equals in class MNKGame
    • stateEqual

      protected boolean stateEqual(Pente p)
      Returns: true if the two games have the same state.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class MNKGame