|
Holger's Java API |
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.antelmann.game.AbstractGame
com.antelmann.game.fourwins.FourWinsGame
public class FourWinsGame
FourWinsGame represents the game of 4-wins or 4-connects. (other names for the game: four wins, connect four, vier gewinnt)
| Field Summary | |
|---|---|
protected int[][] |
board
|
int |
boardHeight
|
int |
boardWidth
|
int |
MAX_MOVES
|
static int |
WINNING_LINE_LENGTH
|
| Constructor Summary | |
|---|---|
FourWinsGame()
creates the standard game board with 7x6 |
|
FourWinsGame(String name)
|
|
FourWinsGame(String name,
int width,
int height)
|
|
| Method Summary | |
|---|---|
protected int |
checkPositionWin(int column,
int row)
|
Object |
clone()
Any inheriting class with non-primitive members must override this clone() method to provide a full deep copy of the object, which is essential for spawnChild() to work correctly. |
boolean |
equals(Object obj)
|
protected int |
freePositionInColumn(int column)
|
int |
getHeight()
|
int |
getValueAt(int column,
int row)
Returns the value for a specified position in the game board. |
int |
getWidth()
|
int[] |
getWinner()
getWinner() returns an array of all winning game roles - as there could be more than one winner. |
int |
hashCode()
experimental, but working |
protected GameMove[] |
listLegalMoves()
listLegalMoves() returns the legal moves for this game. |
int |
nextPlayer()
nextPlayer() returns the integer representing the game role of the next player. |
protected boolean |
popMove()
popMove undoes the last move by altering the game board to the stage before the last move happened. |
protected boolean |
pushMove(GameMove move)
pushMove takes a GameMove and alters the game according to to the move. |
String |
toString()
overridden to provide useful information about the game |
| Methods inherited from class com.antelmann.game.AbstractGame |
|---|
addObserver, clearRedoList, gameOver, getGameName, getLastMove, getLastPlayer, getLegalMoves, getLegalMoves, getMoveHistory, getNumberOfRedoMoves, getObservers, getRedoList, getResult, isLegalMove, isWinner, loadFromFile, makeMove, numberOfMoves, numberOfPlayers, redoMove, removeObserver, resetLegalMoves, resetLists, saveToFile, spawnChild, undoLastMove, undoMoves |
| Methods inherited from class java.lang.Object |
|---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final int WINNING_LINE_LENGTH
public final int MAX_MOVES
public final int boardWidth
public final int boardHeight
protected int[][] board
| Constructor Detail |
|---|
public FourWinsGame()
public FourWinsGame(String name)
public FourWinsGame(String name,
int width,
int height)
throws IllegalArgumentException
IllegalArgumentException| Method Detail |
|---|
protected GameMove[] listLegalMoves()
AbstractGame
listLegalMoves in class AbstractGamepublic int nextPlayer()
GamePlay
protected boolean popMove()
AbstractGame
popMove in class AbstractGameprotected boolean pushMove(GameMove move)
AbstractGame
pushMove in class AbstractGamepublic int[] getWinner()
GamePlay
public int getValueAt(int column,
int row)
throws ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsException
protected int freePositionInColumn(int column)
throws IllegalArgumentException
IllegalArgumentException
protected int checkPositionWin(int column,
int row)
public int getWidth()
public int getHeight()
public String toString()
AbstractGame
toString in class AbstractGame
public Object clone()
throws CloneNotSupportedException
AbstractGamespawnChild() to work correctly. Ay overriding
of this method should still begin with a call to
super.clone(), though.
Also, note that this clone() method does not clone the
embedded GameMove objects, i.e. those are expected not to change
(except for their heuristics, which shouldn't affect game
functionality) - or the subclass will have to take care of this.
clone in interface GamePlayclone in class AbstractGameCloneNotSupportedExceptionAbstractGame.spawnChild(GameMove)public int hashCode()
hashCode in class Objectpublic boolean equals(Object obj)
equals in class Object
|
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||