Hi If someone could just help me set up the problem regardin
Hi! If someone could just help me set up the problem regarding seeding, thatd be great. Setting them up is what im having trouble doing for the prompt below. Thanks in advance!
For this problem we have two pieces, P1 and P2, randomly placed on a R X C board. R is the number of rows and C is the number of columns. Each round P1 and P2 attempt to move closer together by moving a random amount towards the other piece\'s current position. Your job is to figure out the average number of rounds it takes for P1 and P2 to arrive at the same spot.
Input Constraints
Seed: an integer
Number of rows: an integer greater than 0
Number of columns: an integer greater than 0
Number of rounds: an integer greater than 0
Randomness
In order to match the tester output you must make calls to rand in the exact order that I do
For each simulation
 Generate the starting row number for P1
  Generate the starting column number for P1  Generate the starting row number for P2
  Generate the starting column number for P2
For each round in a simulation
If P1 and P2 are on different rows generate a random new row position for P1
This value should be between [P1\' srow ,P2\' srow]
If P1 and P2 are on different columns generate a random new column position for P1
 This value should be between [ P1 \' s column , P2 \' s column ]
  If P1 and P2 are on different rows generate a random new row position for P2
 This value should be between [P2\' srow ,P1\' srow]
  If P1 and P2 are on different columns generate a random new column position for P2
This value should be between [ P2 \' s column , P1 \' s column ]
Additional Requirements
• In order to help with debugging if the number of simulations to run is less than or equal to 5 your program should print out the following information
  The starting positions of P1 and P2
  Where P1 and P2 move to each round
Worked Examples
Here are some examples on a 3 X 3 board that show you the state of the board after each move. Piece 1 is represented by X and Piece 2 by O. When they land on the same spot only X is shown.
Example 1
Since the pieces move towards the other pieces\' current position sometimes they can end up passing each other.
0*X * 1** O 2** *
01 2
 First piece moves from 0,1 to 0,2 Second piece moves from 1,2 to 1,1
0** X 1*O * 2** *
01 2
 First piece moves from 0,2 to 0,2 Second piece moves from 1,1 to 0,2
0** X 1** * 2** *
01 2
Example 2
0O* * 1** X 2** *
01 2
 First piece moves from 1,2 to 1,1 Second piece moves from 0,0 to 0,0
0O* * 1*X * 2** *
01 2
 First piece moves from 1,1 to 0,0 Second piece moves from 0,0 to 0,0
0X* * 1** * 2** *
01 2
Example 3
Since the pieces move towards the other pieces\' current position sometimes they can end up passing each other. Sometimes a piece might not choose to move at all
0*O * 1*X * 2** *
01 2
 First piece moves from 1,1 to 0,1 Second piece moves from 0,1 to 1,1
0*X * 1*O * 2** *
01 2
 First piece moves from 0,1 to 0,1 Second piece moves from 1,1 to 1,1
0*X * 1*O * 2** *
01 2
 First piece moves from 0,1 to 1,1 Second piece moves from 1,1 to 0,1
0*O * 1*X * 2** *
01 2
 First piece moves from 1,1 to 1,1 Second piece moves from 0,1 to 1,1
0** * 1*X * 2** *
01 2
Real Examples
1. Enter the seed for the random number generator: 10 Enter the number of rows on the board: 5
 Enter the number of columns on the board: 7
 Enter the number of simulations to run: 2 Simulation 0
to meet.
 2. Enter the seed for the random number generator: 12
Enter the seed for the random number generator: -34 Enter the number of rows on the board: 10
 Enter the number of columns on the board: 10
 Enter the number of simulations to run: 50
Enter the seed for the random number generator: bob
Solution
//
#include <stdio.h>
 #include <stdlib.h>
void UserPrompt(), Move(), RunSimulation();
int assert_formatting(int numberOfArguments, int numNeeded) {
     // Read the entire line if user input and check if it is valid.
     char newLine;
     int garbage = 0;
     do {
         scanf(\"%c\", &newLine);
         garbage = (newLine != \'\ \' && newLine != \' \') || garbage;
     } while (newLine != \'\ \');
     return (numberOfArguments == numNeeded && !garbage);
 }
void UserPrompt(int *seed, int *rows, int *columns, int *rounds) {
     // Get user imput for seed, rows, columns, and rounds
     int numOfArgs = 0;
     do {
         printf(\"Enter the seed for the random number generator: \");
         numOfArgs = scanf(\" %d\", &*seed);
     } while (!assert_formatting(numOfArgs, 1));
    do {
         printf(\"Enter the number of rows on the board: \");
         numOfArgs = scanf(\" %d\", &*rows);
     } while (!assert_formatting(numOfArgs, 1) || *rows < 1);
    do {
         printf(\"Enter the number of columns on the board: \");
         numOfArgs = scanf(\" %d\", &*columns);
     } while (!assert_formatting(numOfArgs, 1) || *columns < 1);
    do {
         printf(\"Enter the number of simulations to run: \");
         numOfArgs = scanf(\" %d\", &*rounds);
     } while (!assert_formatting(numOfArgs, 1) || *rounds < 1);
    return;
 }
void Move(int *self, int other) {
     // Calculate a new position and update variable self
     int move = random() % (abs(*self - other) + 1);
     *self += (*self < other) ? move : -move;
 }
void RunSimulation(int rows, int columns, int numOfSims) {
     // Generate a random start position for two pieces and have them move a random distance towards each other.
     int P1_R, P1_C, P2_R, P2_C, P1_R_OLD, P1_C_OLD, P2_R_OLD, P2_C_OLD, totalrounds = 0;
    for (int i = 0; i < numOfSims; i++) {
         // Iterate the simulation a total of numOfSims.
       
         // Generate random start positions.
         P1_R = random() % rows;
         P1_C = random() % columns;
         P2_R = random() % rows;
         P2_C = random() % columns;
        if (numOfSims <= 5) {
             printf(\"\ Simulation %d\ \", i);
             printf(\"Piece one starts at: %d, %d\ \", P1_R, P1_C);
             printf(\"Piece two starts at: %d, %d\ \", P2_R, P2_C);
         }
         while (P1_R != P2_R || P1_C != P2_C) {
             // Move the pieces towards each other until they acquire the same space.
             // Piece 1: update position
             P1_R_OLD = P1_R;
             P1_C_OLD = P1_C;
             if (P1_R != P2_R) Move(&P1_R, P2_R);
             if (P1_C != P2_C) Move(&P1_C, P2_C);
             // Piece 2: update position
             P2_R_OLD = P2_R;
             P2_C_OLD = P2_C;
             if (P2_R != P1_R) Move(&P2_R, P1_R);
             if (P2_C != P1_C) Move(&P2_C, P1_C);
             if (numOfSims <= 5) {
                 printf(\"First piece moves from %d,%d to %d,%d\ \", P1_R_OLD, P1_C_OLD, P1_R, P1_C);
                 printf(\"Second piece moves from %d,%d to %d,%d\ \", P2_R_OLD, P2_C_OLD, P2_R, P2_C);
             }
             totalrounds++;
         }
     }
    printf(\"\ On average it takes %.2lf rounds on a board %d X %d for the pieces to meet.\ \",
            ((float) totalrounds / (float) numOfSims), rows, columns);
 }
int main() {
     int seed, rows, columns, rounds;
UserPrompt(&seed, &rows, &columns, &rounds);
srandom(seed);
RunSimulation(rows, columns, rounds);
     return 0;
}




