I need some help on a assignment whose documentation follows:
Your task is to simulate a game between two teams of nine players. The reason for nine players is to facilitate reasonable printing out of the playing field onto the screen or into an output file. Smashball is played on a 25 by 25 square field. When printing out game results, be sure to print out the field with a border around the field.
- Game Initialization
a. Use a random number generator to randomly place all the players in the playing field. If the random process produces two players starting on the same position, redraw new random positions such that all players start on unique spots.
b. Use a random number generator to generate an initial motion direction for each player. The four motion choices for this assignment are East, West, North and South. These directions correspond to the respective movement of each player on the playing field.
My code (so far) follows:
#include <stdio.h>
#include <stdlib.h>
#define SIZE_AREA 25
#define SIZE_TEAM 25
int team [SIZE_TEAM];
int field [SIZE_AREA][SIZE_AREA];
int main (){
int i;
int j;
for (i = 0; i < SIZE_TEAM; i++){
team [i] = field [(rand() % 24)][(rand() % 24)];
}
enum move_direction {East, West, North, South};
for (j = 0; j < SIZE_TEAM; j++){
It's incomplete, but I still am hitting some roadblocks here and there:
How do if the random process produces two players that are starting on the same spot? I need to compare one player's position to the other players' position to see if it's unique. If not, then I have to redraw the positions, but how do I this recursively in C? What if the redrawn positions still are duplicates to another player's position?
The game initialization section asks me to randomly generate initial motion directions for the players, but I can't assign the direction to the players since I'll overwrite their positions. How can I code directions for the players without overwriting their initial positions and how can I change their direction from turn to turn?
That's all I have to say. Again, read the link before commenting and let me know if you can help me (but please, don't give me full-blown answers. Just indicate the source of my concerns and tell me what I should do).