HW4: The Game of Pig Due date: Tuesday, Mar 15 th at 9pm. Late turn-in deadline is Thursday, Mar 17th at 9pm.

Similar documents
HW4: The Game of Pig Due date: Thursday, Oct. 29 th at 9pm. Late turn-in deadline is Tuesday, Nov. 3 rd at 9pm.

Begin this assignment by first creating a new Java Project called Assignment 5.There is only one part to this assignment.

Project 1: A Game of Greed

CPSC 217 Assignment 3 Due Date: Friday March 30, 2018 at 11:59pm

Homework Assignment #2

Homework 7: Subsets Due: 10:00 PM, Oct 24, 2017

Lab Exercise #10. Assignment Overview

Smyth County Public Schools 2017 Computer Science Competition Coding Problems

CS1802 Week 9: Probability, Expectation, Entropy

Multiplication & Division

CSE231 Spring Updated 04/09/2019 Project 10: Basra - A Fishing Card Game

CPSC 217 Assignment 3

The Game of Hog. Scott Lee

Mathematical Talk. Fun and Games! COUNT ON US MATHS CLUB ACTIVITIES SESSION. Key Stage 2. Resources. Hints and Tips

CSC/MTH 231 Discrete Structures II Spring, Homework 5

CS 371M. Homework 2: Risk. All submissions should be done via git. Refer to the git setup, and submission documents for the correct procedure.

CS151 - Assignment 2 Mancala Due: Tuesday March 5 at the beginning of class

CS Programming Project 1

Section Summary. Finite Probability Probabilities of Complements and Unions of Events Probabilistic Reasoning

Programming Languages and Techniques Homework 3

COSC 117 Programming Project 2 Page 1 of 6

CSci 1113: Introduction to C/C++ Programming for Scientists and Engineers Homework 2 Spring 2018

Homework 5 Due April 28, 2017

CMPT 125/128 with Dr. Fraser. Assignment 3

Presentation by Toy Designers: Max Ashley

class TicTacToe: def init (self): # board is a list of 10 strings representing the board(ignore index 0) self.board = [" "]*10 self.

Assignment 1. Due: 2:00pm, Monday 14th November 2016 This assignment counts for 25% of your final grade.

Project Connect Four (Version 1.1)

Instructions [CT+PT Treatment]

Assignment 5: Yahtzee! TM

Assignment 6 Play A Game: Minesweeper or Battleship!!! Due: Sunday, December 3rd, :59pm

STAT 311 (Spring 2016) Worksheet: W3W: Independence due: Mon. 2/1

Ok, we need the computer to generate random numbers. Just add this code inside your main method so you have this:

Descriptive Writing Mentor Project

ICONIP 2009 Intelligent Liar Competition: Liar Dice (Individual Hand)

Math 1313 Section 6.2 Definition of Probability

Optimal Yahtzee performance in multi-player games

Write algorithms with variables. Phil Bagge code-it

Question Description

Materials: Game board, dice (preferable one 10 sided die), 2 sets of colored game board markers.

Probability A = {(1,4), (2,3), (3,2), (4,1)},

Roll for the Tournament -Jousting

To use one-dimensional arrays and implement a collection class.

COMP 9 Lab 3: Blackjack revisited

Part II: Number Guessing Game Part 2. Lab Guessing Game version 2.0

Ace of diamonds. Graphing worksheet

CS 540-2: Introduction to Artificial Intelligence Homework Assignment #2. Assigned: Monday, February 6 Due: Saturday, February 18

G51PGP: Software Paradigms. Object Oriented Coursework 4

CS106X Handout 13 Winter 2018 January 24 th, 2018 Assignment 3: Boggle

Unit 5: What s in a List

An Adaptive-Learning Analysis of the Dice Game Hog Rounds

2359 (i.e. 11:59:00 pm) on 4/16/18 via Blackboard

CS Project 1 Fall 2017

Simulations. 1 The Concept

Assignment #5 Yahtzee! Due: 3:15pm on Wednesday, November 14th

Statistics Laboratory 7

6.041/6.431 Spring 2009 Quiz 1 Wednesday, March 11, 7:30-9:30 PM.

Math 10 Homework 2 ANSWER KEY. Name: Lecturer: Instructions

Homework Week #16 Due January 24, 2019 Grade 2 TLC

If event A is more likely than event B, then the probability of event A is higher than the probability of event B.

Final Project Due August 4, 2017

CS1301 Individual Homework 5 Olympics Due Monday March 7 th, 2016 before 11:55pm Out of 100 Points

CIDM 2315 Final Project: Hunt the Wumpus

Lab 11: GoFirst and Nim 12:00 PM, Nov 19, 2017

Mini Project #2: Motion Planning and Generation for a Robot Arm

Solutions for the Practice Final

Basic Probability Ideas. Experiment - a situation involving chance or probability that leads to results called outcomes.

