ow_board Class Reference

#include <ow_board.h>

List of all members.

Public Member Functions

 ow_board (int columns)
 ow_board (ow_board *board)
void suggested_beginners_seeds_initial_setup ()
int load_gfxdata ()
SDL_Palette * get_palette ()
void draw_gfx (SDL_Surface *surface)
void draw_txt ()
int move (int boardside, int cellx, int celly)
int move_d (int boardside, int cellx, int celly)
int rcapture (int boardside, int cellx, int celly)
int rcapture_d (int boardside, int cellx, int celly)
int capture ()
int takeseeds (int boardside, int cellx, int celly)
int countseeds (int boardside, int cellx, int celly)
int countseeds (int boardside)
int initialboard_countseeds (int boardside, int cellx, int celly)
int initialboard_reset ()
int initialboard_setcurrent ()
int bsetup_takeseeds (int seeds, int boardside, int cellx, int celly)
int bsetup_putseeds (int seeds, int boardside, int cellx, int celly)
int checkavailablemoves (int boardside)
int checkmove (int boardside, int cellx, int celly)
int checkrcapture (int boardside, int cellx, int celly)
void set_undo_mode (int status)
int undolastmove (int nummoves)
int savebackup ()
int restorebackup ()
int endofturn ()
void clear_status_actions ()
int update_status ()
int getcolcount ()
int counthandseeds ()
int setcellseeds (int seeds, int boardside, int cellx, int celly)
void setboardspeed (int bspeed)
string translate_coord2name (int boardside, int cellx, int celly)
 ~ow_board ()

Public Attributes

ow_cellbcells [BRD_NUM_SIDES][BRD_MAX_COLS_PER_PLAYER][BRD_MAX_ROWS_PER_PLAYER]

Private Member Functions

void display_errormove (int boardside, int cellx, int celly)
int _move (int boardside, int cellx, int celly)
void update_status_actions ()
int ntakeseeds (int seeds, int boardside, int cellx, int celly)
int nputseeds (int seeds, int boardside, int cellx, int celly)
int saveundo ()

Private Attributes

int status
int brd_num_cols
int movecount
int movecurrent
cellXY moveini
cellXY movestep
int sowing_delay
int board_sowing_delay
int handseeds
int turnchains
int gfxdata_loaded
SDL_Surface * gfxdata [3]
SDL_Palette * plt
TTF_Font * font
int undo_active
int undodata [BRD_MAX_UNDO_MOVES][BRD_NUM_SIDES][BRD_MAX_COLS_PER_PLAYER][BRD_MAX_ROWS_PER_PLAYER]
int backupsaved
int backupdata [BRD_NUM_SIDES][BRD_MAX_COLS_PER_PLAYER][BRD_MAX_ROWS_PER_PLAYER]


Detailed Description

Author:
David Torres <aiken669@gmail.com>

Constructor & Destructor Documentation

ow_board::ow_board ( int  columns  ) 

Creates a new 'ow_board' object, create board cells, and sets default board values.

Parameters:
columns Number of columns the board has.
Returns:
New 'ow_board' object.

ow_board::ow_board ( ow_board board  ) 

Creates a new board, copying data from this board

Returns:
Pointer to a new board wi the same: cols, rows, cell contents.

ow_board::~ow_board (  ) 

Deletes an 'ow_board' object.


Member Function Documentation

void ow_board::display_errormove ( int  boardside,
int  cellx,
int  celly 
) [private]

Print an illegal movement error on txt_screen and on gfx board (if opened)

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the specified cell in the bcells array.
celly Ypos of the specified cell in the bcells array.

int ow_board::_move ( int  boardside,
int  cellx,
int  celly 
) [private]

Private move(), used by ow_board::move() to make chain moves.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the desired cell in the bcells array.
celly Ypos of the desired cell in the bcells array.
Returns:
1 on success, -1 on any error

void ow_board::update_status_actions (  )  [private]

Update the cells status/action used by draw_gfx for the last movement. Basically used to update the cells who defined a 'timeout' for setaction() and setstatus().

int ow_board::ntakeseeds ( int  seeds,
int  boardside,
int  cellx,
int  celly 
) [private]

Remove N seeds from the specified cell, save them in the private 'this->handseeds' variable.

Parameters:
seeds Number of seeds to be taken from the cell.
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the desired cell in the bcells array.
celly Ypos of the desired cell in the bcells array.
Returns:
Number of seeds taken from the cell, -1 if cell does not have enought seeds to take.

int ow_board::nputseeds ( int  seeds,
int  boardside,
int  cellx,
int  celly 
) [private]

Put seeds in the specified cell, taking them from private 'this->handseeds' variable.

