KWin4Doc Class Reference

The game document or game engine. More...

#include <kwin4doc.h>

Collaboration diagram for KWin4Doc:

Collaboration graph
[legend]
List of all members.

Public Slots

void moveDone (int mode)
 Indication from the view that a move has been displayed.
void loadSettings ()
 Load the game properties from the settings.

Signals

void signalGameRun ()
 Emmitted if the game status changes to run.
void signalChatChanged (KWin4Player *player)
 Emmitted if the chat origin changes.
void signalNextPlayer (int playerNumber)
 Emmitted when the next players move is due.

Public Member Functions

 KWin4Doc (QWidget *parent)
 Constructor.
 ~KWin4Doc ()
 The dstructor.
void setView (KWin4View *view)
 Adds a view to the document which displays the document contents.
void initPlayers ()
 Initializes the KGame derived players.
bool loadgame (QDataStream &stream, bool network, bool reset)
 Save the document in the datastrem.
void readConfig (KConfig *config)
 Read the game config from the config file.
void writeConfig (KConfig *config)
 Write the game config to the config file.
void endGame (TABLE mode)
 End a game.
void resetStatistic ()
 Reset all the player stats.
bool redoMove ()
 Redoes a move if possible.
bool undoMove ()
 Undoes a move if possible.
void calculateHint ()
 Generate a computer AI move and show it to the player as hint.
int getStatistic (COLOUR col, TABLE mode)
 Returns the all time statistics for player of given color The mode determins what statistics to access.
QString getName (COLOUR col)
 Retrieve the name of the player of the given color.
void setName (COLOUR col, const QString &n)
 Set the name of the player of the given color.
KGameIO::IOMode playedBy (int col)
 Query the IO mode of player og the given color.
void setPlayedBy (int col, KGameIO::IOMode mode)
 Sets the input device mode for the given player color.
KWin4PlayergetPlayer (COLOUR col)
 Retrieve the player object for the given player colour.
COLOUR switchStartPlayer ()
 Swap the start player so that the game is started alternatingly.
void setCurrentPlayer (COLOUR no)
 Sets the current player.
COLOUR getCurrentPlayer ()
 Retrieve the player whose turn it is next.
int getCurrentMove ()
 Retrieve the current move number.
int getMaxMove ()
 Retrieve the maximum move which has been made before undos.
int getHistoryCnt ()
 Retrieve the amount of moves in the undo/redo history.

Protected Slots

void repeatMove ()
 Initiate a repeate of the move.
void processAIHintCommand (QDataStream &in, KGameProcessIO *io)
 An AI command was received from the computer AI _hint_ process.
void processAICommand (QDataStream &in, KGameProcessIO *io)
 An AI command was received from the computer AI _input device_ process.
void clientConnected (quint32 cid, KGame *me)
 This slot is called by the signal of KGame to indicated that the network connection is done and a new client is connected.
void prepareAITurn (QDataStream &stream, bool b, KGameIO *input, bool *eatevent)
 This slot is called by the KGame input device when we should prepare a message to the AI process.
void networkMessageUpdate (int id, quint32 sender, quint32 receiver)
 Debug: Listen to network messages.
void playerPropertyChanged (KGamePropertyBase *prop, KPlayer *player)
 Called by KGame when a player property has changed.
void gamePropertyChanged (KGamePropertyBase *prop, KGame *me)
 Called by KGame when a game property has changed.

Protected Member Functions

void createIO (KPlayer *player, KGameIO::IOMode io)
 Create and add an KGameIO device to an given player.
KPlayer * createPlayer (int rtti, int io, bool isvirtual)
 Create a player of a given type (here only one type possible) and equip it with a given KGameIO device.
KPlayer * nextPlayer (KPlayer *last, bool exclusive=true)
 KGame function to determine the next player.
void newPlayersJoin (KGamePlayerList *list, KGamePlayerList *newList, QList< int > &inactive)
 This is also an overwritten function of KGame.
