Due dates:

Getting Started

Start by downloading CS101_Assign03.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.zip
cd CS101_Assign03

Using Notepad++, open the file

H:\CS101\CS101_Assign03\Dominoes.cpp

You will add your code to this file.

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

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.

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!

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
Position 2 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 3 (0=empty, 1=upright, 2=tipping, 3=horizontal): 0
Position 4 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 5 (0=empty, 1=upright, 2=tipping, 3=horizontal): 2
Position 6 (0=empty, 1=upright, 2=tipping, 3=horizontal): 3
Position 7 (0=empty, 1=upright, 2=tipping, 3=horizontal): 0
Position 8 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 9 (0=empty, 1=upright, 2=tipping, 3=horizontal): -1

Initial state:
|| |/_ |

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 and print out the initial configuration.

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 Wednesday, Oct 10th.

Milestone 2

In Milestone 2, using the initial state from Milestone 1 your task is to simulate the new states when the first domino is tipped 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
Position 2 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 3 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 4 (0=empty, 1=upright, 2=tipping, 3=horizontal): 0
Position 5 (0=empty, 1=upright, 2=tipping, 3=horizontal): 2
Position 6 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 7 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 8 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 9 (0=empty, 1=upright, 2=tipping, 3=horizontal): 0
Position 10 (0=empty, 1=upright, 2=tipping, 3=horizontal): 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!

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.

Each time step should be implemented as 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.

Deliverables for Milestone 2

The design artifact for Milestone 2 is due at the beginning class on Friday, 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 Thursday, Oct 18th.

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
Position 2 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 3 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 4 (0=empty, 1=upright, 2=tipping, 3=horizontal): 0
Position 5 (0=empty, 1=upright, 2=tipping, 3=horizontal): 2
Position 6 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 7 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 8 (0=empty, 1=upright, 2=tipping, 3=horizontal): 1
Position 9 (0=empty, 1=upright, 2=tipping, 3=horizontal): 0
Position 10 (0=empty, 1=upright, 2=tipping, 3=horizontal): 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.

If the make commands above do not work, you can submit using the web interface (see the link for details).

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