schemaGameGenerator.c File Reference

File containing schemaGameGenerator module. More...

#include "schemaGameGenerator.h"

Go to the source code of this file.

Functions

bool generateSchema (const char *filename, unsigned int numRow, unsigned int numCol, unsigned int difficult)
 Create a new schema with dimension Row x Column and pre-determinate difficult in given file.
bool check_generateSchema (const FILE *newSchemaFile, unsigned int difficult, unsigned int numRow, unsigned int numCol)
 Check the pre-conditions to run the generateSchema function well.
char ** gameMap_alloc_and_set (unsigned int numRow, unsigned int numCol)
 Dynamic map allocation with row dimension as numRow and column dimension al numCol.
double create_routes (unsigned int difficult, unsigned int numRow, unsigned int numCol, char **gameMap)
 After start point creation, this function uses getRouteNumber , get_denyArea , get_available_cells , point_in_random_direction , getRouteNumber , get_MaxRouteLen and get_direction_from_point functions to generate some routes from the calculate start point to the calculate doors.
unsigned int get_denyArea (unsigned int difficult, unsigned int numDir, unsigned int startDir)
 Find a length, starting from start direction ( X or Y ), where a DOOR could not stay.
unsigned int getRouteNumber (unsigned int difficult, unsigned int numRow, unsigned int numCol)
 Find the appropriate number of routes for a schema having (row,column) dimensions as (numRow,numCol).
directions set_number_of_available_cells (coordinates start, coordinates deny, unsigned int numRow, unsigned int numCol)
 Set the number of available cells in all possible directions.
unsigned int get_MaxRouteLen (unsigned int numRow, unsigned int numCol, coordinates start, coordinates door)
 Extimate the maximum route lenght to reach the door (with coordinates (doorX,doorY) ), starting from start point (with coordinates (startRow,startCol) ), in a schema with dimensions (numRow,numCol).
unsigned int point_in_random_direction (unsigned int avail_dir1, unsigned int avail_dir2, unsigned int start_dir, unsigned int deny_area, double *probability, const double LOW)
 Calculate, using also random function, the value of specified coordinate of a point in the available area, and set the relative probability.
void get_direction_from_point (unsigned int numRow, unsigned int numCol, unsigned int *currentRow, unsigned int *currentCol, double probabilityLeft, double probabilityUp)
 Set the next route step in a schema with dimention (numRow,numCol), using a predeterminated value of probability.
void increase_schema_difficult (char **Map, unsigned int numRow, unsigned int numCol)
 Increase the schema difficult, opening and closing unnecessary cells.
void save_schema_to_file (char **gameMap, unsigned int numRow, unsigned int numCol, FILE *newSchemaFile)
 Save the schema game map into a new file.


Detailed Description

File containing schemaGameGenerator module.

Definition in file schemaGameGenerator.c.


Function Documentation

bool check_generateSchema ( const FILE *  newSchemaFile,
unsigned int  difficult,
unsigned int  numRow,
unsigned int  numCol 
)

Check the pre-conditions to run the generateSchema function well.

Returns:
Positive value (true) if no errors occours in the function execution Negative value (false) otherwise.
Parameters:
newSchemaFile File to save the game
difficult Difficult level
numRow Number of row
numCol Number of column

Definition at line 57 of file schemaGameGenerator.c.

References D1, D5, MAX_DIFFICULT, MAXC, MAXR, MIN_DIFFICULT, MINC, and MINR.

Referenced by generateSchema().

Here is the caller graph for this function:

double create_routes ( unsigned int  difficult,
unsigned int  numRow,
unsigned int  numCol,
char **  gameMap 
)

After start point creation, this function uses getRouteNumber , get_denyArea , get_available_cells , point_in_random_direction , getRouteNumber , get_MaxRouteLen and get_direction_from_point functions to generate some routes from the calculate start point to the calculate doors.

Returns:
function execution time
Parameters:
difficult Difficult level
numRow Number of row
numCol Number of column
gameMap Schema game map

Definition at line 128 of file schemaGameGenerator.c.

References CLOSE, coordinates_data::col, D2, D3, D4, D5, DOOR, possible_directions::down, FREE, get_denyArea(), get_direction_from_point(), get_MaxRouteLen(), getRouteNumber(), possible_directions::left, point_in_random_direction(), possible_directions::right, coordinates_data::row, set_number_of_available_cells(), START, and possible_directions::up.

Referenced by generateSchema().

Here is the call graph for this function:

Here is the caller graph for this function:

char** gameMap_alloc_and_set ( unsigned int  numRow,
unsigned int  numCol 
)

Dynamic map allocation with row dimension as numRow and column dimension al numCol.

Returns:
a pointer to matrix
Parameters:
numRow Number of row
numCol Number of column

Definition at line 103 of file schemaGameGenerator.c.

References CLOSE, D5, and schemaProp::gameMap.

Referenced by generateSchema().

Here is the caller graph for this function:

bool generateSchema ( const char *  filename,
unsigned int  numRow,
unsigned int  numCol,
unsigned int  difficult 
)

Create a new schema with dimension Row x Column and pre-determinate difficult in given file.

Steps :

  • Check the parameters
  • Put a start point
  • Generate dx and dy (deny areas)
  • Choose the number of doors
  • Put the doors
  • Generate the routes
  • Open/Close blocks to increase difficult
  • Create the file

