#include <ow_board.h>
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_cell * | bcells [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] |
ow_board::ow_board | ( | int | columns | ) |
Creates a new 'ow_board' object, create board cells, and sets default board values.
columns | Number of columns the board has. |
ow_board::ow_board | ( | ow_board * | board | ) |
Creates a new board, copying data from this board
ow_board::~ow_board | ( | ) |
Deletes an 'ow_board' object.
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)
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.
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. |
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.
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. |
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.
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. |
int ow_board::saveundo | ( | ) | [private] |
Save the cells content info to a backup private variable (undodata array) for future use with the undolasmove() function.
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
SDL_Palette * ow_board::get_palette | ( | ) |
Returns gfx color palette for draw_gfx to use
void ow_board::draw_gfx | ( | SDL_Surface * | surface | ) |
Draws the gfx board using SDL library
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.
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. |
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.
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. |
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.
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. |
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.
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. |
int ow_board::capture | ( | ) |
Executes a Capture in the cell where the last sow movement ended.
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.
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. |
int ow_board::countseeds | ( | int | boardside, | |
int | cellx, | |||
int | celly | |||
) |
Returns the count of seeds 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. |
int ow_board::countseeds | ( | int | boardside | ) |
Returns the count of seeds in the specified board side.
boardside | Side of the board (BRD_SIDE_NORTH, BRD_SIDE_SOUTH). |
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.
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 |
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.
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. |
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.
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. |
int ow_board::checkavailablemoves | ( | int | boardside | ) |
Checks if there is any allowed moves for the player with the turn.
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.
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::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.
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. |
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.
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.
nummoves | Number of moves to 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.
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.
int ow_board::endofturn | ( | ) |
Check if the board has finished executing last user commands and is ready for new commands.
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.
int ow_board::getcolcount | ( | ) |
Gets the number of columns the board has.
int ow_board::counthandseeds | ( | ) |
Gets the number of seeds in the 'this->handseeds' variable.
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.
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. |
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.
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.
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. |