void resetGame (bool initview)
 Reset the whole game to the beginning (clear board, .
MOVESTATUS makeMove (int x, int mode)
 Make a game move to the given position and return a status.
bool doMove (int x, int id)
 Perform a game move.
int checkGameOver (KPlayer *player)
 Check whether the field has a game over situation.
int checkGameOver (int x, COLOUR col)
 Check whether the field has a game over situation.
void prepareGameMessage (QDataStream &stream, qint32 pl)
 Pack the current game into a data stream so that it can be send to the computer AI.
bool playerInput (QDataStream &msg, KPlayer *player)
 Main function to handle player input.
void recalcIO ()
 Set the IO devices new.
void activateCurrentPlayer ()
 Set the turn of the current player to true so that he can move.
QString findProcessName ()
 Find the name of the AI process executable file.
void setScore (long value)
 Set the score value of the AI.
void setColour (int x, int y, COLOUR c)
 Set the colour of a position on the game board.
COLOUR getColour (int x, int y)
 Retrieve the colour of a position on the game board.
COLOUR getPlayerColour (int player)
 Retrieve the color of the i-th player.

Detailed Description

The game document or game engine.

It is derived from the KGame framework.

Definition at line 44 of file kwin4doc.h.


Constructor & Destructor Documentation

KWin4Doc::KWin4Doc QWidget *  parent  ) 
 

Constructor.

Parameters:
parent The parent widget

Definition at line 50 of file kwin4doc.cpp.

References clientConnected(), gamePropertyChanged(), global_debug, networkMessageUpdate(), Red, resetGame(), setCurrentPlayer(), and Yellow.

Here is the call graph for this function:

KWin4Doc::~KWin4Doc  ) 
 

The dstructor.

Definition at line 121 of file kwin4doc.cpp.

References writeConfig().

Here is the call graph for this function:


Member Function Documentation

void KWin4Doc::activateCurrentPlayer  )  [protected]
 

Set the turn of the current player to true so that he can move.

Definition at line 210 of file kwin4doc.cpp.

References getCurrentPlayer(), getPlayer(), and global_debug.

Referenced by loadgame().

Here is the call graph for this function:

void KWin4Doc::calculateHint  ) 
 

Generate a computer AI move and show it to the player as hint.

Definition at line 1121 of file kwin4doc.cpp.

References findProcessName(), getCurrentPlayer(), global_debug, prepareGameMessage(), and processAIHintCommand().

Referenced by KWin4App::askForHint().

Here is the call graph for this function:

int KWin4Doc::checkGameOver int  x,
COLOUR  col
[protected]
 

Check whether the field has a game over situation.

Called by above standard KGame function but with more suitable parameters.

Parameters:
x The position of the last move
col The color of the last move

Definition at line 474 of file kwin4doc.cpp.

References getColour(), and Nobody.

Here is the call graph for this function:

int KWin4Doc::checkGameOver KPlayer *  player  )  [protected]
 

Check whether the field has a game over situation.

KGame stanard function.

Parameters:
player The current player
Returns:
-1: remis, 1: won, 0: continue game

Definition at line 464 of file kwin4doc.cpp.

References global_debug.

void KWin4Doc::clientConnected quint32  cid,
KGame *  me
[protected, slot]
 

This slot is called by the signal of KGame to indicated that the network connection is done and a new client is connected.

Parameters:
cid Is the id of the client connected. If this is equal gameId() WE are the client.
me The game

Definition at line 1056 of file kwin4doc.cpp.

References global_debug, and signalChatChanged().

Referenced by KWin4Doc().

void KWin4Doc::createIO KPlayer *  player,
KGameIO::IOMode  io
[protected]
 

Create and add an KGameIO device to an given player.

The old ones have to be removed manually before.

Parameters:
player The player to modify
io The IO mode (Mouse, AI, Keyboard, ...)

Definition at line 919 of file kwin4doc.cpp.

References findProcessName(), global_debug, prepareAITurn(), and processAICommand().

Referenced by createPlayer(), and setPlayedBy().

Here is the call graph for this function:

KPlayer * KWin4Doc::createPlayer int  rtti,
int  io,
bool  isvirtual
[protected]
 

Create a player of a given type (here only one type possible) and equip it with a given KGameIO device.

Virtual players are remote network players.

Parameters:
rtti Unused
io The IO mode
isvirtual True for network players (without physical IO)

Definition at line 843 of file kwin4doc.cpp.

References createIO(), and playerPropertyChanged().

Referenced by initPlayers().

Here is the call graph for this function:

bool KWin4Doc::doMove int  x,
int  id
[protected]
 

