Package a5.logic
Class Pente
java.lang.Object
a5.logic.MNKGame
a5.logic.Pente
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns: a new game state representing the state of the game after the current player takes a movep
.int
capturedPairsNo
(PlayerRole playerRole) Returns: the number of captured pairs byplayerRole
.boolean
Although MNKGame is a mutable abstraction, equality is defined in terms of the state of the object.gameType()
Returns: the type of this game.boolean
hasEnded()
Checks if there are enough consecutive stones in a row so that the game ends.int
hashCode()
boolean
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()
, andp
is empty on board.protected boolean
stateEqual
(Pente p) Returns: true if the two games have the same state.toString()
Methods inherited from class a5.logic.MNKGame
advanceTurn, board, changePlayer, colSize, countToWin, currentPlayer, currentTurn, legalMoves, result, rowSize, setResult, stateEqual
-
Constructor Details
-
Pente
public Pente()Create an 8-by-8 Pente game. -
Pente
Creates: a copy of the game state.
-
-
Method Details
-
makeMove
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()
, andp
is empty on board. on board. -
applyMove
Returns: a new game state representing the state of the game after the current player takes a movep
. -
capturedPairsNo
Returns: the number of captured pairs byplayerRole
. -
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. -
gameType
Description copied from class:MNKGame
Returns: the type of this game. -
toString
-
equals
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. -
stateEqual
Returns: true if the two games have the same state. -
hashCode
public int hashCode()
-