Parameters:
seeds Number of seeds to put in the specified cell
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the specified cell in the bcells array.
celly Ypos of the specified cell in the bcells array.
Returns:
1 on success, <=0 on error.

int ow_board::saveundo (  )  [private]

Save the cells content info to a backup private variable (undodata array) for future use with the undolasmove() function.

Returns:
1 is successful, -1 if cannot save info.

void ow_board::suggested_beginners_seeds_initial_setup (  ) 

Setup the seeds in the board according to the beginners suggested setup.

int ow_board::load_gfxdata (  ) 

Load board .png graphics for draw_gfx() to use

Returns:
0 on success, -1 on any error loading

SDL_Palette * ow_board::get_palette (  ) 

Returns gfx color palette for draw_gfx to use

Returns:
Color palette in SDL format

void ow_board::draw_gfx ( SDL_Surface *  surface  ) 

Draws the gfx board using SDL library

Parameters:
surface SDL Screen surface to draw

void ow_board::draw_txt (  ) 

Draws the txt board version

int ow_board::move ( int  boardside,
int  cellx,
int  celly 
)

Takes all the seeds in the specified cell and execute a regular Mancala sow movement.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the desired cell in the bcells array.
celly Ypos of the desired cell in the bcells array.
Returns:
1 on success, -1 on any error

int ow_board::move_d ( int  boardside,
int  cellx,
int  celly 
)

Move_d(irect): Makes the full move (chainmoves,captures,etc) before returning. Same that move() but doing the full move before returning, move() needs various update_status() calls to complete movement. Note: The Chainmove is limited to 100.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the desired cell in the bcells array.
celly Ypos of the desired cell in the bcells array.
Returns:
1 on success, -1 on any error

int ow_board::rcapture ( int  boardside,
int  cellx,
int  celly 
)

Takes all the seeds in the specified cell and execute a 'reverse' Mancala sow movement. It checks if the movement is allowed, only allowed if the reverse movement ends with a capture.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the desired cell in the bcells array.
celly Ypos of the desired cell in the bcells array.
Returns:
1 on success, -1 on any error

int ow_board::rcapture_d ( int  boardside,
int  cellx,
int  celly 
)

Rcapture_d(irect): Starts a rcapture and makes the full move (chainmoves,captures,etc) before returning. Same that rcapture() but doing the full move before returning, rcapture() needs various update_status() calls to complete movement. Note: The Chainmove is limited to 100.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the desired cell in the bcells array.
celly Ypos of the desired cell in the bcells array.
Returns:
1 on success, -1 on any error

int ow_board::capture (  ) 

Executes a Capture in the cell where the last sow movement ended.

Returns:
Seeds of enemy captured cells taken, and a BRD_STATUS_REENTER_CAPTURE event launched.

1 on success

int ow_board::takeseeds ( int  boardside,
int  cellx,
int  celly 
)

Remove all seeds from the specified cell, save them in the private 'this->handseeds' variable.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the desired cell in the bcells array.
celly Ypos of the desired cell in the bcells array.
Returns:
Number of seeds taken from the cell, -1 on error.

int ow_board::countseeds ( int  boardside,
int  cellx,
int  celly 
)

Returns the count of seeds in the specified cell.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the specified cell in the bcells array.
celly Ypos of the specified cell in the bcells array.
Returns:
Number of seeds

int ow_board::countseeds ( int  boardside  ) 

Returns the count of seeds in the specified board side.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
Returns:
Number of seeds

int ow_board::initialboard_countseeds ( int  boardside,
int  cellx,
int  celly 
)

The board always keep a copy of the initial status of the cells of the board. This function returns the count of seeds in the specified cell, from the copy of the initial board status. You can get board initial status reading the content of all its cells with this function. To get the countseeds of cell of the board current status, you can use regular countseeds() instead. Note: This works saving initial board status to the undoqueue, so if you have undo option disabled probably it will not work properly.

Parameters:
undostep (0-N) specified the slot in the undo queue you want to query about.
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the specified cell in the board according to the undodata
celly Ypos of the specified cell in the board according to the undodata
Returns:
Number of seeds, -1 on error (undo inactive, so no previous status data available)

int ow_board::initialboard_reset (  ) 

The board always keep a copy of the initial status of the cells of the board. This function returns the board to its initial status Note: This works saving initial board status to the undoqueue, so if you have undo option disabled probably it will not work properly.

int ow_board::initialboard_setcurrent (  ) 

Set the current status of the board as 'initialboard'. As consecuence it deletes the undo queue if exists.

int ow_board::bsetup_takeseeds ( int  seeds,
int  boardside,
int  cellx,
int  celly 
)