Perform a game move.

Calls makeMove().

Parameters:
x The position to move to
id The player id
Returns:
True if the move was successful.

Definition at line 285 of file kwin4doc.cpp.

References global_debug, GNormal, and makeMove().

Referenced by playerInput().

Here is the call graph for this function:

void KWin4Doc::endGame TABLE  mode  ) 
 

End a game.

Update statistic and forward end game to view.

Parameters:
mode Indicate how the game ended for the current player [TWin, TLost, TRemis, TBrk]

Definition at line 219 of file kwin4doc.cpp.

References KWin4View::endGame(), getPlayer(), KWin4Player::incBrk(), KWin4Player::incLost(), KWin4Player::incRemis(), KWin4Player::incWin(), Red, TLost, TRemis, TWin, and Yellow.

Referenced by KWin4App::EndGame().

Here is the call graph for this function:

QString KWin4Doc::findProcessName  )  [protected]
 

Find the name of the AI process executable file.

Returns:
The filename

Definition at line 798 of file kwin4doc.cpp.

References global_debug, and SRC_DIR.

Referenced by calculateHint(), and createIO().

void KWin4Doc::gamePropertyChanged KGamePropertyBase *  prop,
KGame *  me
[protected, slot]
 

Called by KGame when a game property has changed.

We update the game status etc.

Parameters:
prop The property
me The game

Definition at line 1196 of file kwin4doc.cpp.

Referenced by KWin4Doc().

COLOUR KWin4Doc::getColour int  x,
int  y
[protected]
 

Retrieve the colour of a position on the game board.

Parameters:
x The x position [0-6]
y The y position [0-5]
Returns:
The color [Red, Yellow, Nobody]

Definition at line 158 of file kwin4doc.cpp.

References FIELD_SIZE_X.

Referenced by checkGameOver(), and prepareGameMessage().

int KWin4Doc::getCurrentMove  ) 
 

Retrieve the current move number.

Returns:
The amount [0..42]

Definition at line 777 of file kwin4doc.cpp.

Referenced by KWin4App::checkMenus(), and prepareGameMessage().

COLOUR KWin4Doc::getCurrentPlayer  ) 
 

Retrieve the player whose turn it is next.

Returns:
The current player.

Definition at line 751 of file kwin4doc.cpp.

Referenced by activateCurrentPlayer(), calculateHint(), makeMove(), moveDone(), KWin4App::networkBroken(), nextPlayer(), prepareGameMessage(), redoMove(), KWin4App::redoMove(), repeatMove(), undoMove(), KWin4App::undoMove(), and KWin4App::updateStatusNames().

int KWin4Doc::getHistoryCnt  ) 
 

Retrieve the amount of moves in the undo/redo history.

Returns:
The amount [0..42]

Definition at line 791 of file kwin4doc.cpp.

Referenced by KWin4App::checkMenus(), makeMove(), redoMove(), and undoMove().

int KWin4Doc::getMaxMove  ) 
 

Retrieve the maximum move which has been made before undos.

Returns:
The amount [0..42]

Definition at line 784 of file kwin4doc.cpp.

QString KWin4Doc::getName COLOUR  col  ) 
 

Retrieve the name of the player of the given color.

Parameters:
col The color
Returns:
The name.

Definition at line 420 of file kwin4doc.cpp.

References getPlayer().

Referenced by KWin4App::showStatistics(), KWin4App::slotGameOver(), and KWin4App::updateStatusNames().

Here is the call graph for this function:

KWin4Player * KWin4Doc::getPlayer COLOUR  col  ) 
 

Retrieve the player object for the given player colour.

Parameters:
col The player color
Returns:
The player object.

Definition at line 1107 of file kwin4doc.cpp.

Referenced by activateCurrentPlayer(), KWin4App::configureChat(), endGame(), getName(), getStatistic(), moveDone(), KWin4App::networkBroken(), newPlayersJoin(), nextPlayer(), readConfig(), recalcIO(), KWin4App::remoteChanged(), repeatMove(), resetStatistic(), setName(), setPlayedBy(), and writeConfig().

COLOUR KWin4Doc::getPlayerColour int  player  )  [protected]
 

Retrieve the color of the i-th player.

Player 0 is the start player and player 1 the follow up player.

