Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i dont think the code works, this is the second part for the problem, please refer to the previous one aswell and give an answer

i dont think the code works, this is the second part for the problem, please refer to the previous one aswell and give an answer with all the parts in it. Please also give an output for the same and should be in c not cppDynamically allocate one 2-D integer array with identifier boardpp and with dimensions
number of rows by number of columns. Check that the allocations have worked and print the
following error messages if the allocation fails. After printing an error message, clean up, and
terminate the program. This array represents the gameboard. This array will hold the integer
representations of the colours of the squares (White=1, Red=2, Green=3, Blue=4)
ERROR: array of pointers for could not be allocated
ERROR: Array storage could not be allocated
Dynamically allocate one 1-D array of structures of length numRobots.
You will then initialize the board by calling function InitBoard with the following prototype.
This function will call the selected individual initialization functions.
int InitBoard ( int **boardpp, int numRows, int numCols,
enum initTypelist my(ist, unsigned int seed);
The initialization function will be chosen to create one of the three possible initial board types
described below
Initial Board type Rand: The colour of each square randomly chosen from the four available
colours. For each square, the probability of any one of the colours being chosen will be equal.
This function is posted with the description of the assignment. The provided function
initializes using srand(initSeed) immediately before determining the colour of the first square
(0,0). The colour of the squares are initialized by one, using one call to rand for each square.
The first square (0,0) will use the first random number generated by rand(). Initialization will
proceed along a row, then on to the start of the next row. This is the same ordering as the
ordering of elements in memory. To assure a matching random board please use the provided
function for this initialization method.
void InitBoardRand(int **board, int numRows, int numCols,
unsigned int seed);
Initial Board type Checkerboard: White and red checkerboard pattern with upper left square
(0,0) initialized to white.
void InitBoardChecker(int **board, int numRows, int numCols);
Initial Board type AllWhite: All squares in the board initialized to white.
void InitBoardAlLWhite(int **board, int numRows, int numCols);
Randomly place each robot on the board, assign the direction it is facing, and assign the
colour of paint it is carrying. To do these things use the following algorithm. To compare to
the provided output (get the same random numbers) order is very important.
Initialize the random number generator srand(seed)
For each robot ( number of robots -1)
Robot x coordinate = rand()% numCols;
Robot y coordinate = rand()% numRows;
Direction robot is facing= rand()% NUM_DIRECTIONS +1 ;
Colour of paint the robot is carrying = rand()% NUM_COLOURS +1 ;
Run the game for the number of turns requested. For each turn each robot will move forward,
then rotate, and then change the colour of the square it has moved onto.
a. If moving forward moves the robot off the top of the board in will reappear in the
bottom row (the column will not change)
b. If moving forward moves the robot off the bottom of the board it will reappear on the
top row of the board ( the column will not change)
c. If moving to the left moves the robot off the side of the board then it will reappear on
the other side of the board (the row will not change)
You will print the board into the output file and to the screen every interval turns. The output
will be printed for turn 0(initial state), turn interval, turn 2xinterval .... turn number of turns
-1. The final turn need not be a multiple of interval.
I am providing you with a print function that will display the board in colour on your terminal
(it works only for the terminal, it does not work for writing into a file). This should help you
when you are debugging.
Sample outputs for comparison will be posted in the next few days.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions