Class NimState
java.lang.Object
games.nim.NimState
- All Implemented Interfaces:
common.State<Integer,NimState>, common.util.Copyable<NimState>, game.State<Integer, NimState>
Represents the states of the Nim variant called the subtraction game. In this
game, two players remove objects from a pile of objects in alternating
turns. On each turn, at least one object must be removed; however, no more
than
k objects can be removed (k is a positive integer). The
winner of the game is the player who takes the last object.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface game.State
game.State.Player, game.State.Status -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncopy()game.State.PlayerReturns the player who moves next.game.State.StatusReturns the status of the game.booleanReturns whether the game is over.booleanReturns whether it is allowed to remove the specified number of objects.voidRemoves the specified number of objects.toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface game.State
isWinner
-
Constructor Details
-
NimState
public NimState(int numberOfObjects, int limit) Creates aNimStateinstance with the specified number of objects.- Parameters:
numberOfObjects- the initial number of objects, must be positivelimit- upper limit for the number of objects to be removed, must be positive
-
NimState
Creates a deep copy of the specifiedNimStateobject.- Parameters:
other- the object to be copied
-
-
Method Details
-
isLegalMove
Returns whether it is allowed to remove the specified number of objects. -
makeMove
-
getLegalMoves
-
getNextPlayer
-
isGameOver
-
getStatus
-
copy
-
toString
-