Parameters:
player The player number [0,1]
Returns:
The color of the player.

Definition at line 451 of file kwin4doc.cpp.

References Red, and Yellow.

Referenced by loadSettings(), and prepareGameMessage().

int KWin4Doc::getStatistic COLOUR  col,
TABLE  mode
 

Returns the all time statistics for player of given color The mode determins what statistics to access.

Parameters:
col The player color
mode The type of data to retrieve [TWin, TRemis, TLost, TBrk, TSum]
Returns:
The amount of the queried category.

Definition at line 428 of file kwin4doc.cpp.

References KWin4Player::brk(), getPlayer(), KWin4Player::lost(), KWin4Player::remis(), TBrk, TLost, TRemis, TSum, TWin, and KWin4Player::win().

Referenced by KWin4App::showStatistics().

Here is the call graph for this function:

void KWin4Doc::initPlayers  ) 
 

Initializes the KGame derived players.

Definition at line 131 of file kwin4doc.cpp.

References createPlayer(), Prefs::name1(), Red, setPlayedBy(), and Yellow.

Referenced by KWin4App::KWin4App().

Here is the call graph for this function:

bool KWin4Doc::loadgame QDataStream &  stream,
bool  network,
bool  reset
 

Save the document in the datastrem.

This is a KGame function.

Parameters:
stream The data stream to use
network Is the saving via the network (a network game)
reset Reset parameter forward to KGame
Returns:
True on success, false otherwise.

Definition at line 1257 of file kwin4doc.cpp.

References activateCurrentPlayer(), global_debug, recalcIO(), redoMove(), resetGame(), and undoMove().

Here is the call graph for this function:

void KWin4Doc::loadSettings  )  [slot]
 

Load the game properties from the settings.

Either the config file or the config dialog call this.

Definition at line 680 of file kwin4doc.cpp.

References Prefs::colour1(), getPlayerColour(), Prefs::input1(), Prefs::input2(), Prefs::level(), Prefs::name1(), Prefs::name2(), Red, Score::setLevel(), setName(), setPlayedBy(), switchStartPlayer(), and Yellow.

Referenced by readConfig().

MOVESTATUS KWin4Doc::makeMove int  x,
int  mode
[protected]
 

Make a game move to the given position and return a status.

Also displays it in the view.

Parameters:
x The position to move to
mode The mode of the move (0: normal move: 1: redo move)
Returns:
The movement status (allowed, normal, ...)

Definition at line 296 of file kwin4doc.cpp.

References KWin4View::displayMove(), FIELD_SIZE_X, FIELD_SIZE_Y, getCurrentPlayer(), getHistoryCnt(), GIllMove, GNormal, GNotAllowed, GTip, Nobody, setColour(), and Tip.

Referenced by doMove(), and redoMove().

Here is the call graph for this function:

void KWin4Doc::moveDone int  mode  )  [slot]
 

Indication from the view that a move has been displayed.

Now The next player can be switched.

Parameters:
mode A user defined (unused) mode

Definition at line 252 of file kwin4doc.cpp.

References getCurrentPlayer(), and getPlayer().

Referenced by setView().

void KWin4Doc::networkMessageUpdate int  id,
quint32  sender,
quint32  receiver
[protected, slot]
 

Debug: Listen to network messages.

Parameters:
id The message id
sender The sender
receiver The receiver

Definition at line 836 of file kwin4doc.cpp.

Referenced by KWin4Doc().

void KWin4Doc::newPlayersJoin KGamePlayerList *  list,
KGamePlayerList *  newList,
QList< int > &  inactive
[protected]
 

This is also an overwritten function of KGame.

It is called in the game negotiation upon connect. Here the games have to determine what player is remote and what is local.

Parameters:
list Unused
newList List of new players
inactive List of inactive players

Definition at line 1306 of file kwin4doc.cpp.

References getPlayer(), global_debug, Red, and Yellow.

Here is the call graph for this function:

KPlayer * KWin4Doc::nextPlayer KPlayer *  last,
bool  exclusive = true
[protected]
 

KGame function to determine the next player.

In KWin4 players alternate.

Parameters:
last The last player to move
exclusive unused

Definition at line 264 of file kwin4doc.cpp.

