Class FiveGame
java.lang.Object
nl.uu.cs.aplib.exampleUsages.fiveGame.FiveGame
A simple game as an example for agents to play. The game is played by two
players on an NxN board. The players take turn to put their pieces. The
pieces of player-1 are called "circles", that of player-2 are "crosses". A
piece is placed on an empty square. Some squares may be blocked; these are
randomly determined when the board was created.
A player wins if she can make a horizontal, vertical, or diagonal connected segment of length 5, consisting of only her pieces.
The game ends in tie if the board is full, and no player wins.
The main-method gives a demo using two random-agents as players.
- Author:
- wish
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static class
static class
A simple random auto-player.static class
static class
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) FiveGame.SQUARE[][]
(package private) int
(package private) FiveGame.Square_
(package private) Random
-
Constructor Summary
ConstructorsConstructorDescriptionFiveGame(int size, int numOfBlocked)
Construct an instance of FiveGame of the specified size x size. -
Method Summary
Modifier and TypeMethodDescriptionGet the game status (unfinished/cross-won/circle-won/tie).FiveGame.SQUARE[][]
getState()
Get a copy of the game board.static void
boolean
move(FiveGame.SQUARE ty, int x, int y)
Place a piece of the specified type in the given coordinate.void
print()
void
toString()
Produce a string summarizing the status of the game.
-
Field Details
-
rnd
Random rnd -
boardsize
int boardsize -
board
FiveGame.SQUARE[][] board -
lastmove
FiveGame.Square_ lastmove
-
-
Constructor Details
-
FiveGame
public FiveGame(int size, int numOfBlocked)Construct an instance of FiveGame of the specified size x size.- Parameters:
size
-numOfBlocked
- This many squares will be randomly selected and blocked.
-
-
Method Details
-
getState
Get a copy of the game board. -
getGameStatus
Get the game status (unfinished/cross-won/circle-won/tie). -
move
Place a piece of the specified type in the given coordinate. If the square is unoccupied, this returns true, else false.- Parameters:
ty
- Should be either CROSS or CIRCLE.
-
getLastmove
-
toString
-
toStringShort
Produce a string summarizing the status of the game. -
print
public void print() -
printStatus
public void printStatus() -
main
-