Docsity

Pythons Last Stand - Introduction to Computing | CS 1301, Assignments of Computer Science

Toggle sidebar
bg1
EXTRA CS 1301 – Fall 2006 Page 1/5
CS 1301 – Fall 2006
EXTRA – Python’s last stand
Due: Wednesday, December 6, 2006 at 6 PM EST
Files to submit: hw11.py
1. Fill in skeleton code provided
IMPORTANT NOTES:
• Since we will be taking averaging only the top 10 homework grades, you do not need to
complete this homework if you are already satisfied with your homework average.
• Since this extra homework is being turned in so late, it is going to be autograded – this
means that it is all or nothing. The TA’s will be available to help, but if you do turn it in,
please make sure it works completely
• There is no extra credit on this assignment
A good source of information for completing this homework would be to look in your old
completed homework or in the book.
Overview
http://en.wikipedia.org/wiki/Yahtzee
In this assignment, you will be programming a small part of the popular dice game, Yahtzee.
In the game, players roll 5 dice and make poker-like combinations out of them in order to rack
up certain point values.
Specifically, we will be making a YahtzeeHand class which contains an array of 5 numbers and
3 different methods which check to see if you have rolled certain hands.
While there are many more combination of dice, you only need to check for these 3:
• Yahtzee – the same as 5 of a kind (all 5 dice have the same value)
• Straight – the dice are all in order (ie, 1,2,3,4,5 OR 2,3,4,5,6)
• Four of a Kind – 4 of the dice have the same value, we don’t care about the 5th die
pf3
pf4
pf5

Partial preview of the text

Download Pythons Last Stand - Introduction to Computing | CS 1301 and more Assignments Computer Science in PDF only on Docsity!

CS 1301 – Fall 2006

EXTRA – Python’s last stand

Due: Wednesday, December 6, 2006 at 6 PM EST

Files to submit: hw11.py

1. Fill in skeleton code provided

IMPORTANT NOTES:

  • Since we will be taking averaging only the top 10 homework grades, you do not need to complete this homework if you are already satisfied with your homework average.
  • Since this extra homework is being turned in so late, it is going to be autograded – this means that it is all or nothing. The TA’s will be available to help, but if you do turn it in, please make sure it works completely
  • There is no extra credit on this assignment

A good source of information for completing this homework would be to look in your old completed homework or in the book.

Overview

http://en.wikipedia.org/wiki/Yahtzee

In this assignment, you will be programming a small part of the popular dice game, Yahtzee.

In the game, players roll 5 dice and make poker-like combinations out of them in order to rack up certain point values.

Specifically, we will be making a YahtzeeHand class which contains an array of 5 numbers and 3 different methods which check to see if you have rolled certain hands.

While there are many more combination of dice, you only need to check for these 3:

  • Yahtzee – the same as 5 of a kind (all 5 dice have the same value)
  • Straight – the dice are all in order (ie, 1,2,3,4,5 OR 2,3,4,5,6)
  • Four of a Kind – 4 of the dice have the same value, we don’t care about the 5th^ die

All of the following methods should be INSIDE of the YahtzeeHand

Class.

Part 1: init method

In this method, you need to take in 5 integer values between 1 and 6 inclusive. You may assume you will always have valid input and you do not need to check.

  • First, create an empty array called dice inside of the class (remember to use self).
  • Then append the dice array with all 5 parameters.
  • Finally, sort the array using the build in sort function. Since we do not care about the order of the dice, it doesn’t matter if we reorder them in the array. Sorting the dice is VERY IMPORTANT as it makes the next 3 functions much easier to write. If you do not remember to sort the values, you will have a very hard time with the rest of this assignment.

Part 2: str method

This is a simple method that returns a string representation of the YatzheeHand object. It should be a 5 digit number with no spaces.

Don’t overthink this method – it should only be 1-2 lines. Hint: Remember to use str as needed on the dice array to get strings.

Part 3: isYahtzee method

Return true if all of the dice have the same value; else return false.

Part 4: isStraight method

Return true if we have all 5 dice in a row; else return false. Hint: remember, since we sorted the dice, the only 2 possible combinations are : 1,2,3,4,5 OR 2,3,4,5,

Part 5: isFourOfAKind method

Return true if we have AT least 4 dice that are all the same (ie. All Yatzhees are automatically 4 of a kinds); else returns false.

Hint: remember that the dice are all sorted, so the 4 dice that are the same would need to be contiguous.

Sample Seeds

Here is output with debug mode off: If you are not getting the correct answers, try turning debug mode on and looking at each row of data to see where you are miscounting.

================================ RESTART ================================

Please enter seed: 8 Enter 1 for debug mode, 0 for no extra output: Yahtzees: 1 Straights: 30 Four of a Kinds:

================================ RESTART ================================

Please enter seed: 19 Enter 1 for debug mode, 0 for no extra output: Yahtzees: 5 Straights: 25 Four of a Kinds:

================================ RESTART ================================

Please enter seed: 28 Enter 1 for debug mode, 0 for no extra output: Yahtzees: 2 Straights: 27 Four of a Kinds:

================================ RESTART ================================

Please enter seed: 991 Enter 1 for debug mode, 0 for no extra output: Yahtzees: 0 Straights: 41 Four of a Kinds:

================================ RESTART ================================

Please enter seed: 677 Enter 1 for debug mode, 0 for no extra output: Yahtzees: 1 Straights: 29 Four of a Kinds:

================================ RESTART ================================

Please enter seed: 314 Enter 1 for debug mode, 0 for no extra output: Yahtzees: 1 Straights: 43 Four of a Kinds:

================================ RESTART ================================

Please enter seed: 574 Enter 1 for debug mode, 0 for no extra output: Yahtzees: 1 Straights: 35 Four of a Kinds:

================================ RESTART ================================

Please enter seed: 271 Enter 1 for debug mode, 0 for no extra output: Yahtzees: 3 Straights: 25 Four of a Kinds:

Final thoughts

Once again, please be sure your program works perfectly before turning it in. Since it is due during dead week, we are trying to get it graded extremely quickly and it is much easier for us to give you full credit than to find out what you did wrong.

Good Luck!

Written by Joshua Silver, Fall 2006