References getCurrentPlayer(), getPlayer(), global_debug, Red, setCurrentPlayer(), signalNextPlayer(), and Yellow.

Here is the call graph for this function:

KGameIO::IOMode KWin4Doc::playedBy int  col  ) 
 

Query the IO mode of player og the given color.

Parameters:
col The color
Returns:
The input device mode.

Definition at line 883 of file kwin4doc.cpp.

Referenced by KWin4App::networkBroken(), KWin4App::redoMove(), and KWin4App::undoMove().

bool KWin4Doc::playerInput QDataStream &  msg,
KPlayer *  player
[protected]
 

Main function to handle player input.

This function is the central input for all player inputs. Mouse, Keyboard AI or network end here in the same format. A move is initiated here.

Parameters:
msg The game move messasge
player The sender player

Definition at line 858 of file kwin4doc.cpp.

References doMove(), and repeatMove().

Here is the call graph for this function:

void KWin4Doc::playerPropertyChanged KGamePropertyBase *  prop,
KPlayer *  player
[protected, slot]
 

Called by KGame when a player property has changed.

We check whether the name changed and then update the score widget.

Parameters:
prop The property
player The affected player

Definition at line 1181 of file kwin4doc.cpp.

References global_debug, and Score::setPlayerName().

Referenced by createPlayer().

void KWin4Doc::prepareAITurn QDataStream &  stream,
bool  b,
KGameIO *  input,
bool *  eatevent
[protected, slot]
 

This slot is called by the KGame input device when we should prepare a message to the AI process.

Parameters:
stream The message stream
b True if it is our turn
input The input device
eatevent Set to true if a message has been send

Definition at line 970 of file kwin4doc.cpp.

References global_debug, and prepareGameMessage().

Referenced by createIO().

void KWin4Doc::prepareGameMessage QDataStream &  stream,
qint32  pl
[protected]
 

Pack the current game into a data stream so that it can be send to the computer AI.

Parameters:
stream The data stream to write to
pl The player id

Definition at line 997 of file kwin4doc.cpp.

References FIELD_SIZE_X, FIELD_SIZE_Y, getColour(), getCurrentMove(), getCurrentPlayer(), getPlayerColour(), global_debug, and Prefs::level().

Referenced by calculateHint(), and prepareAITurn().

Here is the call graph for this function:

void KWin4Doc::processAICommand QDataStream &  in,
KGameProcessIO *  io
[protected, slot]
 

An AI command was received from the computer AI _input device_ process.

Process it. Currently this is only the move score value.

Parameters:
in The input stream from the process
io The io device

Definition at line 1031 of file kwin4doc.cpp.

References global_debug, and setScore().

Referenced by createIO().

void KWin4Doc::processAIHintCommand QDataStream &  in,
KGameProcessIO *  io
[protected, slot]
 

An AI command was received from the computer AI _hint_ process.

Process it. Currently this is only the hint move.

Parameters:
in The input stream from the process
io The io device

Definition at line 1147 of file kwin4doc.cpp.

References KWin4View::displayHint(), and global_debug.

Referenced by calculateHint().

void KWin4Doc::readConfig KConfig *  config  ) 
 

Read the game config from the config file.

Parameters:
config The config

Definition at line 724 of file kwin4doc.cpp.

References getPlayer(), loadSettings(), KWin4Player::readConfig(), Red, and Yellow.

Referenced by KWin4App::KWin4App().

Here is the call graph for this function:

void KWin4Doc::recalcIO  )  [protected]
 

Set the IO devices new.

Definition at line 911 of file kwin4doc.cpp.

References getPlayer(), Red, and Yellow.

Referenced by loadgame().

Here is the call graph for this function:

bool KWin4Doc::redoMove  ) 
 

Redoes a move if possible.

Returns:
True on success.

Definition at line 396 of file kwin4doc.cpp.

References getCurrentPlayer(), getHistoryCnt(), makeMove(), Red, setCurrentPlayer(), setScore(), and Yellow.

Referenced by loadgame(), and KWin4App::redoMove().

Here is the call graph for this function:

void KWin4Doc::repeatMove  )  [protected, slot]
 

Initiate a repeate of the move.

This happens if somehow the player input created an invalid move. The the same player has to input again.

Definition at line 876 of file kwin4doc.cpp.

References getCurrentPlayer(), and getPlayer().