Programming Assignment 4

Section 6.1 #16. Question: What is the probability that a five-card poker hand contains a flush, that is, five cards of the same suit?

Sheepshead, THE Game Set Up

Programming Problems 14 th Annual Computer Science Programming Contest

MA 110 Homework 1 ANSWERS

Mighty Planetary Empires

CS107L Handout 06 Autumn 2007 November 2, 2007 CS107L Assignment: Blackjack

Probability. March 06, J. Boulton MDM 4U1. P(A) = n(a) n(s) Introductory Probability

CMSC 201 Fall 2018 Project 3 Sudoku

settinga.html & setcookiesa.php

03/05/14 20:47:19 readme

Problem 4.R1: Best Range

A Rule-Based Learning Poker Player

the gamedesigninitiative at cornell university Lecture 6 Uncertainty & Risk

PROBLEM SET 2 Due: Friday, September 28. Reading: CLRS Chapter 5 & Appendix C; CLR Sections 6.1, 6.2, 6.3, & 6.6;

SHUFFLING INTO MATH JANE FELLING. Box Cars and One-Eyed Jacks RSA ILLINOIS. Day Presenting: Tuesday Room: Marsalis 2 Time: 10:45-11:45

CSE 231 Spring 2013 Programming Project 03

First Name: Last Name: Lab Cover Page. Teaching Assistant to whom you are submitting

CSCI 2200 Foundations of Computer Science (FoCS) Solutions for Homework 7

Beeches Holiday Lets Games Manual

The Common Application

Computing Science (CMPUT) 496

Project 2 - Blackjack Due 7/1/12 by Midnight

1. An office building contains 27 floors and has 37 offices on each floor. How many offices are in the building?

CSC242 Intro to AI Spring 2012 Project 2: Knowledge and Reasoning Handed out: Thu Mar 1 Due: Wed Mar 21 11:59pm

This assignment is worth 75 points and is due on the crashwhite.polytechnic.org server at 23:59:59 on the date given in class.

Introduction to Artificial Intelligence CS 151 Programming Assignment 2 Mancala!! Due (in dropbox) Tuesday, September 23, 9:34am

For slightly more detailed instructions on how to play, visit:

Documentation and Discussion

Addition and Subtraction with Rational Numbers

Name. Is the game fair or not? Prove your answer with math. If the game is fair, play it 36 times and record the results.

BOOM! subtract 15. add 3. multiply by 10% round to. nearest integer. START: multiply by 2. multiply by 4. subtract 35. divide by 2

Up & Down GOAL OF THE GAME UP&DOWN CARD A GAME BY JENS MERKL & JEAN-CLAUDE PELLIN ART BY CAMILLE CHAUSSY

Transcription:

HW4: The Game of Pig Due date: Tuesday, Mar 15 th at 9pm. Late turn-in deadline is Thursday, Mar 17th at 9pm. 1. Background: Pig is a folk jeopardy dice game described by John Scarne in 1945, and was an ancestor of the modern game Pass the Pigs (originally called PigMania ). The rules are simple: Two players race to reach 100 points. Each turn, a player repeatedly rolls a standard die until either a 1 is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn, the player is faced with two decisions: a) roll - If the player rolls a 1: the player scores nothing and it becomes the opponent's turn. 2-6: the number is added to the player's turn total and the player's turn continues. b) hold - The turn total is added to the player's score and it becomes the opponent's turn. To familiarize yourself with play, you can play an optimal Pig opponent online. The key decision facing a player is how large a turn total should be risked to possibly get an even larger total. In this homework assignment, you will be writing a relatively aggressive (although somewhat naïve) algorithm. In this homework, once an automated player reaches a turn total of 20 or more, they will hold. Otherwise, they will continue rolling. 2. Assignment: By the end of this homework, you should be able to simulate a 2 player game of Pig. But we'll break it up into pieces (methods) which you can work on individually. In Section 3, there is a listing of methods to write. You MUST write these in order, as some methods will need to invoke other methods. Name your file HW4.java. 3. Methods to implement: a) roll: this method should return a random integer, 1-6 inclusive. You have already written this method for a previous lab, and you are free to use that method. b) holdat20: This method should mimic a single turn of Pig where the player rolls until a 1 is rolled or until the turn total is greater than or equal to 20 input parameter(s): none return value: an integer value representing the number of points the player scored on this turn (ie, their turn total). output: your method should print the value of each roll the player takes. When the player's turn is over, the method should print out the total points scored. Examples: holdat20() might generate the output:

