schemaGameUtility.h File Reference

File containing the interface of schemaGameUtility module. More...

#include <sys/stat.h>
#include <dirent.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>
#include <malloc.h>
#include <time.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
#include "define.h"
#include "gameIOManager.h"
#include "bestroute.h"

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  stateOfGame
 Data struct containing the game's state properties. More...

Typedefs

typedef struct stateOfGame currentGameState

Functions

currentGameState initializeCurrentGameState ()
 Initialize the variables in the data struct currentGameState.
double newgame (char schemafilename[], unsigned int *bestrouteweight)
 Start a new game, using loadCheckGame and bestroute functions.
bool checkRowColValues (unsigned short int *errnum, char *err)
 Checks if the number of rows and columns in the schema are corrects.
void setSchemaDataStructures (char **schema_propr)
 Set the values of the passed schema into the global variable schemaData.gameMap.
void checkDoorStartPoint (unsigned short int *errnum, char *err)
 Checks if the number of doors and start point are corrects.
unsigned short int loadCheckGame (char *file_name)
 Function that uses the function readfile to get a vector of strings, which represent the data of the schema.
unsigned int getdoors (unsigned int *doorsRow, unsigned int *doorsCol)
 Function that find all the DOORs in the schema.
bool isDirectory (char const *path)
 Check if a path is a directory.
char * get_schema_name (unsigned short int level)
 Function that retrieval a schema name of specified level randomly.
bool isallowedchar (unsigned short int typeCharSel, char char2check)
 Function that checks if the character in input is allowed Variable "selection" is used as bit mask.
unsigned int countDigits (unsigned int number)
 Count number of digits of the variable "number".
bool check_if_text_is_number (const bool runme, const char *text, char *err_buff, const char *err_label)
 Check if the passed text is composed by digits.
unsigned int calcSchemaResults (char *labeltxt, currentGameState gameState)
 Calculate the schema results (correctness, bonus, time, points) and print them into labeltxt.

Variables

static const unsigned short int START_LEVEL = 1
 Number of the first level.
static const unsigned short int START_TOTAL_POINTS = 0
 Number of points before start a tournament.
static const unsigned short int START_ROUND_NUMBER = 1
 Number of round before start a tournament.


Detailed Description

File containing the interface of schemaGameUtility module.

Definition in file schemaGameUtility.h.


Typedef Documentation

typedef struct stateOfGame currentGameState

Definition at line 69 of file schemaGameUtility.h.


Function Documentation

unsigned int calcSchemaResults ( char *  labeltxt,
currentGameState  gameState 
)

Calculate the schema results (correctness, bonus, time, points) and print them into labeltxt.

Parameters:
labeltxt Schema results output
gameState State of game

Definition at line 503 of file schemaGameUtility.c.

References stateOfGame::bestrouteweight, BONUS_POINTS, stateOfGame::currentlevel, D1, D2, GIVE_BONUS_PERC, stateOfGame::iters, NO_BONUS_POINTS, stateOfGame::numOfRound, SEC_PER_LEVEL, stateOfGame::starttime, and stateOfGame::totalpoints.

Referenced by win().

Here is the caller graph for this function:

bool check_if_text_is_number ( const bool  runme,
const char *  text,
char *  err_buff,
const char *  err_label 
) [inline]

Check if the passed text is composed by digits.

If 'runme' is set to false the function skip the checks and return 'false'.

Returns:
true if pass the check, false otherwise
Parameters:
runme Execute the check
text Text to check
err_buff Error message
err_label Label to put into err_buff

Definition at line 477 of file schemaGameUtility.c.

References DIGITS, and isallowedchar().

Referenced by checkResponseErrorGenerateParameters().

Here is the call graph for this function:

Here is the caller graph for this function:

void checkDoorStartPoint ( unsigned short int *  errnum,
char *  err 
)

Checks if the number of doors and start point are corrects.

Parameters:
errnum Number of errors
err Error string message

Definition at line 207 of file schemaGameUtility.c.

References D1, DOOR, schemaProp::gameMap, schemaProp::numCol, schemaProp::numRow, schemaData, START, schemaProp::startCol, and schemaProp::startRow.

Referenced by loadCheckGame().

Here is the caller graph for this function:

bool checkRowColValues ( unsigned short int *  errnum,
char *  err 
)

Checks if the number of rows and columns in the schema are corrects.

Returns:
true if no errors occours false otherwise
Parameters:
errnum Number of errors
err Error string message

Definition at line 138 of file schemaGameUtility.c.

References D1, MAXC, MAXR, MINC, MINR, schemaProp::numCol, schemaProp::numRow, and schemaData.

Referenced by loadCheckGame().

Here is the caller graph for this function:

unsigned int countDigits ( unsigned int  number  )  [inline]

Count number of digits of the variable "number".

Returns:
number of digits
Parameters:
number Number to analyze

Definition at line 464 of file schemaGameUtility.c.

References maxValueOfNumericBase, and numericBase.

Referenced by get_schema_name(), and set_gtk_entry_text_from_num().

Here is the caller graph for this function:

char* get_schema_name ( unsigned short int  level  ) 

Function that retrieval a schema name of specified level randomly.

Returns:
Schema name (char *)
Parameters:
level Number of the level

Definition at line 342 of file schemaGameUtility.c.

