Due dates:

Getting Started

Start by downloading CS101_Assign03_Fa23.zip, saving it in the directory H:\CS101.

Start a Cygwin Bash Shell and run the following commands:

cd h:
cd CS101
unzip CS101_Assign03_Fa23.zip
cd CS101_Assign03_Fa23

Using Notepad++, open the file

H:\CS101\CS101_Assign03_Fa23\Dominoes.cpp

You will add your code to this file.

Your Task

The program should prompt the user to enter the initial configuration for up to 20 dominoes and then

  1. Print the initial configuration
  2. Simulate how the domino configuration will change when the first domino is tipped over for 10 time steps.

When you are ready to compile the program, in the Cygwin window type the command

make

To run the program, type the command

./Dominoes.exe

Example run (user input in bold):

Position 1 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 2 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 3 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 4 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 0
Position 5 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 2
Position 6 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 7 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 8 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 9 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 0
Position 10 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 11 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): -1

Initial state:
||| /||| |

Tipping over domino 0:
/|| /||| |

Time step 1:
_/| _/|| |

Time step 2:
__/ __/| |

Time step 3:
___ ___/ |

Time step 4:
___ ____ |

Time step 5:
___ ____ |

Time step 6:
___ ____ |

Time step 7:
___ ____ |

Time step 8:
___ ____ |

Time step 9:
___ ____ |

Time step 10:
___ ____ |

Finished!

Milestone 1

In Milestone 1, your tasks are to

Here is an example run of the program for Milestone 1 (user input in bold):

Enter the initial configuration:
Position 1 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 2 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 3 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 0
Position 4 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 5 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 2
Position 6 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 3
Position 7 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 0
Position 8 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 9 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): -1

Initial state:
|| |/_ |

Deliverables for Milestone 1

The code for Milestone 1 should be submitted to Marmoset (using the command make submit_ms1) by the end of the day on Thursday, Oct 5th.

Submitting Milestone 1

To submit your code, make sure your Dominoes.cpp file is saved, and in the Cygwin window type

make submit_ms1

Approach/Hints

Domino states

Use an array of integer values to store the state of each domino and a counter to track the number of valid domino elements. Then use loops to obtain the initial state from the user until either 20 dominoes are entered or the user enters -1. Store the number of valid dominoes the user entered and print out the initial configuration using a loop.

Milestone 2

In Milestone 2, using the initial domino state stored in an array from Milestone 1, your task is to simulate the new states when the first domino is tipped (only if it is upright) for 10 consecutive time steps.

The rules for updating the state of a domino are as follows:

Here is an example run (user input in bold):

Position 1 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 2 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 3 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 4 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 0
Position 5 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 2
Position 6 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 7 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 8 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 9 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 0
Position 10 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 11 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): -1

Initial state:
||| /||| |

Tipping over domino 0:
/|| /||| |

Time step 1:
_/| _/|| |

Time step 2:
__/ __/| |

Time step 3:
___ ___/ |

Time step 4:
___ ____ |

Time step 5:
___ ____ |

Time step 6:
___ ____ |

Time step 7:
___ ____ |

Time step 8:
___ ____ |

Time step 9:
___ ____ |

Time step 10:
___ ____ |

Finished!

Deliverables for Milestone 2

The design artifact for Milestone 2 is due at the beginning class on Thursday, Oct 12th. Make sure that you fill out the “Strategy” and “Control flow sketch” sections of the design template.

The code for Milestone 2 should be submitted to Marmoset (using the command make submit_ms2) by the end of the day on Monday, Oct 16th.

Submitting Milestone 2

To submit your code, make sure your Dominoes.cpp file is saved, and in the Cygwin window type

make submit_ms2

Approach/Hints

Start by changing the state of the first domino if it is upright to tipping. If it is not upright, then its state should not change.

Construct an outer for loop to count the timesteps. Then for each time step (i.e. nested inside the outer loop) should be two for loops:

You should use a value for “ready to tip” positions that is distinct from the values that represent empty, upright, tipping, and horizontal.

Use a third for loop to print out the configuration of the playing field after the simulation of the timestep has completed.

Get code working to simulate a single time step before working on multiple time steps. Consider adding debug code to print out the values in the array at intermediate points in the code, e.g. after each of the three for loops in a single time step.

Grading

Your grade will be determined as follows:

Milestone 1 - 35 points

Milestone 2 - 65 points

We expect you to use good coding style. Points may be deducted for poor variable names, inconsistent or missing indentation, and/or lack of comments.

Extra Credit - 10 points

Run the simulation only as long as the state changes.

Here is an example run (user input in bold):

Position 1 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 2 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 3 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 4 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 0
Position 5 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 2
Position 6 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 7 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 8 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 9 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 0
Position 10 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): 1
Position 11 (0=empty, 1=upright, 2=tipping, 3=horizontal, -1=finished): -1

Initial state:
||| /||| |

Tipping over domino 0:
/|| /||| |

Time step 1:
_/| _/|| |

Time step 2:
__/ __/| |

Time step 3:
___ ___/ |

Time step 4:
___ ____ |

Finished!

Submitting

To submit your code, make sure your Dominoes.cpp file is saved, and in the Cygwin window type one of the following commands (depending on whether you are submitting Milestone 1 or Milestone 2).

For Milestone 1:

make submit_ms1

File Milestone 2:

make submit_ms2

Enter your Marmoset username and password (which you should have received by email.) Note that your password will not be echoed to the screen. Make sure that after you enter your username and password, you see a message indicating that the submission was successful.

Make sure that you check the file(s) you submitted to ensure that they are correct. See the instructions for Verifying your submission.

Important: It is your responsibility to verify that you submitted the correct files. You may receive a grade of 0 for incorrectly submitted work.