In this case, the method should return 20 (the player's score for this turn) Another call to holdat20() might generate: In this case, the method would return 0 (the player's score for this turn) c) Once you have part b working, modify this method by adding a parameter to your holdat20 method. This parameter should be an integer and will represent the player's current score. Modify your method to immediately hold if the turn would put the player's score at 100 or greater. The method should still return the score for the current turn. Example: holdat20(90) might generate the output Turn total: 13 This call should return 13 d) holdui: This method will also simulate a single player turn, but this method will incorporate user input. Specifically, this method will ask the user whether or not to continue rolling at each step. Input parameter(s): the method takes no parameters, but it will need to use a Scanner to read user input. Make the Scanner a class variable and initialize it to read from System.in. In other words, the Scanner variable should be declared and initialized outside of any method. Return value: this method should return the turn's total score, like the holdat20 method. Output format: The output for this method would also include a prompt to the user, and a running total as the user rolls. It should also include roll values, same as holdat20. Example of a single call to holdui. User input is in blue. Turn total: 2 (1 to Roll, 2 to Hold): 1 Turn total: 4 (1 to Roll, 2 to Hold): 1

Turn total: 8 (1 to Roll, 2 to Hold): 1 Turn total: 24 (1 to Roll, 2 to Hold): 2 Turn total: 24 In this example, the method should return 24 (total score of turn) The user should make ALL decisions. In other words, the player can continue rolling as many times as they would like, and they can hold whenever they would like. They should also be able to continue rolling even if their current turn total would surpass 100 points. e) playgame: This method should implement a 2-player game of Pig where the user plays against a computer player that always rolls until a 1 ("pig") is rolled, or the turn total is greater than or equal to 20, or the score plus the turn total is greater than or equal to 100 (ie, the behavior implemented in holdat20). The human player can make a decision when to roll or hold (ie, the behavior implemented in holdui). The first player is chosen randomly. Input parameter(s): One String, which is the human player's name/identifier. Return value: this method has no return value Output format: Before the game, randomly select which player the user will be, and print the line "[Computer or User's name], you will be player #.", where # is the user's player number: either 1 or 2. Before each turn, print a line with "Player 1 score: " and player 1's score. Print another line with "Player 2 score: " and player 2's score. Finally, print a line with "It is player #'s turn.", where "#" is replaced by the current player number. Play starts with player 1 and then alternates. After a "pig" roll of 1, or a "hold", print a line with "Turn total: " followed by the turn total. In the case of a "pig", this turn total is 0. Then, print a line with "New score: " followed by the new score for the current player. When the game ends (ie when one player reaches 100 points), you should print out a message indicating the game is over and which player won. Example game (long!), invoked with playgame( Valerie ) Valerie, you will be player 2. Player 2 score: 0 New score: 0 Player 2 score: 0

Turn total: 11 (1 to Roll, 2 to Hold): 1 Turn total: 17 (1 to Roll, 2 to Hold): 1 Turn total: 21 (1 to Roll, 2 to Hold): 2 Turn total: 21 New score: 21 Player 2 score: 21 New score: 0 Player 2 score: 21 Turn total: 12 (1 to Roll, 2 to Hold): 1 Turn total: 14 (1 to Roll, 2 to Hold): 1 (1 to Roll, 2 to Hold): 2 New score: 41 Player 2 score: 41 Player 2 score: 41 Turn total: 3 (1 to Roll, 2 to Hold): 1 Turn total: 8 (1 to Roll, 2 to Hold): 1 Turn total: 14 (1 to Roll, 2 to Hold): 1 Turn total: 16 (1 to Roll, 2 to Hold): 1 (1 to Roll, 2 to Hold): 2 New score: 61 Player 2 score: 61 Player 2 score: 61

Turn total: 3 (1 to Roll, 2 to Hold): 1 Turn total: 11 (1 to Roll, 2 to Hold): 1 Turn total: 19 (1 to Roll, 2 to Hold): 2 Turn total: 19 New score: 80 Player 2 score: 80 Player 2 score: 80 Turn total: 2 (1 to Roll, 2 to Hold): 1 Turn total: 4 (1 to Roll, 2 to Hold): 1 Turn total: 8 (1 to Roll, 2 to Hold): 1 Turn total: 24 (1 to Roll, 2 to Hold): 2 Turn total: 24 New score: 104 Game over!!! Valerie wins! The score was 104-20 4. Hints and Tips: a) Consider using boolean flags in this assignment. It can be easier to set a boolean flag like computergoesfirst to true or false (based on a random number) and then base decisions about what to print on that variable later in your program. Likewise, keep track of whose turn it is with a flag like computersturn which can alternately be set to true or false as a turn ends. b) Although it's tempting, avoid using class variables to keep track of players' scores in this assignment. Trust me, they are quite confusing to keep track of. 5. Submission: a) Don't forget your Name, userid, section number, and collaboration statement as comments at the top of your file. b) You may submit as many times as you want, but we only grade the last submission. c) Submit your.java file (not your.class file!) to the HW4 assignment on BB. d) Due date is Tuesday, Mar. 15 th at 9pm. Late turn-in deadline is Thursday, Mar. 19th at 9pm.