• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdegames API Reference
  • KDE Home
  • Contact Us
 

ksquares

Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
aiController Class Reference

#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.
Author
Matt Williams matt@.nosp@m.mill.nosp@m.iams..nosp@m.com
Tom Vincent Peters kde@v.nosp@m.ince.nosp@m.nt-pe.nosp@m.ters.nosp@m..de

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
newPlayerIdID of the player
newLineslist of the lines which are drawn
newSquareOwnerslist of squares and their owners
newWidthheight of the current gameboard
newHeightwidth 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
safeMovesLeftnumber 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.

QList< int > aiController::chooseLeastDamaging ( const QList< int > &  choiceList) const
protected
Parameters
choiceListlist 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.

int aiController::countBorderLines ( int  squareIndex,
const bool *  linesList 
) const
protected
Parameters
squareIndexthe index of the square (relates to squareOwners )
linesListthe 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.

int aiController::countBorderLines ( int *  sidesOfSquare,
int  squareIndex,
const bool *  linesList 
) const
protected
Parameters
sidesOfSquareoutput parameter: the indices of the four lines surrounding the square
squareIndexthe index of the square (relates to squareOwners )
linesListthe 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.

KSquares::Direction aiController::lineDirection ( int  lineIndex) const
protected
Parameters
lineIndexthe index of the line (relates to lines )
Returns
the direction of the line

Definition at line 555 of file aicontroller.cpp.

void aiController::linesFromSquare ( int *  sidesOfSquare,
int  squareIndex 
) const
protected
Parameters
sidesOfSquareoutput parameter: the indices of the four lines surrounding the square
squareIndexthe index of the square (relates to squareOwners )

Definition at line 543 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 152 of file aicontroller.cpp.

QList< int > aiController::squaresFromLine ( int  lineIndex) const
protected
Parameters
lineIndexthe 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

int aiController::height
protected

Height of the game board.

Definition at line 118 of file aicontroller.h.

bool* aiController::lines
protected

Definition at line 112 of file aicontroller.h.

int aiController::linesSize
protected

List of which lines are complete.

Definition at line 111 of file aicontroller.h.

int aiController::playerId
protected

The ID of the player this AI belongs to.

Definition at line 114 of file aicontroller.h.

QList<int> aiController::squareOwners
protected

List of the owners of each square.

Definition at line 109 of file aicontroller.h.

int aiController::width
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:
  • aicontroller.h
  • aicontroller.cpp
This file is part of the KDE documentation.
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.

ksquares

Skip menu "ksquares"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdegames API Reference

Skip menu "kdegames API Reference"
  • granatier
  • kapman
  • kblackbox
  • kgoldrunner
  • kigo
  • kmahjongg
  • KShisen
  • ksquares
  • libkdegames
  •   highscore
  •   libkdegamesprivate
  •     kgame
  • libkmahjongg
  • palapeli
  •   libpala

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal