Date

September 29, 2016

Activity 1: Login and Record Attendance

We will be taking roll in lab each week! Please come to your assigned lab to be counted present!

If you are in an Olsson lab, click "Lab Attendance" on the left-hand menu in Collab to register your attendance and keep up with your lab grade.
YOU MUST CLICK THE LARGE GREEN OR YELLOW BUTTON FOR YOUR ATTENDANCE TO COUNT!!

You must do this from a machine in Olsson 001 and not your laptop. If you have trouble, talk to your lab TA. Students in Lab 109 will do attendance via direction from the TA.

Activity 2: Take Quiz 3

While you are waiting for lab to start, click on Tests & Quizzes in Collab from either the desktop or laptop and take Quiz 3 - a very short review quiz on the material we have covered thus far. If you do not complete it today, you have until Sunday to do so.

Activity 3: Starting Out

First, find a partner to work with today if you have not yet done so.

The TAs will walk you through how to play the game of Pig, discussing the basic game algorithm and how you might put together your own version.

If you are not familiar with the game, read up on the rules here: Pig - Dice Game Rules (We are playing the main game type, not one of the variants listed.)

Activity 4: Pseudocode

Here's an outline of what the program will look like. This isn't necessarily the only way to do it, but it's one way to pull it off.

Read through this algorithm and see if you have any questions.

# Here are some suggested variables you might need:
player_temp_total = 0
player_total = 0
comp_temp_total = 0
comp_total = 0
turn = "player"
winning_score = 50

while neither has reached the needed score to win:

    while it is player 1's turn:
        Print the current score of both players
        roll the die (i.e. get a random number between 1 and 6) - something like roll = randint(1,6)
        if the die comes up with a 1:
            the player loses any currently allocated points
            reset the temporary score
            switch to the computer's turn
        else:
            add the die roll to a temporary set of accumulated points
            ask if they want to roll again 
            if no:
                add the temporary set of points to the player's bank
                reset the temporary score
                switch to the computer's turn
        if player's total > score needed to win:
            print the winning message and end the game


    while it is the computer's turn:  
        # the computer's code goes here and looks similar to above, 
        # except you determine when the computer will end its turn as 
        # opposed to prompting the user
        # try different reasons to stop and see what works!  
        # for example, have the computer always keep rolling until it
        # banks 10 points before ending it's turn

Activity 5: Example Run

Here's an example game where the score to reach is 50 (we use 50 here instead of 100 because playing to 100 takes a bit too much space... the game is the same). Your outputs do not have to exactly match ours, but this gives an idea of what the game could look like.

Welcome to Pig!

Player: 0 Computer: 0
It's your turn!
You rolled a 2
You currently have 2 banked.
Do you wish to roll again (y/n)?: y

Player: 0 Computer: 0
It's your turn!
You rolled a 4
You currently have 6 banked.
Do you wish to roll again (y/n)?: y

Player: 0 Computer: 0
It's your turn!
You rolled a 5
You currently have 11 banked.
Do you wish to roll again (y/n)?: n
Your total score is now: 11

Player: 11 Computer: 0
It's the computer's turn!
The computer rolled a 4
The computer has 4 banked.

Player: 11 Computer: 0
It's the computer's turn!
The computer rolled a 6
The computer has 10 banked.
The computer has chosen to end its turn.
The computer's score is now: 10

Player: 11 Computer: 10
It's your turn!
You rolled a 3
You currently have 3 banked.
Do you wish to roll again (y/n)?: y

Player: 11 Computer: 10
It's your turn!
You rolled a 1
PIG! Too bad! Your total is currently: 11

Player: 11 Computer: 10
It's the computer's turn!
The computer rolled a 3
The computer has 3 banked.

Player: 11 Computer: 10
It's the computer's turn!
The computer rolled a 4
The computer has 7 banked.
The computer has chosen to end its turn.
The computer's score is now: 17

Player: 11 Computer: 17
It's your turn!
You rolled a 5
You currently have 5 banked.
Do you wish to roll again (y/n)?: y

Player: 11 Computer: 17
It's your turn!
You rolled a 1
PIG! Too bad! Your total is currently: 11

Player: 11 Computer: 17
It's the computer's turn!
The computer rolled a 3
The computer has 3 banked.

Player: 11 Computer: 17
It's the computer's turn!
The computer rolled a 2
The computer has 5 banked.

Player: 11 Computer: 17
It's the computer's turn!
The computer rolled a 6
The computer has 11 banked.
The computer has chosen to end its turn.
The computer's score is now: 28

Player: 11 Computer: 28
It's your turn!
You rolled a 5
You currently have 5 banked.
Do you wish to roll again (y/n)?: y

Player: 11 Computer: 28
It's your turn!
You rolled a 5
You currently have 10 banked.
Do you wish to roll again (y/n)?: n
Your total socre is now: 21

Player: 21 Computer: 28
It's the computer's turn!
The computer rolled a 4
The computer has 4 banked.

Player: 21 Computer: 28
It's the computer's turn!
The computer rolled a 3
The computer has 7 banked.
The computer has chosen to end its turn.
The computer's score is now: 35

Player: 21 Computer: 35
It's your turn!
You rolled a 2
You currently have 2 banked.
Do you wish to roll again (y/n)?: y

Player: 21 Computer: 35
It's your turn!
You rolled a 4
You currently have 6 banked.
Do you wish to roll again (y/n)?: y

Player: 21 Computer: 35
It's your turn!
You rolled a 1
PIG! Too bad! Your total is currently: 21

Player: 21 Computer: 35
It's the computer's turn!
The computer rolled a 4
The computer has 4 banked.

Player: 21 Computer: 35
It's the computer's turn!
The computer rolled a 5
The computer has 9 banked.
The computer has chosen to end its turn.
The computer's score is now: 44

Player: 21 Computer: 44
It's your turn!
You rolled a 1
PIG! Too bad! Your total is currently: 21

Player: 21 Computer: 44
It's the computer's turn!
The computer rolled a 3
The computer has 3 banked.

Player: 21 Computer: 44
It's the computer's turn!
The computer rolled a 2
The computer has 5 banked.

Player: 21 Computer: 44
It's the computer's turn!
The computer rolled a 2
The computer has 7 banked.
The computer has chosen to end its turn.
The computer's score is now: 51
The computer wins! 51 to 21

Activity 6: Get Coding!

You have the pseudocode, you have an example, now get to it!

Submission

Submission: Each partner should submit one .py file named pig.py to https://archimedes.cs.virginia.edu/cs1110/. Please put both partners' names and id's in two comments at the top of the file.

Submit before you leave! Even if you don't finish, submit what you have.