ksquares
#include <aicontroller.h>
Public Member Functions | |
aiController (int newPlayerId, const QList< bool > &newLines, const QList< int > &newSquareOwners, int newWidth, int newHeight) | |
~aiController () | |
QList< int > | autoFill (int safeMovesLeft) |
int | chooseLine () const |
Protected Member Functions | |
QList< int > | chooseLeastDamaging (const QList< int > &choiceList) const |
int | countBorderLines (int squareIndex, const bool *linesList) const |
int | countBorderLines (int *sidesOfSquare, int squareIndex, const bool *linesList) const |
KSquares::Direction | lineDirection (int lineIndex) const |
void | linesFromSquare (int *sidesOfSquare, int squareIndex) const |
QList< int > | safeMoves () const |
QList< int > | squaresFromLine (int lineIndex) const |
Protected Attributes | |
int | height |
bool * | lines |
int | linesSize |
int | playerId |
QList< int > | squareOwners |
int | width |
Detailed Description
AI Controller for KSquares.
When playing a game of squares there are a number of stages the game goes through:
- The random line placement stage. Where players are just placing lines while trying to not complete the third side of any squares
- Next players will try to only draw the third side of a square if it will only give the opponent the minimum amount of points
- The more advanced player will, at the end of a large run of squares leave a small area at the end, forcing the opponent to take only that small section, leaving another large area open to him.
- The even more advanced player will fight for control over the game. This means that he will count the chains forming in the last phase of the "random line" game phase and thus make sure that he will be the one who gets the first long chain. This works like a Nim game somehow. Currently, the first three points are implemented.
Definition at line 31 of file aicontroller.h.
Constructor & Destructor Documentation
aiController::aiController | ( | int | newPlayerId, |
const QList< bool > & | newLines, | ||
const QList< int > & | newSquareOwners, | ||
int | newWidth, | ||
int | newHeight | ||
) |
Create a new AI controller.
- Parameters
-
newPlayerId ID of the player newLines list of the lines which are drawn newSquareOwners list of squares and their owners newWidth height of the current gameboard newHeight width of the current gameboard
Definition at line 19 of file aicontroller.cpp.
aiController::~aiController | ( | ) |
Definition at line 28 of file aicontroller.cpp.
Member Function Documentation
QList< int > aiController::autoFill | ( | int | safeMovesLeft | ) |
Finds lines that can be filled without causing squares to be surrounded by 3 lines as a result.
- Parameters
-
safeMovesLeft number of safe moves that can be performed after those returned by the function are drawn (note: the number is valid only for a certain sequence, for other sequences they could either be more or less)
- Returns
- the list of lines that can be safely drawn
Definition at line 33 of file aicontroller.cpp.
- Parameters
-
choiceList list of indices (of lines) which have squares next to them with two lines drawn (relates to lines )
- Returns
- list of indices (of lines) which would be the least damaging in the short term
Definition at line 178 of file aicontroller.cpp.
int aiController::chooseLine | ( | ) | const |
Choses where to draw the line: Creates a list of all the squares which are surrounded by 3 lines and if the list isn't empty, randomly picks one of them.
Otherwise, creates a list of all the squares which are surrounded by 1 or 2 lines and if the list isn't empty, randomly chooses one of them. Otherwise, randomly chooses a square which is surrounded by three lines.
- Returns
- The index of the line from "QVector<bool> lines"
Definition at line 59 of file aicontroller.cpp.
|
protected |
- Parameters
-
squareIndex the index of the square (relates to squareOwners ) linesList the linesList you want to work from
- Returns
- the number of lines currently drawn around a specific square
Definition at line 509 of file aicontroller.cpp.
|
protected |
- Parameters
-
sidesOfSquare output parameter: the indices of the four lines surrounding the square squareIndex the index of the square (relates to squareOwners ) linesList the linesList you want to work from
- Returns
- the number of lines currently drawn around a specific square
Definition at line 490 of file aicontroller.cpp.
|
protected |
- Parameters
-
lineIndex the index of the line (relates to lines )
- Returns
- the direction of the line
Definition at line 555 of file aicontroller.cpp.
|
protected |
- Parameters
-
sidesOfSquare output parameter: the indices of the four lines surrounding the square squareIndex the index of the square (relates to squareOwners )
Definition at line 543 of file aicontroller.cpp.
|
protected |
- Returns
- list of moves that are safe (squares surrounded by 2 lines are avoided)
Definition at line 152 of file aicontroller.cpp.
|
protected |
- Parameters
-
lineIndex the index of the line (relates to lines )
- Returns
- the (one or two) squares abutting a line
Definition at line 515 of file aicontroller.cpp.
Member Data Documentation
|
protected |
Height of the game board.
Definition at line 118 of file aicontroller.h.
|
protected |
Definition at line 112 of file aicontroller.h.
|
protected |
List of which lines are complete.
Definition at line 111 of file aicontroller.h.
|
protected |
The ID of the player this AI belongs to.
Definition at line 114 of file aicontroller.h.
|
protected |
List of the owners of each square.
Definition at line 109 of file aicontroller.h.
|
protected |
Width of the game board.
Definition at line 116 of file aicontroller.h.
The documentation for this class was generated from the following files:
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:18:39 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.