Returns:
Positive value (true) if no errors occours in the function execution Negative value (false) otherwise.
Parameters:
filename File name
numRow Rows number
numCol Columns number
difficult Difficult level

Definition at line 10 of file schemaGameGenerator.c.

References check_generateSchema(), create_routes(), D1, schemaProp::gameMap, gameMap_alloc_and_set(), increase_schema_difficult(), MAX_DIFFICULT, MAXC, MAXR, MIN_DIFFICULT, MINC, MINR, and save_schema_to_file().

Referenced by generate_game().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int get_denyArea ( unsigned int  difficult,
unsigned int  numDir,
unsigned int  startDir 
)

Find a length, starting from start direction ( X or Y ), where a DOOR could not stay.

This measure maybe variable and this variability maybe obtained by random function. This value is attenuate using difficult percentage.

Returns:
number of deny cells from start direction
Parameters:
difficult Difficult level
numDir Number in that Dir- ection Eg. Dir = Row
startDir Start position Dir- ection Eg. Dir = Col

Definition at line 251 of file schemaGameGenerator.c.

References D5, D6, and MAX_DIFFICULT.

Referenced by create_routes().

Here is the caller graph for this function:

void get_direction_from_point ( unsigned int  numRow,
unsigned int  numCol,
unsigned int *  currentRow,
unsigned int *  currentCol,
double  probabilityLeft,
double  probabilityUp 
)

Set the next route step in a schema with dimention (numRow,numCol), using a predeterminated value of probability.

The opposite probability value (Eg. left right) is (1-probability).

Parameters:
numRow Number of row
numCol Number of column
currentRow Current updated row.
currentCol Current updated column.
probabilityLeft Probability to go left
probabilityUp Probability to go up

Definition at line 491 of file schemaGameGenerator.c.

References D5, and D8.

Referenced by create_routes().

Here is the caller graph for this function:

unsigned int get_MaxRouteLen ( unsigned int  numRow,
unsigned int  numCol,
coordinates  start,
coordinates  door 
)

Extimate the maximum route lenght to reach the door (with coordinates (doorX,doorY) ), starting from start point (with coordinates (startRow,startCol) ), in a schema with dimensions (numRow,numCol).

Returns:
maximum route length from start point to the door
Parameters:
numRow Number of row
numCol Number of column
start Start coordinates
door Door cooridnates

Definition at line 374 of file schemaGameGenerator.c.

References coordinates_data::col, D5, and coordinates_data::row.

Referenced by create_routes().

Here is the caller graph for this function:

unsigned int getRouteNumber ( unsigned int  difficult,
unsigned int  numRow,
unsigned int  numCol 
)

Find the appropriate number of routes for a schema having (row,column) dimensions as (numRow,numCol).

This measure maybe variable and this variability maybe obtained by random function. This value is attenuate using difficult percentage.

Returns:
number of deny cells from start direction
Parameters:
difficult Difficult level
numRow Number of row
numCol Number of column

Definition at line 286 of file schemaGameGenerator.c.

References D2, D5, MAX_DIFFICULT, and MIN_DIFFICULT.

Referenced by create_routes().

Here is the caller graph for this function:

void increase_schema_difficult ( char **  Map,
unsigned int  numRow,
unsigned int  numCol 
)

Increase the schema difficult, opening and closing unnecessary cells.

Parameters:
Map Schema game map
numRow Number of row
numCol Number of column

Definition at line 554 of file schemaGameGenerator.c.

References CLOSE, D5, and FREE.

Referenced by generateSchema().

Here is the caller graph for this function:

unsigned int point_in_random_direction ( unsigned int  avail_dir1,
unsigned int  avail_dir2,
unsigned int  start_dir,
unsigned int  deny_area,
double *  probability,
const double  LOW 
)

Calculate, using also random function, the value of specified coordinate of a point in the available area, and set the relative probability.

Returns:
Coordinate value.
Parameters:
avail_dir1 Number of available cells in direction 'dir1' Eg. left
avail_dir2 Number of available cells in direction 'dir2' Eg. right
start_dir Start Dir-ection Eg. Dir = row
deny_area Deny area starting from start point
probability Calculating probabilty
LOW value of LOW probability

Definition at line 410 of file schemaGameGenerator.c.

References D5, and D8.

Referenced by create_routes().

Here is the caller graph for this function:

void save_schema_to_file ( char **  gameMap,
unsigned int  numRow,
unsigned int  numCol,
FILE *  newSchemaFile 
)

Save the schema game map into a new file.

Parameters:
gameMap Schema game map
numRow Number of row
numCol Number of column
newSchemaFile New schema file

Definition at line 602 of file schemaGameGenerator.c.

References D4, D5, PRGNAME, and PRGVERS.

Referenced by generateSchema().

Here is the caller graph for this function:

directions set_number_of_available_cells ( coordinates  start,
coordinates  deny,
unsigned int  numRow,
unsigned int  numCol 
)

Set the number of available cells in all possible directions.

Returns:
number of available cells in structure directions.
Parameters:
start Start coordinates.
deny Deny area coordinates
numRow Number of row
numCol Number of column

Definition at line 342 of file schemaGameGenerator.c.

References coordinates_data::col, D3, D5, possible_directions::down, possible_directions::left, possible_directions::right, coordinates_data::row, and possible_directions::up.

Referenced by create_routes().

Here is the caller graph for this function:


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