Main Page   Alphabetical List   Data Structures   File List   Globals  

start_core.c File Reference

Implementation of functions declared in start_core.h. More...


Functions

void initialise_start ()
 Function used to initialise the elements of the start array. More...

void update_battlefield (char *name,int player, int x, int y)
 Update the battlefield array. More...

int pieces_placed ()
 Check if all pieces have been placed on the board. More...

int check_placement (int player, int y2)
 Check if a placement is on the correct side of the board. More...


Detailed Description

Implementation of functions declared in start_core.h.


Function Documentation

int check_placement int    player,
int    y2
 

Check if a placement is on the correct side of the board.

A function that checks if the player is placing his pieces on the correct end of the board.

Parameters:
player  The integer id of the player that made the move
y2  The y coordinate of the move command received necessary to perform the checks
Returns:
int returns TRUE (1) if all placement correct, FALSE (0) otherwise
This function checks if the placement made is on the correct end of the board and if not then prints the adequate
debug information and returns FALSE. Exploiting the unique identification number that each player has, we check if
player 0 has placed a piece in the bottom two rows and player 1 in the top two. For this reason only the y coordinate is used to perform the check.
i.e. in squares in battlefield (y = 8,9) for player 1, and 0,1 for player 0

00123                                           {
00124 
00125         if (player == 1){
00126                 if ( (y2 == 8) || (y2 == 9))
00127                         return TRUE;
00128                 else {
00129                         vccPrintPdxDebugInfo("Player 1 can only place pieces in the top part of the board\n");
00130                         return FALSE;
00131                 }
00132         } else if (player == 0){
00133                 if ( (y2 == 0) || (y2 == 1))
00134                         return TRUE;
00135                 else {
00136                         vccPrintPdxDebugInfo("Player 0 can only place pieces in the bottom part of the board\n");
00137                         return FALSE;
00138                 }
00139         }
00140 
00141         return FALSE;
00142 }

void initialise_start  
 

Function used to initialise the elements of the start array.

Returns:
void
Basic functionality is to assign to each element of the array a specific value that represents that piece.
For example, start[0][1] is assigned to a Marshal. This element fills its fields with the below values:

marshal.name = "Marshal";
marshal.remaining = 1;
marshal.player = 0;

At the end this piece structure is assigned to the correct element and this square is now initialised
start[0][1] = marshal;

This function is automatically called by the poin_entry_Init function in the white.c file, when the game is commenced.

00004                        {
00005 
00006 /* first form structs of pieces to be added to array */
00007         start_piece marshal , general , colonel , major , captain , lieutenant;
00008         start_piece sergeant , miner , scout , spy , bomb , flag;
00009 
00010         /* marshal */
00011         marshal.name = "Marshal";
00012         marshal.remaining = 1;
00013         marshal.player = 0;
00014 
00015         /* general */
00016         general.name = "General";
00017         general.remaining = 1;
00018         general.player = 0;
00019 
00020         /* colonel */
00021         colonel.name = "Colonel";
00022         colonel.remaining = 2;
00023         colonel.player = 0;
00024 
00025         /* major */
00026         major.name = "Major";
00027         major.remaining = 3;
00028         major.player = 0;
00029         
00030         /* captain */
00031         captain.name = "Captain";
00032         captain.remaining = 4;
00033         captain.player = 0;
00034 
00035         /* lieutenant */
00036         lieutenant.name = "Lieutenant";
00037         lieutenant.remaining = 4;
00038         lieutenant.player = 0;
00039         
00040         /* sergeant */
00041         sergeant.name = "Sergeant";
00042         sergeant.remaining = 4;
00043         sergeant.player = 0;
00044 
00045         /* miner */
00046         miner.name = "Miner";
00047         miner.remaining = 5;
00048         miner.player = 0;
00049 
00050         /* scout */
00051         scout.name = "Scout";
00052         scout.remaining = 8;
00053         scout.player = 0;
00054 
00055         /* spy */
00056         spy.name = "Spy";
00057         spy.remaining = 1;
00058         spy.player = 0;
00059 
00060         /* bomb */
00061         bomb.name = "Bomb";
00062         bomb.remaining = 6;
00063         bomb.player = 0;
00064 
00065         /* flag */
00066         flag.name = "Flag";
00067         flag.remaining = 1;
00068         flag.player = 0;
00069 
00070         
00071         /* Now place data (structs) on board */
00072 
00073         /* first row */
00074         start[0][1] = marshal;  
00075         start[1][1] = general;
00076         start[2][1] = colonel;
00077         start[3][1] = major;
00078         start[4][1] = captain;
00079         start[5][1] = lieutenant;
00080 
00081         /* ...second row */
00082         start[0][2] = sergeant;
00083         start[1][2] = miner;
00084         start[2][2] = scout;
00085         start[3][2] = spy;
00086         start[4][2] = bomb;
00087         start[5][2] = flag;
00088 }

int pieces_placed  
 

Check if all pieces have been placed on the board.

A function that checks if all pieces are placed on board

Returns:
int returns TRUE (1) if all pieces have been placed, FALSE (0) otherwise
This function checks the start array to see if all pieces have been placed on the board. It is called whenever a player
presses the START button. i.e. whenever he tries to commence the game. The game rules point out that for a game to
start the player must firstly place all pieces on the board. To check this, I have exploited the representation of
a piece during the initialisation stage with the start array. In particular, the "remaining" field, which shows how
many pieces are still to be placed on the board.

00105                    {
00106 
00107         int i , j;
00108 
00109         
00110         for (i=0; i<=5; i++){
00111                 for (j=0; j<=2; j++){
00112                         if (start[i][j].remaining != 0)
00113                                 return FALSE;
00114                 }
00115         }
00116         
00117         return TRUE; /* TRUE means all pieces have been placed */
00118 }

void update_battlefield char *    name,
int    player,
int    x,
int    y
 

Update the battlefield array.

A function that updates the battlefield array.

Parameters:
name  The name of the piece that was placed on the battlefield
player  The integer id of the player that made the move
x  The integer x coordinate of the board that the piece was placed on
y  The integer y coordinate of the board that the piece was placed on
Returns:
void
This function is the link between the initialisation part of the game and the battle part. When a piece is primarily,
placed on the board two things occur:
  1. The start array is updated (i.e. the "remaining" field is decremented
  2. The battlefield array element corresponding to the coordinates where the piece was placed, is filled in with its
    data. For example, if the piece in start[2][1] is placed on piece [5][4] on the board, then the element
    battlefield[5][4] should now hold the data for a Marshal which is the start[2][1] element.
This function makes use of the getIndexInTable function and the pieces_table array.

00090                                                                  {
00091 
00092          int index;
00093         
00094         /* now update data on battlefield */
00095 
00096         index = getIndexInTable(name); 
00097 
00098 
00099         battlefield[x][y].occupied = pieces_table[index];
00100                                 
00101         battlefield[x][y].player = player;
00102 }


Generated on Sat Mar 16 13:12:16 2002 for SLIP 2002 - Stratego2Go by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002