|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfourwin.PlayingField
public class PlayingField
This class represents a situation on the Connect4 playing field. It is used to safe the real situation of the connect4 board and to save the simulated situations used by AI algorithms.
The situation is saved in 7x6 array. (width x height, top left-hand corner is 0,0) Every field represents a position in the connect4 field. The situation is coded as follows:
Using that code makes it easily possible to detect 2,3 or 4 chips in a row for one player by simply adding the values saved for the single fields. The result is unique. Example: 4-in-a-row for player 1 means that the sum of 4 neighbored positions is 1+1+1+1 = 4. The 4 is only reachable with 4x1.
Field Summary | |
---|---|
(package private) int |
lastInsertedColumn
|
(package private) int |
lastInsertedRow
|
(package private) int |
numberOfChips
|
(package private) byte[][] |
playingarray
|
Constructor Summary | |
---|---|
PlayingField()
|
|
PlayingField(PlayingField pf)
|
Method Summary | |
---|---|
int |
checkWin()
This method checks if there exists a winner for the actual board. |
int |
Evaluate(int playerID)
For backward compatibility. |
int |
Evaluate(int playerID,
int numberInRow)
|
boolean |
fullColumn(int column)
This method checks if a column is full with chips or not. |
boolean |
fullField()
This method checks if the playing field is full with chips ( true ) or not ( false ) to check a possible draw. |
byte |
getField(int row,
int column)
|
byte |
getFirstEmptyRow(byte column)
This method returns the first empty row if the column is overgiven. |
int |
getLastInsertedColumn()
|
int |
getNumberOfChips()
|
private int |
getNumberOfSumInA4Row(int sumToCheck)
Returns the number of found sum for each 4-chip possibility. |
private int |
getNumberOfSumInA4RowDiagonal(int sumToCheck)
Splitted getNumberOfSumInA4Row() just to check the diagonal possibilities. |
private int |
getNumberOfSumInA4RowHorizontal(int sumToCheck)
Splitted getNumberOfSumInA4Row() just to check the horizontal possibilities. |
private int |
getNumberOfSumInA4RowVertical(int sumToCheck)
Splitted getNumberOfSumInA4Row() just to check the vertical possibilities. |
private int |
getNumberOfSumInA5RowHorizontal(int sumToCheck)
Searches for 5-in-a-row chances (which means two 4-in-a-row chances that cannot be defended) |
ArrayList<Integer> |
getPossibleMoves()
This method returns an ArrayList (IEnumerable) with all moves which are possible at the current situation. |
ArrayList<Integer> |
getPossibleMovesFromRightToLeft()
This method returns all possible moves beginning from the right going to the left. |
boolean |
insertChip(byte value,
int column)
This method inserts a chip in a specific column from a specific player if the column is not full. |
void |
Reset()
Resets the playing field. |
void |
setField(int row,
int column,
byte value)
|
void |
UndoLastMove()
Deprecated. |
void |
UndoMove(byte column)
Removes the topmost chip in the given column. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
byte[][] playingarray
int lastInsertedColumn
int lastInsertedRow
int numberOfChips
Constructor Detail |
---|
public PlayingField()
public PlayingField(PlayingField pf)
Method Detail |
---|
public void Reset()
public boolean fullField()
public void setField(int row, int column, byte value)
public byte getField(int row, int column)
public int getLastInsertedColumn()
public int getNumberOfChips()
public boolean fullColumn(int column)
column
- to check
public boolean insertChip(byte value, int column)
value
- of Player ( similar to Player/Opponent ID )column
- to insert chip
public byte getFirstEmptyRow(byte column)
column
-
@Deprecated public void UndoLastMove()
public void UndoMove(byte column)
column
- Column to remove the topmost chip.public int checkWin()
public ArrayList<Integer> getPossibleMoves()
public ArrayList<Integer> getPossibleMovesFromRightToLeft()
This method returns all possible moves beginning from the right going to the left. Possible move means that the column is not full.
The method is used by the board scanner which begins its search at the first column on the right-hand side.
public int Evaluate(int playerID)
playerID
- ID of the player for which the evaluation should be done.
public int Evaluate(int playerID, int numberInRow)
playerID
- Player-ID of player for which the playing field is evaluated.numberInRow
-
private int getNumberOfSumInA4Row(int sumToCheck)
sumToCheck
-
private int getNumberOfSumInA4RowHorizontal(int sumToCheck)
sumToCheck
-
getNumberOfSumInA4Row(int)
private int getNumberOfSumInA5RowHorizontal(int sumToCheck)
sumToCheck
-
private int getNumberOfSumInA4RowVertical(int sumToCheck)
sumToCheck
-
getNumberOfSumInA4Row(int)
private int getNumberOfSumInA4RowDiagonal(int sumToCheck)
sumToCheck
-
getNumberOfSumInA4Row(int)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |