Programming Languages and Techniques Homework 3

Similar documents
Lab Exercise #10. Assignment Overview

COMPONENTS. The Dreamworld board. The Dreamshards and their shardbag

relates to Racko and the rules of the game.

Project 1: A Game of Greed

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

CS Programming Project 1

ECE2049: Foundations of Embedded Systems Lab Exercise #1 C Term 2018 Implementing a Black Jack game

Acing Math (One Deck At A Time!): A Collection of Math Games. Table of Contents

PHASE 10 CARD GAME Copyright 1982 by Kenneth R. Johnson

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

3. If you can t make the sum with your cards, you must draw one card. 4. Players take turns rolling and discarding cards.

Corners! How To Play - a Comprehensive Guide. Written by Peter V. Costescu RPClasses.com

MITOCW watch?v=-qcpo_dwjk4

CMPT 310 Assignment 1

CS Project 1 Fall 2017

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

Chapter 2 Integers. Math 20 Activity Packet Page 1

Checkpoint Questions Due Monday, October 7 at 2:15 PM Remaining Questions Due Friday, October 11 at 2:15 PM

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

Economics 101 Spring 2015 Answers to Homework #1 Due Thursday, February 5, 2015

Teaching the TERNARY BASE

* Rules are not final and subject to change *

Comprehensive Rules Document v1.1

The student will explain and evaluate the financial impact and consequences of gambling.

Bible Battles Trading Card Game OFFICIAL RULES. Copyright 2009 Bible Battles Trading Card Game

CSE 231 Fall 2012 Programming Project 8

Kenken For Teachers. Tom Davis January 8, Abstract

CMS.608 / CMS.864 Game Design Spring 2008

Setup. These rules are for three, four, or five players. A two-player variant is described at the end of this rulebook.

Problem Set 10 2 E = 3 F

Mage Tower Rulebook Ver 0.1

Session 5 Variation About the Mean

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

Alberta 55 plus Cribbage Rules

NOTES ON SEPT 13-18, 2012

Stand in Your Creative Power

CMS.608 / CMS.864 Game Design Spring 2008

HEY! DON T READ THESE RULES!

Activity 6: Playing Elevens

Eleventh Annual Ohio Wesleyan University Programming Contest April 1, 2017 Rules: 1. There are six questions to be completed in four hours. 2.

For this assignment, your job is to create a program that plays (a simplified version of) blackjack. Name your program blackjack.py.

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

Only and are worth points. The point value of and is printed at the bottom of the card.

Free Cell Solver. Copyright 2001 Kevin Atkinson Shari Holstege December 11, 2001

37 Game Theory. Bebe b1 b2 b3. a Abe a a A Two-Person Zero-Sum Game

CSSE220 BomberMan programming assignment Team Project

January 11, 2017 Administrative notes

FOURTH LECTURE : SEPTEMBER 18, 2014

School Based Projects

Contents. 12 Award cards 4 Player Aid cards 8 Attraction mats 4 Equipment tiles 15 Player markers (tractors) in 5 colors

CONTENTS. 1. Number of Players. 2. General. 3. Ending the Game. FF-TCG Comprehensive Rules ver.1.0 Last Update: 22/11/2017

Situations Involving Multiplication and Division with Products to 50

UNIVERSITY of PENNSYLVANIA CIS 391/521: Fundamentals of AI Midterm 1, Spring 2010

Homework Assignment #1

AGES PLAYERS. Game Guide

CS 787: Advanced Algorithms Homework 1

Phase 10 Masters Edition Copyright 2000 Kenneth R. Johnson For 2 to 4 Players

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

Roommate & Room Selection Process

CRISS-CROSS POKER. Community cards Cards which are used by all players to form a five-card Poker hand.

Laboratory 1: Uncertainty Analysis

Probability Paradoxes

Probability Homework Pack 1

The Exciting World of Bridge

Composing and Decomposing Whole Numbers to 20

ECE 302 Homework Assignment 2 Solutions

Check out the Weapons. One of these powerful Weapons was used to render the Doctor unconscious for the kidnapping. You must find out which one.

CS 210 Fundamentals of Programming I Fall 2015 Programming Project 8

When placed on Towers, Player Marker L-Hexes show ownership of that Tower and indicate the Level of that Tower. At Level 1, orient the L-Hex

122 Taking Shape: Activities to Develop Geometric and Spatial Thinking, Grades K 2 P

Advanced Strategy in Spades

A Games-based, Strategy-focused Fluency Plan

Red Dragon Inn Tournament Rules

Presents: Basic Card Play in Bridge

Assignment II: Set. Objective. Materials

(3 to 6 players) Lie, cheat steal and backstab your way to victory on your quest to become the next President of the United States.

Crapaud/Crapette. A competitive patience game for two players

18.S34 (FALL, 2007) PROBLEMS ON PROBABILITY

Tic-tac-toe. Lars-Henrik Eriksson. Functional Programming 1. Original presentation by Tjark Weber. Lars-Henrik Eriksson (UU) Tic-tac-toe 1 / 23

Escape the Nightmare

Here are two situations involving chance:

Analyzing Games: Solutions

Game Background. Components

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

Due: Sunday 13 November by 10:59pm Worth: 8%

Cards Against Inanity

GorbyX Rummy is a unique variation of Rummy card games using the invented five suited

Poker Rules Friday Night Poker Club

Robot Factory Rulebook

Components. Loading dock 1. Loading dock 2. Loading dock 3. 7 shift tokens 5 action cards: 3 mining action cards

CMPT 310 Assignment 1

Health in Action Project

Inheritance Inheritance

Grade 6 Math Circles March 8-9, Modular Arithmetic

Grade 7/8 Math Circles Game Theory October 27/28, 2015

HAND & FOOT CARD GAME RULES

From Trading Up Game Teacher's guide, by H. B. Von Dohlen, 2001, Austin, TX: PRO-ED. Copyright 2001 by PRO-ED, Inc. Introduction

Mah Jongg FAQs. Answers to Frequently Asked Questions with hints. Q. How do we exchange seats when we are playing a four-player game?

Make better decisions. Learn the rules of the game before you play.

Taffy Tangle. cpsc 231 assignment #5. Due Dates

Transcription:

Programming Languages and Techniques Homework 3 Due as per deadline on canvas This homework deals with the following topics * lists * being creative in creating a game strategy (aka having fun) General Idea This assignment is mainly intended to get you to practice list modifications We will be implementing the old game Racko which is a game that involves rearranging your hand of cards in order to have an increasing (some people go decreasing) sequence. While Racko is typically played with 2 to 4 players, we will keep this simple and just play the user versus the computer. The user s moves are decided by the user by asking for input, the computer s moves are decided by you the programmers! What that means is that there is NO right answer for the section that asks you to program a strategy for the computer. All we want you to do is come up with some reasonable enough strategy that ensures that a human user does not consistently beat the computer. So unlike your previous assignments, this one has a creative component to it as well. Rules of the game A Racko deck is composed of 60 cards, each numbered 1 to 60. The objective is to be the first player to arrange all of the cards in your rack from lowest to highest. To start the game, shuffle the deck, both the user and the computer pick a card from the deck. Let the computer pick first. The person who gets to play first is the person who has the higher number. The cards then get shuffled again and both the user and the computer gets dealt 10 cards. As a player receives each card, he must place it in the highest available slot in his rack, starting at slot 10, without rearranging any of them. The goal of each hand is to create a sequence of numbers in ascending order, starting at slot 1. The top card of the deck is turned over to start the discard pile. A player takes a turn by taking the top card from either the deck or the discard pile, then discarding one from his rack and inserting the new card in its place. If the player draws a card from the deck, he may immediately discard it; if he takes the top discard, though, he must put it into his rack. 1

The first player to get his 10 cards in ascending order calls Rack-O! and wins the hand. While I do not have a link to an online Racko game, there is a very similar game (with little Vikings!) over here tower blaster We also have the actual game with us (assuming I did not forget to bring it with me to recitation) and are more than happy to pass it around in class for you to get a feel for what the game is like. Finally here is just a random picture of the game to remind yourself what it looks like (you can also stop by my office to take another look). The actual program Once again we provide you with stubs of functions. But this time around there is less guidance as to what exactly you need to put in them. Here are the functions that need to be written. We are expecting to see these functions with these names and these method signatures. Note that we will make heavy use of lists in the assignment. Since a rack looks more like a vertically oriented structure, we need to have some convention. Our convention is that lst = [3, 17, 11, 30, 33, 38, 49, 46, 25, 53] is actually the following rack from slots 10 down to 1 3 17 11 30 33 38 49 46 25 53 So yes, this particular rack is a long way from a victory. We know this is a somewhat awkward way to representing the data, but we are deliberately asking you to do it this way in order for you to do more list exercises. The deck and discard are also going to be represented as lists. Note that in both the deck and the discard pile, you only have access to the top. If you take a card from the pile, you need to call the pop function. If you add a card to a pile you call the append function. shuffle(cardstack) - shuffle the deck to start the game. Also shuffle the discard pile if we ever run out of cards and need to restart the game. This function does not return anything. You can import the random module and just use random.shuffle. 2

check racko(rack) - given a rack (this will be either the user s or the computer s) determine if Racko has been achieved. Remember that Racko means that the cards are in ascending order. This function returns a boolean value. get top card(card stack) - get the top card from any stack of cards. Used at the start of game play for dealing cards. This same function will also be used during each player s turn to take the top card from either the discard pile or from the deck. This function must return an integer. deal initial hands(deck) - start the game off by dealing two hands of 10 cards each. This function returns two lists - one representing the user s hand and the other representing the computer s hand. Make sure that you follow normal card game conventions of dealing. So programatically you have to deal one card to the user, one to the computer, one to the user, one to the computer and so on. The computer is always the first person that gets dealt to. The user always plays first. Remember that the rules of our version of Racko will be that you have to place your cards in the order of top most slot of the rack first, then the next slot and so on. In the example above, this would mean that someone was dealt the cards 3, 17, 11, 30, 33,... in that order. The method of returning 2 things from a function is to make a tuple out of the return values. For example, the following piece of code returns the sum and the maximum in a list. Note that a tuple is slightly different from a list. We will explain this in more detail in next lecture. def get_sum_and_max(lst): return (sum(lst), max(lst)) def main(): sum_and_max = get_sum_and_max(range(1, 10)) print "max is", sum_and_max[1] print "sum is", sum_and_max[0] print top to bottom(rack) - given a rack(represented as a list) print it out from top to bottom in a manner that looks more akin to the game (more stack like than list like). See the example above for the exact specification. Please stick to that specification in terms of the representation of the rack. 3

find and replace(new card, card to be replaced, hand, discard) - find the card to be replaced (represented by a number) in the hand and replace it with newcard. The replaced card then gets put on top of the discard. Check and make sure that the cardtobereplaced is truly a card in the hand. If the user accidentally typed a card number incorrectly, just politely remind them to try again and leave the hand unchanged. add card to discard(card, discard) - add the card(represented as just an integer) to the top of the discard pile. computer play(hand, deck, discard pile) - This function is where you can write the computer s strategy down. It is also the function where we are giving you very little guidance in terms of actual code. You are supposed to be somewhat creative here, but I do want your code to be deterministic. That is, given a particular rack and a particular card (either from the discard pile or as the top card of the deck), you either always take the card or always reject it. Here are some potential decisions the computer has to make 1. Given the computer s current hand, do you want to take the top card on the discard or do you want to take the top card from the deck and see if that card is useful to you. 2. How do you evaluate the usefulness of a card and which position it should go into. 3. There might be some simple rules you can give the computer. For instance, it is disastrous to put something like a 5 in the top slot. You want big numbers over there. You are allowed to do pretty much anything in this function except make a random decision or make a decision that is obviously incorrect. For instance, making your bottom card a 60 is a recipe for disaster. Also, the computer CANNOT CHEAT. What does that mean? The computer cannot peek at the top card of the deck and then make a decision of going to the discard. It s decision making should be something that a human should be able to make as well. This function has to return the new hand for the computer. main() - a function that puts it all together. You play until someone gets Racko. We have a basic structure for main() in the next page. We deliberately have not written real code. The intent is that you fill in the required pieces of code once you understand our comments. You do not have to adhere to this structure of main(). You can use your own design as long as you stick to the rules of the game. 4

def main ( ) : #c r e a t e a l i s t o f i n t e g e r s t h a t r e p r e s e n t s a deck #c r e a t e an empty d i s c a r d p i l e s h u f f l e ( deck ) hands = d e a l i n i t i a l h a n d s ( deck ) #hands i s a t u p l e. #a s s i g n one element of t h i s t u p l e as the user s hand #a s s i g n the o t h e r element of the t u p l e as computer s hand p r i n t t o p t o b o t t o m ( human hand ) #r e v e a l one card to begin the d i s c a r d p i l e while n e i t h e r the computer nor the user has racko : computer hand = computer play ( computer hand, deck, d i s c a r d ) #ask the user i f they want t h i s card #p r i n t the user s hand i f user chooses t h i s card : #ask the user f o r the card ( number ) they want to k i c k out #modify the user s hand and the d i s c a r d p i l e #p r i n t the user s hand e l i f c h o i c e == n : card = deck. pop ( ) #p r i n t t h i s card to show the user what they got #ask the user i f they want t h i s secondchoice = raw input ( keep i t?\n ) i f secondchoice == y : #modify user s hand and d i s c a r d p i l e # p r i n t user s hand else : d i s c a r d. append ( card ) #p r i n t the user s hand #check and make sure t h e r e are s t i l l some cards in the deck #e l s e r e s h u f f l e the d i s c a r d and r e s t a r t. Evaluation The primary goal of this assignment is to get you to feel familiar with lists and to have some level of fun while creating a game. While we want you to spend time on coming up with some kind of strategy for the computer, that is NOT the primary part of the assignment. Come up with something reasonable. Any reasonable strategy will have you doing some fun things with lists. If the user always does absolutely nothing at all, that is, they reject the discard card and they reject the top card from the deck and move it onto the discard, then we want the computer 5

to beat the user. Your computer should have enough intelligence to beat the stupid and lazy user. Also, remember the user has no idea what you are doing internally in your functions and does not want to be shown a large amount of print statements. At any given point in the game, they should know only 3 things - their entire hand printed in the rack form, the top card of the discard and if they choose to dive into the deck they get to know the top card of the deck. Evaluation criteria 8 points for getting the game to work. 5 points for style - variable names, function names, modularity. The modularity part basically refers to breaking down the computer strategy into smaller functions. We do not want to see one massive function that deals with the computer s strategy. 4 points for getting the specifications correct (passing all the TAs tests). As long as you follow our specifications, these tests will pass. Remember to stick to the same function names. Make sure your functions (other than the main function) do not print any extra information. Make sure your functions return the datatype that we expect you to return. 3 points for strategy - we just need you to implement a reasonable strategy. What data structures to use In this HW you are only allowed to use lists (and tuples in the one place as shown above). Please do not use dictionaries, classes or any in built python libraries. Remember that the deck, the discard pile and the two hands (user and computer) are just lists. what to submit Submit one single file called Racko.py. This is still an individual assignment. We will do groups from the next HW. Please put the following at the end. Now that you have seen it a few times, we will deduct a point if you do not have this at the end. if name == main : main() 6