Setup board: Take N seeds from the specified cell, save them in the private 'this->handseeds' variable.

Parameters:
seeds Number of seeds to be taken from the cell.
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the desired cell in the bcells array.
celly Ypos of the desired cell in the bcells array.
Returns:
Number of seeds taken from the cell, -1 if cell does not have enought seeds to take.

int ow_board::bsetup_putseeds ( int  seeds,
int  boardside,
int  cellx,
int  celly 
)

Setup board: Put seeds in the specified cell. Controls if maxnumseeds on board has been reached.

Parameters:
seeds Number of seeds to put in the specified cell
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the specified cell in the bcells array.
celly Ypos of the specified cell in the bcells array.
Returns:
1 on success, <=0 on error, if no more seeds allowed on board.

int ow_board::checkavailablemoves ( int  boardside  ) 

Checks if there is any allowed moves for the player with the turn.

Parameters:
boardside The side of the board you want to check if there is remaining allowed movements.

int ow_board::checkmove ( int  boardside,
int  cellx,
int  celly 
)

Check if starting a movement from the specified cell is a legal movement.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the specified cell in the bcells array.
celly Ypos of the specified cell in the bcells array.
Returns:
1 on legal movement, -1 on illegal movement

int ow_board::checkrcapture ( int  boardside,
int  cellx,
int  celly 
)

Check if starting a reverse capture from the specified cell is a legal movement. Reverse movement is only allowed from 4 cells most left in each player board side.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the specified cell in the bcells array.
celly Ypos of the specified cell in the bcells array.
Returns:
1 on legal movement, -1 on illegal movement

void ow_board::set_undo_mode ( int  status  ) 

Activate/Deactivate the UndoLastmove option. If deactived the board status is not saved so UndoMove cannot be performed.

Parameters:
status 1 to activate undo_mode, 0 to deactivate undo_mode.

int ow_board::undolastmove ( int  nummoves  ) 

Return the board to the status previous to the last move.

Parameters:
nummoves Number of moves to undo.
Returns:
1 is successful, -1 if cannot undo.

int ow_board::savebackup (  ) 

Save the cells content info to a backup private variable (backupdata array). You can use this function in conjunction with restorebackup to temporary save/restore the cell contents of the board with any purpose you like.

Returns:
1 is successful, -1 if cannot save info.

int ow_board::restorebackup (  ) 

Restore the cells content info saved previously by savebackup() You can use this function in conjunction with savebackup to temporary save/restore the cell contents of the board with any purpose you like.

Returns:
1 is successful, -1 if cannot restore info, no previously saved backup data.

int ow_board::endofturn (  ) 

Check if the board has finished executing last user commands and is ready for new commands.

Returns:
true if finished, false if board still executing last command.

void ow_board::clear_status_actions (  ) 

Clears the cells status/action used by draw_gfx for the last movement.

int ow_board::update_status (  ) 

Executes the user commands in a delayed way, so the user is NOT blocked while the command ends.

Returns:
status of the board (BRD_STATUS_CHAINMOVE,BRD_STATUS_CAPTURE,BRD_STATUS_REENTER_CAPTURE, etc)

int ow_board::getcolcount (  ) 

Gets the number of columns the board has.

Returns:
Number of columns.

int ow_board::counthandseeds (  ) 

Gets the number of seeds in the 'this->handseeds' variable.

Returns:
Number of seeds.

int ow_board::setcellseeds ( int  seeds,
int  boardside,
int  cellx,
int  celly 
)

Set the number of seeds of the specified cell, overriding the previous value. This is used during board setup, while putseeds() is used during playgame and checks play rules.

Parameters:
seeds Number of seeds to put in the specified cell
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the specified cell in the bcells array.
celly Ypos of the specified cell in the bcells array.
Returns:
1 on success, 0 on error.

void ow_board::setboardspeed ( int  bspeed  ) 

Set the speed of the board. Usefull to make it faster during batch games, or slower during human games.

Parameters:
bspeed Desired speed (BRD_SOWING_SPEED_USLOW,BRD_SOWING_SPEED_SLOW,BRD_SOWING_SPEED_NORM,BRD_SOWING_SPEED_FAST,BRD_SOWING_SPEED_ULTRA)

string ow_board::translate_coord2name ( int  boardside,
int  cellx,
int  celly 
)

Gets the name of the board cell corresponding to the given cell coords.

Parameters:
boardside Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH).
cellx Xpos of the specified cell in the bcells array.
celly Ypos of the specified cell in the bcells array.
Returns:
The name of the cell


The documentation for this class was generated from the following files:
Generated on Sun Jun 22 13:45:47 2008 for Omweso by  doxygen 1.5.3