ksquares
aiController Class Reference
#include <aicontroller.h>
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
- Finally, 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. Currently, the first two points are implemented.
Definition at line 29 of file aicontroller.h.
Public Member Functions | |
| aiController (int newPlayerId, const QList< bool > &newLines, const QList< int > &newSquareOwners, int newWidth, int newHeight) | |
| QList< int > | autoFill (int safeMovesLeft) |
| int | chooseLine () const |
Protected Member Functions | |
| QList< int > | chooseLeastDamaging (const QList< int > &choiceList) const |
| int | countBorderLines (int squareIndex, const QList< bool > &linesList) const |
| KSquares::Direction | lineDirection (int lineIndex) const |
| QList< int > | linesFromSquare (int squareIndex) const |
| QList< int > | safeMoves () const |
| QList< int > | squaresFromLine (int lineIndex) const |
Protected Attributes | |
| int | height |
| QList< bool > | lines |
| int | playerId |
| QList< int > | squareOwners |
| int | width |
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 17 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 23 of file aicontroller.cpp.
| QList< int > aiController::chooseLeastDamaging | ( | const QList< int > & | choiceList | ) | const [protected] |
- 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 151 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 49 of file aicontroller.cpp.
| int aiController::countBorderLines | ( | int | squareIndex, | |
| const QList< bool > & | linesList | |||
| ) | const [protected] |
- Parameters:
-
squareIndex the index of the square (relates to squareOwners )
- Parameters:
-
linesList the linesList you want to work from
- Returns:
- the number of lines currently drawn around a specific square
Definition at line 194 of file aicontroller.cpp.
| KSquares::Direction aiController::lineDirection | ( | int | lineIndex | ) | const [protected] |
- Parameters:
-
lineIndex the index of the line (relates to lines )
- Returns:
- the direction of the line
Definition at line 255 of file aicontroller.cpp.
| QList< int > aiController::linesFromSquare | ( | int | squareIndex | ) | const [protected] |
- Parameters:
-
squareIndex the index of the square (relates to squareOwners )
- Returns:
- the indices of the four lines surrounding the square
Definition at line 241 of file aicontroller.cpp.
| QList< int > aiController::safeMoves | ( | ) | const [protected] |
- Returns:
- list of moves that are safe (squares surrounded by 2 lines are avoided)
Definition at line 125 of file aicontroller.cpp.
| QList< int > aiController::squaresFromLine | ( | int | lineIndex | ) | const [protected] |
- Parameters:
-
lineIndex the index of the line (relates to lines )
- Returns:
- the (one or two) squares abutting a line
Definition at line 213 of file aicontroller.cpp.
Member Data Documentation
int aiController::height [protected] |
QList<bool> aiController::lines [protected] |
int aiController::playerId [protected] |
QList<int> aiController::squareOwners [protected] |
int aiController::width [protected] |
The documentation for this class was generated from the following files:
KDE 4.1 API Reference