Referenced by playerInput().

void KWin4Doc::resetGame bool  initview  )  [protected]
 

Reset the whole game to the beginning (clear board, .

..)

Parameters:
initview If true also reset the view

Definition at line 177 of file kwin4doc.cpp.

References FIELD_SIZE_X, FIELD_SIZE_Y, Nobody, and setColour().

Referenced by KWin4Doc(), and loadgame().

Here is the call graph for this function:

void KWin4Doc::resetStatistic  ) 
 

Reset all the player stats.

Definition at line 664 of file kwin4doc.cpp.

References getPlayer(), Red, KWin4Player::resetStats(), and Yellow.

Referenced by KWin4App::showStatistics().

Here is the call graph for this function:

void KWin4Doc::setColour int  x,
int  y,
COLOUR  c
[protected]
 

Set the colour of a position on the game board.

Parameters:
x The x position [0-6]
y The y position [0-5]
c The color [Red, Yellow, Nobody]

Definition at line 165 of file kwin4doc.cpp.

References FIELD_SIZE_X, and FIELD_SIZE_Y.

Referenced by makeMove(), resetGame(), and undoMove().

void KWin4Doc::setCurrentPlayer COLOUR  no  ) 
 

Sets the current player.

Parameters:
no The current player

Definition at line 758 of file kwin4doc.cpp.

Referenced by KWin4Doc(), nextPlayer(), redoMove(), and undoMove().

void KWin4Doc::setName COLOUR  col,
const QString &  n
 

Set the name of the player of the given color.

Parameters:
col The color
n The new name

Definition at line 413 of file kwin4doc.cpp.

References getPlayer().

Referenced by loadSettings().

Here is the call graph for this function:

void KWin4Doc::setPlayedBy int  col,
KGameIO::IOMode  mode
 

Sets the input device mode for the given player color.

Parameters:
col The color
mode The input device code (Mouse, Key, ...)

Definition at line 890 of file kwin4doc.cpp.

References createIO(), getPlayer(), global_debug, Score::setPlayedBy(), and KWin4Player::status().

Referenced by initPlayers(), loadSettings(), and KWin4App::networkBroken().

Here is the call graph for this function:

void KWin4Doc::setScore long  value  )  [protected]
 

Set the score value of the AI.

Parameters:
value The score value.

Definition at line 672 of file kwin4doc.cpp.

Referenced by processAICommand(), redoMove(), and undoMove().

void KWin4Doc::setView KWin4View view  ) 
 

Adds a view to the document which displays the document contents.

Parameters:
view The view to add

Definition at line 150 of file kwin4doc.cpp.

References moveDone().

Referenced by KWin4App::KWin4App().

void KWin4Doc::signalChatChanged KWin4Player player  )  [signal]
 

Emmitted if the chat origin changes.

Parameters:
player The affected player

Referenced by clientConnected().

void KWin4Doc::signalGameRun  )  [signal]
 

Emmitted if the game status changes to run.

void KWin4Doc::signalNextPlayer int  playerNumber  )  [signal]
 

Emmitted when the next players move is due.

Parameters:
playerNumber The number of the player

Referenced by nextPlayer().

COLOUR KWin4Doc::switchStartPlayer  ) 
 

Swap the start player so that the game is started alternatingly.

Returns:
The new start player color.

Definition at line 765 of file kwin4doc.cpp.

References Red, and Yellow.

Referenced by KWin4App::EndGame(), and loadSettings().

bool KWin4Doc::undoMove  ) 
 

Undoes a move if possible.

Returns:
True on success.

Definition at line 349 of file kwin4doc.cpp.

References KWin4View::displayMove(), getCurrentPlayer(), getHistoryCnt(), Nobody, Red, setColour(), setCurrentPlayer(), setScore(), and Yellow.

Referenced by loadgame(), and KWin4App::undoMove().

Here is the call graph for this function:

void KWin4Doc::writeConfig KConfig *  config  ) 
 

Write the game config to the config file.

Parameters:
config The config

Definition at line 738 of file kwin4doc.cpp.

References getPlayer(), Red, KWin4Player::writeConfig(), and Yellow.

Referenced by ~KWin4Doc().

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Sun Mar 4 10:56:43 2007 for KWin4 by  doxygen 1.4.6