Answered step by step
Verified Expert Solution
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 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 Red Green Blue
ERROR: array of pointers for could not be allocated
ERROR: Array storage could not be allocated
Dynamically allocate one 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 myist 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 srandinitSeed immediately before determining the colour of the first square
The colour of the squares are initialized by one, using one call to rand for each square.
The first square 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 InitBoardRandint board int numRows, int numCols,
unsigned int seed;
Initial Board type Checkerboard: White and red checkerboard pattern with upper left square
initialized to white.
void InitBoardCheckerint board int numRows, int numCols;
Initial Board type AllWhite: All squares in the board initialized to white.
void InitBoardAlLWhiteint 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 srandseed
For each robot number of robots
Robot coordinate rand numCols;
Robot y coordinate rand numRows;
Direction robot is facing rand NUMDIRECTIONS ;
Colour of paint the robot is carrying rand NUMCOLOURS ;
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 initial state turn interval, turn xinterval turn number of turns
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.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started