Section 5.5 Application: The Card Game of War. 5.5 Application: The Card Game of War A deck of cards is shuffled and dealt to two players The players.

Slides:



Advertisements
Similar presentations
1 CSC 222: Computer Programming II Spring 2004 HW1 review arrays vs. vectors class design object-oriented design data objects + functionality example:
Advertisements

Victory in the Card Game ‘War’ and Initial Hand Strength
Topics in Python Blackjack & TKinter
C9, a case study: Solitaire
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Example - The.
It’s All in the Cards Adding and Subtracting Integers
Top-Down Design CSC 161: The Art of Programming Prof. Henry Kautz 9/16/2009.
Rules for Classroom Play. Setup 1. Remove blue ACTION cards from the Observatory deck 2. Shuffle both decks well and set Volcano deck to one side 3. Deal.
Rational Agents for the Card Game “BS” Jeff Reilly, Brian Munce, Stephen Tanguis, Alex Keeler.
Matlab tutorial course Exercises 4:. Exercises – for loops Download the scripts loops_example.m and if_else_example.m, run the code Download the function,
12 Pontoon1May Pontoon program CE : Fundamental Programming Techniques.
Design Example. Requirements Make a program that simulates the game of blackjack For now, we ignore money/betting…. just simulate game play But… this.
Pippin’s Garden Problem There are many solutions depending how efficient you want to be. Generate all possible locations (x,y) for the lower left corner,
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Examples.
Mau Mau (mow- mow) A card game
o Simulate a deck of playing cards o Shuffle the deck o Deal (5) cards into the hand o Turn over the first card o The user must guess whether the next.
o Simulate a deck of playing cards o Shuffle the deck o Deal 5 cards into the hand o Turn over the first card o The user must guess whether the next card.
VOCABULARY  Deck or pack  Suit  Hearts  Clubs  Diamonds  Spades  Dealer  Shuffle  Pick up  Rank  Draw  Set  Joker  Jack 
Black Jack Dr. Bernard Chen University of Central Arkansas Spring 2012.
FINDING COMPARISONS, FACTOR PAIRS AND PRIMES Through 3 Math Card Games.
April 2009 BEATING BLACKJACK CARD COUNTING FEASIBILITY ANALYSIS THROUGH SIMULATION.
CS161 Topic #15 1 Today in CS161 Lecture #15 Practicing! Writing Programs to Practice Write a game program (1 player) of Mad Math Reuse the functions to.
Putting together a complete system Chapter 10. Overview  Design a modest but complete system  A collection of objects work together to solve a problem.
Catch the Spirit of Mathematical Practices Mathematics Investigations Q-Cards: Rational Numbers The Q-Card game has 8 starter cards, 28 playing cards,
Section 3.1: Proof Strategy Now that we have a fair amount of experience with proofs, we will start to prove more difficult theorems. Our experience so.
Learning to Play KardKuro Goals: Have Fun while Practicing Addition and Subtraction. Improve Social Learning Opportunities with Classmates. Become familiar.
World Religions Tabulate Game. wild cards wild cards ordinary cards.
Chapter 5 Array-Based Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
In the Kitchen Use recipes for fractions How much is 1,1/2, ¼ cup? How many ¼ are in a cup? Let your student measure the ingredients. Double the recipe/half.
Chapter 5 Array-Based Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Week 8 : User-Defined Objects (Simple Blackjack Game)
Chapter 5 The Queue ADT. Chapter 5: The Queue ADT 5.1 – Queues 5.2 – Formal Specification 5.3 – Array-Based Implementations 5.4 – Application: Palindromes.
Chomp. How is the game played Human player goes first choose a square, all to the right and down are “eaten” computer takes a turn whoever is forced to.
More on Logic Today we look at the for loop and then put all of this together to look at some more complex forms of logic that a program will need The.
Computer Science Up Down Controls, Decisions and Random Numbers.
Math Parent Involvement Workshop November 11, :45 a.m. – 8:30 a.m. Second Grade.
Arrangements and Selections (and how they may be counted)
AP Java Elevens Lab.
A game of precision, quick reaction and observation.
Lecture 11.
Chapter 5 Black Jack.
6.NS.5 Integer War You will need: deck of cards
Volume: Working Backwards
Dot Cards Face-Off Game
Probability of casino games
A R R A Y ! for Multiplication!!
Bubble, Selection & Insertion sort
The Game: Attack and Defend
Pre-K and Kindergarten
Truth tables: Ways to organize results of Boolean expressions.
Let’s Practice Play 2 Missing Digits !
Pedro Freitas MathsJam 2017
Engaging children in exciting and engaging mental maths homework.
Truth tables: Ways to organize results of Boolean expressions.
Games Workshop.
1st/2nd Grade Math Games Family Math Night.
3rd/4th grade Family Math Night Games
Created by Meredith Roe Virtual School Program Manager,
Components 96 Pig cards How are they different?
Paradise Magic League: Rules and Regulations
Truth tables: Ways to organize results of Boolean expressions.
Task 2 Implementation help
Vocab-Rummy A card game with: Could be used for:
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Counting and Probability
Matlab tutorial course
A R R A Y ! for Multiplication!!
Decision Statements.
Agenda Warmup Lesson 1.9 (random #s, Boolean variables, etc)
Whose is it? Game.
Presentation transcript:

Section 5.5 Application: The Card Game of War

5.5 Application: The Card Game of War A deck of cards is shuffled and dealt to two players The players repeatedly battle with their cards –A battle consists of each player placing the top card from their hand, face up, on the table. –Whoever has the higher of the two cards wins the cards –A tied battle means war! In a war –Each player adds three more cards to the prize pile, and then turns up another battle card. –Whoever wins this battle wins the entire prize pile –If that battle is also a tie then there is another war … The card game continues until one of the players runs out of cards, either during a regular battle or during a war. That player loses.

Our War Program Simulates several games of war and tells us, on average, how many battles are waged in each game Models player’s hands and the prize pile as queues Simulates the game by coordinating the dequeing and enqueing operations among the two hands and the prize pile according to the rules Requires two input values - the number of games to simulate and the maximum number of battles allowed before a game is discontinued Output from the program consists of –the number of discontinued games –the number of completed games –the average number of battles waged in completed games

The RankCardDeck Class To help solve our problem we create a class called RankCardDeck, that models a deck of cards Since we are only interested in card “ranks” we do not model suits Three methods are exported –shuffle – randomizes card order –hasMoreCards – returns a boolean –nextCard – returns an int

The WarGame Class To help solve our problem we create another class called WarGame, that simulates a game of War The constructor requires an argument indicating the maximum number of battles to allow before discontinuing the game The class exports two methods –play that simulates a game until it is finished or discontinued, returning true if the game finished normally and false if the game was discontinued –getNumBattles that returns the number of battles waged in the most recent game

The play method Creates three queues –player1’s hand –player2’s hand –the prize pile of cards shuffles the deck of cards and "deals" them repeatedly calls a battle method, which enacts the battle between the two players, until the game is over or discontinued the battle method is recursive – do you see why?

The battle method battle() Get player1's card from player1's hand Put player1's card in the prize pile Get player2's card from player2's hand Put player2's card in the prize pile if (player1's card > player2's card) { remove all the cards from the prize pile and put them in player1's hand } else if (player2's card > player1's card) { remove all the cards from the prize pile and put them in player2's hand } else // war! { each player puts three cards in the prize pile battle() }

Code and Demo Instructors can now walk through the code contained in RankCardDeck.java, WarGame.java and WarGameApp.java, review the programming notes from the chapter, and demonstrate the running program.

Program Architecture