References countDigits(), D1, D2, GAMES_DIR, GAMES_LEVEL_DIR, isDirectory(), and NULLCHAR.

Referenced by new_tournament().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int getdoors ( unsigned int *  doorsRow,
unsigned int *  doorsCol 
)

Function that find all the DOORs in the schema.

Returns:
number of doors (unsigned int)
Parameters:
doorsRow Number of rows doors
doorsCol Number of column of the doors

Definition at line 299 of file schemaGameUtility.c.

References D1, DOOR, schemaProp::gameMap, schemaProp::numCol, schemaProp::numRow, and schemaData.

Referenced by newgame().

Here is the caller graph for this function:

currentGameState initializeCurrentGameState (  ) 

Initialize the variables in the data struct currentGameState.

Definition at line 17 of file schemaGameUtility.c.

References stateOfGame::bestrouteweight, stateOfGame::currentCol, stateOfGame::currentlevel, stateOfGame::currentRow, D1, gameState, stateOfGame::iters, stateOfGame::numOfRound, stateOfGame::playing, stateOfGame::starttime, and stateOfGame::totalpoints.

Referenced by gui().

Here is the caller graph for this function:

bool isallowedchar ( unsigned short int  typeCharSel,
char  char2check 
)

Function that checks if the character in input is allowed Variable "selection" is used as bit mask.

Selection = 1 means characters from 'a' to 'z' Selection = 2 means characters from 'A' to 'Z' Selection = 4 means characters from '0' to '9' Some other possible combination :

  • Selection = 3 means (2) and (1) (NB. 2+1=3)
  • Selection = 5 means (4) and (1) (NB. 4+1=5)
  • Selection = 6 means (4) and (2) (NB. 4+2=6)
  • Selection = 7 means (4) and (2) and (1) (NB. 4+2+1=7)

Returns:
Positive value (true) if the character is allowed. Negative value (false) otherwise.
Parameters:
typeCharSel Selection mask
char2check Character to check

Definition at line 420 of file schemaGameUtility.c.

References D1, D4, D5, DIGITS, LOWERCASE, and UPPERCASE.

Referenced by check_if_text_is_number(), checkResponseNameError(), and setGameRecordStructValue().

Here is the caller graph for this function:

bool isDirectory ( char const *  path  ) 

Check if a path is a directory.

Returns:
Negative value (false) if it isn't a directory or doesn't exist. Positive value (true) otherwise.
Parameters:
path Path to check

Definition at line 323 of file schemaGameUtility.c.

References D5.

Referenced by get_schema_name().

Here is the caller graph for this function:

unsigned short int loadCheckGame ( char *  file_name  ) 

Function that uses the function readfile to get a vector of strings, which represent the data of the schema.

Store the read data in it's structure without memory loss.

Returns:
number of error occurred (unsigned short int)
Parameters:
file_name Name of file that contains the game

Definition at line 238 of file schemaGameUtility.c.

References checkDoorStartPoint(), checkRowColValues(), D1, D6, schemaProp::gameMap, MAX_ERR_BUFFER_LEN, MAXC, MAXR, schemaProp::numCol, schemaProp::numRow, readfile(), schemaData, and setSchemaDataStructures().

Referenced by newgame().

Here is the call graph for this function:

Here is the caller graph for this function:

double newgame ( char  schemafilename[],
unsigned int *  bestrouteweight 
)

Start a new game, using loadCheckGame and bestroute functions.

If debug mode is turned on use printschema function to print the schema.

Returns:
execution time (double)
Parameters:
schemafilename Name of the schema to start
bestrouteweight Best route weight

Definition at line 47 of file schemaGameUtility.c.

References bestroute(), D1, D2, D4, D5, getdoors(), loadCheckGame(), schemaProp::numCol, schemaProp::numRow, printschema(), schemaData, schemaProp::startCol, and schemaProp::startRow.

Referenced by generate_game(), new_tournament(), and open_game().

Here is the call graph for this function:

Here is the caller graph for this function:

void setSchemaDataStructures ( char **  schema_propr  ) 

Set the values of the passed schema into the global variable schemaData.gameMap.

Initialize also the global variable schemaData.visitedCellInfo.

Parameters:
schema_propr Schema game map.

Definition at line 177 of file schemaGameUtility.c.

References D1, schemaProp::gameMap, schemaProp::numCol, schemaProp::numRow, schemaData, UNVISITED, and schemaProp::visitedCellInfo.

Referenced by loadCheckGame().

Here is the caller graph for this function:


Variable Documentation

const unsigned short int START_LEVEL = 1 [static]

Number of the first level.

Definition at line 29 of file schemaGameUtility.h.

Referenced by generate_game(), new_tournament(), open_game(), and win().

const unsigned short int START_ROUND_NUMBER = 1 [static]

Number of round before start a tournament.

Definition at line 33 of file schemaGameUtility.h.

Referenced by generate_game(), open_game(), and win().

const unsigned short int START_TOTAL_POINTS = 0 [static]

Number of points before start a tournament.

Definition at line 31 of file schemaGameUtility.h.

Referenced by generate_game(), new_tournament(), open_game(), and win().


Generated on Fri Apr 2 18:28:09 2010 for SMLabyrinth by  doxygen 1.5.8