Free Essay

# On the Workings of Cribbage

In:

Submitted By jflan1118
Words 1846
Pages 8
import java.util.*;

public class Cribbage {

ArrayList<Card> deck; static ArrayList<Card> myHand; static ArrayList<Card> cpuHand; ArrayList<Card> opponentHand; ArrayList<Card> myNewHand; ArrayList<Card> crib; int runFour; int runThree; int runFive;

Card cut; static Card AceOfClubs = new Card(1, 1); static Card TwoOfClubs = new Card(1, 2); Card ThreeOfClubs = new Card(1, 3); static Card FourOfClubs = new Card(1, 4); static Card FiveOfClubs = new Card(1, 5); static Card SixOfClubs = new Card(1, 6); static Card SevenOfClubs = new Card(1, 7); static Card EightOfClubs = new Card(1, 8); static Card NineOfClubs = new Card(1, 9); static Card TenOfClubs = new Card(1, 10); Card JackOfClubs = new Card(1, 11); Card QueenOfClubs = new Card(1, 12); Card KingOfClubs = new Card(1, 13);

static Card AceOfDiamonds = new Card(2, 1); Card TwoOfDiamonds = new Card(2, 2); Card ThreeOfDiamonds = new Card(2, 3); Card FourOfDiamonds = new Card(2, 4); static Card FiveOfDiamonds = new Card(2, 5); static Card SixOfDiamonds = new Card(2, 6); Card SevenOfDiamonds = new Card(2, 7); Card EightOfDiamonds = new Card(2, 8); Card NineOfDiamonds = new Card(2, 9); Card TenOfDiamonds = new Card(2, 10); Card JackOfDiamonds = new Card(2, 11); Card QueenOfDiamonds = new Card(2, 12); static Card KingOfDiamonds = new Card(2, 13);

static Card AceOfHearts = new Card(3, 1); Card TwoOfHearts = new Card(3, 2); Card ThreeOfHearts = new Card(3, 3); Card FourOfHearts = new Card(3, 4); static Card FiveOfHearts = new Card(3, 5); Card SixOfHearts = new Card(3, 6); Card SevenOfHearts = new Card(3, 7); Card EightOfHearts = new Card(3, 8); Card NineOfHearts = new Card(3, 9); Card TenOfHearts = new Card(3, 10); Card JackOfHearts = new Card(3, 11); static Card QueenOfHearts = new Card(3, 12); Card KingOfHearts = new Card(3, 13);

public static void main(String[] args) { Cribbage c = new Cribbage(); c.shuffle(); c.deal(); c.showMyHand(); c.showCpuHand(); c.weedOut(cpuHand.get(0), cpuHand.get(1), cpuHand.get(2), cpuHand.get(3), cpuHand.get(4), cpuHand.get(5)); // c.countHandOfFour(myHand.get(0), myHand.get(1), myHand.get(2), myHand.get(3)); // c.showMyHand(); // c.countHand(EightOfClubs, NineOfClubs, SixOfClubs, SevenOfClubs); // c.countHand(new Card(1,10), new Card(2,5), new Card(3,11), new // Card(4,5));

}

public void shuffle() { deck = new ArrayList<Card>(); myHand = new ArrayList<Card>(); cpuHand = new ArrayList<Card>();

}

public void showDeck() {

for (int i = 0; i < deck.size(); i++) { System.out.println(deck.get(i)); }

}

public void showMyHand() {

for (int i = 0; i < myHand.size(); i++) { System.out.println(myHand.get(i)); } } public void showMyNewHand() {

for (int i = 0; i < myNewHand.size(); i++) { System.out.println(myNewHand.get(i)); } } public void showCpuHand() {

for (int i = 0; i < cpuHand.size(); i++) { System.out.print(cpuHand.get(i)+" "); } System.out.println(""); } public void showOpponentHand() {

for (int i = 0; i < opponentHand.size(); i++) { System.out.print(opponentHand.get(i)+" "); }

} public void showCrib() {

for (int i = 0; i < crib.size(); i++) { System.out.print(crib.get(i)+" "); }

}

public void deal() { for (int i = 1; i < 7; i++) { int x = (int) (deck.size() * Math.random()); // System.out.print(deck.get(x) + " "); myHand.add(deck.get(x)); deck.remove(x);

}

// System.out.println(""); // System.out.println("");

for (int j = 1; j < 7; j++) { int x = (int) (deck.size() * Math.random()); // System.out.print(deck.get(x) + " "); cpuHand.add((Card) deck.get(x)); deck.remove(x); // weedOut(cpuHand.get(0), cpuHand.get(1), cpuHand.get(2), cpuHand.get(3), cpuHand.get(4), cpuHand.get(5)); }

// System.out.println(""); // System.out.println("");

// cardsToKitty(cpuHand.get(0), cpuHand.get(1), cpuHand.get(2), // cpuHand.get(3), cpuHand.get(4), cpuHand.get(5)); }

public int isPair(Card a, Card b) { if (a.rank == b.rank) { return 2; } else { return 0; } }

public int isFifteen(Card a, Card b) { if (a.value + b.value == 15) { return 2; } else { return 0; } }

public int isFifteen(Card a, Card b, Card c) { if (a.value + b.value + c.value == 15) { return 2; } else { return 0; } }

public int isFifteen(Card a, Card b, Card c, Card d) { if (a.value + b.value + c.value + d.value == 15) { return 2; } else { return 0; } } public int isFlush(Card a, Card b, Card c, Card d) { if (a.suit == b.suit && b.suit == c.suit && c.suit == d.suit) {return 4;} else {return 0;} } public void isRunOfFour(Card a, Card b, Card c, Card d) { sort(a.rank, b.rank, c.rank, d.rank); } public void sort(int a, int b, int c, int d) { int Hand[] = new int[]{a,b,c,d}; Arrays.sort(Hand); determineRunOfFour(Hand); } public void determineRunOfFour(int[] a) { if (a[0]+1 == a[1] && a[1]+1 == a[2] && a[2]+1 == a[3] && runFive == 0) {runFour = 4;} else {runFour = 0;} } public int runOfFourValue(Card a, Card b, Card c, Card d) { isRunOfFour(a, b, c, d); return runFour; } public void isRunOfThree(Card a, Card b, Card c) { sort(a.rank, b.rank, c.rank); } public void sort(int a, int b, int c) { int Hand[] = new int[]{a,b,c}; Arrays.sort(Hand); determineRunOfThree(Hand); } public void determineRunOfThree(int[] a) { if (a[0]+1 == a[1] && a[1]+1 == a[2] && runFour == 0 && runFive == 0) {runThree = 3;} else {runThree = 0;} } public int runOfThreeValue(Card a, Card b, Card c) { isRunOfThree(a, b, c); return runThree; }

public void isRunOfFive(Card a, Card b, Card c, Card d, Card e) { sort(a.rank, b.rank, c.rank, d.rank, e.rank); } public void sort(int a, int b, int c, int d, int e) { int Hand[] = new int[]{a,b,c,d,e}; Arrays.sort(Hand); determineRunOfFive(Hand); } public void determineRunOfFive(int[] a) { if (a[0]+1 == a[1] && a[1]+1 == a[2] && a[2]+1 == a[3] && a[3]+1 == a[4]) {runFive = 4;} else {runFive = 0;} } public int runOfFiveValue(Card a, Card b, Card c, Card d, Card e) { isRunOfFive(a, b, c, d, e); return runFive; }

public int countHandOfFour(Card a, Card b, Card c, Card d) { return(isPair(a, b) + isPair(a, c) + isPair(a, d) + isPair(b, c) + isPair(b, d) + isPair(c, d) + isFifteen(a, b) + isFifteen(a, c) + isFifteen(a, d) + isFifteen(b, c) + isFifteen(b, d) + isFifteen(c, d) + isFifteen(a, b, c) + isFifteen(a, b, d) + isFifteen(a, c, d) + isFifteen(b, c, d) + isFifteen(a, b, c, d) + isFlush(a, b, c, d) + runOfFourValue(a, b, c, d) + runOfThreeValue(a, b, c) + runOfThreeValue(a, b, d) + runOfThreeValue(a, c, d) + runOfThreeValue(b, c, d)); }

public void weedOut(Card a, Card b, Card c, Card d, Card e, Card f) { opponentHand = new ArrayList<Card>(); crib = new ArrayList<Card>(); int max = 0; Card opponent1 = null; Card opponent2 = null; Card opponent3 = null; Card opponent4 = null; Card crib1 = null; Card crib2 = null;

if (countHandOfFour(a,b,c,d) > max) {max = countHandOfFour(a,b,c,d); opponent1 = a; opponent2 = b; opponent3 = c; opponent4 = d; crib1 = e; crib2 = f; } if (countHandOfFour(a,b,c,e) > max) {max = countHandOfFour(a,b,c,e); opponent1 = a; opponent2 = b; opponent3 = c; opponent4 = e; crib1 = d; crib2 = f; } if (countHandOfFour(a,b,c,f) > max) {max = countHandOfFour(a,b,c,f); opponent1 = a; opponent2 = b; opponent3 = c; opponent4 = f; crib1 = d; crib2 = e; } if (countHandOfFour(a,b,d,e) > max) {max = countHandOfFour(a,b,d,e); opponent1 = a; opponent2 = b; opponent3 = d; opponent4 = e; crib1 = c; crib2 = f; } if (countHandOfFour(a,b,d,f) > max) {max = countHandOfFour(a,b,d,f); opponent1 = a; opponent2 = b; opponent3 = d; opponent4 = f; crib1 = c; crib2 = e; } if (countHandOfFour(a,b,e,f) > max) {max = countHandOfFour(a,b,e,f); opponent1 = a; opponent2 = b; opponent3 = e; opponent4 = f; crib1 = c; crib2 = d; } if (countHandOfFour(a,e,c,d) > max) {max = countHandOfFour(a,e,c,d); opponent1 = a; opponent2 = e; opponent3 = c; opponent4 = d; crib1 = b; crib2 = f; } if (countHandOfFour(a,f,c,d) > max) {max = countHandOfFour(a,f,c,d); opponent1 = a; opponent2 = f; opponent3 = c; opponent4 = d; crib1 = b; crib2 = e; } if (countHandOfFour(a,e,c,f) > max) {max = countHandOfFour(a,e,c,f); opponent1 = a; opponent2 = e; opponent3 = c; opponent4 = f; crib1 = b; crib2 = d; } if (countHandOfFour(a,d,e,f) > max) {max = countHandOfFour(a,d,e,f); opponent1 = a; opponent2 = d; opponent3 = e; opponent4 = f; crib1 = b; crib2 = c; } if (countHandOfFour(e,b,c,d) > max) {max = countHandOfFour(e,b,c,d); opponent1 = e; opponent2 = b; opponent3 = c; opponent4 = d; crib1 = a; crib2 = f; } if (countHandOfFour(f,b,c,d) > max) {max = countHandOfFour(f,b,c,d); opponent1 = f; opponent2 = b; opponent3 = c; opponent4 = d; crib1 = a; crib2 = e; } if (countHandOfFour(e,b,c,f) > max) {max = countHandOfFour(e,b,c,f); opponent1 = e; opponent2 = b; opponent3 = c; opponent4 = f; crib1 = a; crib2 = d; } if (countHandOfFour(e,b,f,d) > max) {max = countHandOfFour(e,b,f,d); opponent1 = e; opponent2 = b; opponent3 = f; opponent4 = d; crib1 = a; crib2 = c; } if (countHandOfFour(e,f,c,d) > max) {max = countHandOfFour(e,f,c,d); opponent1 = e; opponent2 = f; opponent3 = c; opponent4 = d; crib1 = a; crib2 = b; } opponentHand.add(opponent1); opponentHand.add(opponent2); opponentHand.add(opponent3); opponentHand.add(opponent4); showOpponentHand(); System.out.println(""); System.out.print(max); countHandOfFour(opponent1, opponent2, opponent3, opponent4); crib.add(crib1); crib.add(crib2); System.out.println(""); // showCrib(); // System.out.println(opponent1); // System.out.println(opponent2); // System.out.println(opponent3); // System.out.println(opponent4);

}

}

### Similar Documents

#### Stereotypes In Ruth Park's The Harp In The South

...the south’. Throughout the whole story, Hughie is depicted as a heavy drinker who is always coming home drunk. On page 27 of ‘The harp in the south’ The Author, (Ruth Park) writes, Mumma had been waiting for their return impatiently, for Hughie was due home, and she feared that he would be drunk, and anxious for a fight. This presents a character to the audience who is so often coming home drunk to the point that his wife and children are afraid of him. In the Australian film ‘Red Dog’ the men are hard working beer drinking men. When the workers are not working they are at the pub. John, an American who has assumed an Australian stereotype is one of the characters in the film who has a beer at every opportunity he can get because a stereotypical Australian is always drinking, they are “rewarding themselves” after a hard day's work. Mrs. Cribbage, another character in the film says, “That’s no proper town and there’s no such community, it’s just a bunch of dirty miners working, drinking and whoring.” Alcohol, one of the major Australian stereotypes is incredibly stereotypically depicted in in every beer advertisement. Famous quotes like “I feel like a Tooheys” and “Matter of fact, I’ve got it now” (VB), create an image of Australians only ever drinking or thinking about beer. To be fair, the perceived connection between Australians and beer is not misplaced but, must I say is slightly exaggerated. Australia's drinking standards are way above average but just miss out on a spot...

Words: 705 - Pages: 3

#### Forrest Mars Accomplishments

...by sending tubes of M&M’s overseas to help with the rations. So if he was never born, then millions of people would be lost without their precious chocolate treat and the war might not have turned out for the best. Forrest Mars was born on March 21, 1904 in Wadena, Minnesota. When he was six, his parents divorced and he was sent to live with his grandparents in North Brattleford, Saskatchewan, Canada. Forrest and his mother kept in touch, however he did not see his father until he was a young man. Growing up, Forrest was like a sponge, especially in math and always soaking up more knowledge any chance he could. He was also a bookworm on the hunt for trivia games and trivia knowledge. He was a champ with board games, poker, chess and cribbage. In the year of 1922, Forrest graduated from Lethbridge Central School in Alberta, Canada. Since he was a bright chap he was offered a scholarship to the University of California at Berkeley. At Berkeley he studied mining. Like his father Frank Mars, Forrest was sweet in the kitchen as well as a savvy thrifty businessman. He was thrifty businessman because he bought meat at a low price and then sold it to the kitchen chefs for a higher price. Soon he was making \$100 dollars a week (that was a lot of money back then). He was so good at it he stopped his studies in college to focus on his true passion- business. In 1923 Forrest found work as a traveling salesman. While on an excursion to Chicago, Forrest placed advertisements along all...

Words: 1072 - Pages: 5

#### King County’s Community and Culture the Effects on Obesity

...King County’s Community and Culture The Effects on Obesity King County The Oregon Territorial Legislature established King County of Washington State from a portion of Thurston County on December 22, 1852 after the Oregon Territorial Assembly (King County history quick facts, 2016). King County was first named after William Rufus King of Alabama, the vice president of Franklin Pierce; but in 2005, it was later renamed after Martin Luther King Jr. To the west of King County is Puget Sound, Cascade Mountains to the east, the Canadian border to the north and the Oregon border to the south. A magnificent 2126 square miles of land and 180.5 square miles of water surround it with natural beauty (King County, Washington, 2016). It consists of 20 school districts and 19 cities, including the largest city in Washington, Seattle. Community Assessment In 1860, King County’s population originated as 305 residents; its current population census is a remarkable 2 million, ranked the 14th most populated county in the United States (King County history quick facts, 2016). The number of households in the year 2015 was 850,932 and is estimated to increase to 906,000 in 2020. The diversified industries and populations consists of 64.8% Caucasian, 15.5% Asian, 8.9% Hispanic or Latino, 6.0% African American, and 0.7% American Indian or Alaskan Native (American FactFinder - Community Facts, 2016). In the 20th century, King County’s population growth was an industrial divergence contributed...

Words: 4219 - Pages: 17

Free Essay

#### 50 Books for Kindergarten

Words: 13803 - Pages: 56

Free Essay

#### The Sporting British

...CONTENTS |Introduction |2 | |Main part |3 | |The British. The main features of the British character. |3 | |History of british sport |5 | |Sports invented in Great Britain |6 | |Framework of sport in Britain. |10 | |Modern Sport in Great Britain: Structure, Administration, Funding, Popularity, Sport media and Diseases. |13 | |Elite level sport |15 | |6.1. Elite level team sports |15 | |6.2. Elite level individual sports |22...

Words: 17524 - Pages: 71

Free Essay

Words: 91454 - Pages: 366

#### Marketing

...S E C O N D E D I T I O N POWER MARKETING, SELLING, and PRICING A Business Guide for Wedding and Portrait Photographers Amherst Media ® PUBLISHER OF PHOTOGRAPHY BOOKS Mitche Graf Dedication I would like to dedicate this book to one of the greatest men I have ever met, Pat Wright. Although he is no longer with us, he left behind a legacy that will not soon be forgotten. As my stepfather, my supporter, and my friend, he showed me the value of not only a hard days’ work, but also the importance of taking time to enjoy the precious moments life has to offer. By example, he taught me to take my work seriously, but to take myself lightly. His playful spirit will forever be an integral part of my daily life, and his gentle approach to loving others will always help guide me in each of my relationships. I am honored to have known such a tender and loving man. Copyright © 2009 by Mitche Graf. All rights reserved. Published by: Amherst Media, Inc. P.O. Box 586 Buffalo, N.Y. 14226 Fax: 716-874-4508 www.AmherstMedia.com Publisher: Craig Alesse Senior Editor/Production Manager: Michelle Perkins Assistant Editor: Barbara A. Lynch-Johnt Editorial Assistance: John S. Loder, Carey A. Maines, C. A. Schweizer ISBN-13: 978-1-58428-246-4 Library of Congress Card Catalog Number: 2008926666 Printed in Korea. 10 9 8 7 6 5 4 3 2 1 No part of this publication may be reproduced, stored, or transmitted in any form or by any means, electronic, mechanical...

Words: 83440 - Pages: 334

Free Essay

#### Lovestories Book

...http://www.ebooksread.com/ THE WORKS OF MARY ROBERTS RINEHART LOVE STORIES THE REVIEW OF REVIEWS COMPANY Publishers NEW YORK PUBLISHED BY ARRANGEMENT WITH GEORGE H. DORAN COMPANY. Copyright, 1919, By George H. Doran Company Copyright, 1912, 1913, 1916, by the Curtis Publishing Company Copyright, 1912, by The McClure Publications, Inc. Copyright, 1917, by The Metropolitan Magazine Co. CONTENTS I TWENTY-TWO II JANE III IN THE PAVILION IV GOD'S FOOL V THE MIRACLE VI "ARE WE DOWNHEARTED? NO!" VII THE GAME LOVE STORIES TWENTY-TWO I The Probationer's name was really Nella Jane Brown, but she was entered in the training school as N. Jane Brown. However, she meant when she was accepted to be plain Jane Brown. Not, of course, that she could ever be really plain. People on the outside of hospitals have a curious theory about nurses, especially if they are under twenty. They believe that they have been disappointed in love. They never think that they may intend to study medicine later on, or that they may think nursing is a good and honourable career, or that they may really like to care for the sick. The man in this story had the theory very hard. When he opened his eyes after the wall of the warehouse dropped, N. Jane Brown was sitting beside him. She had been practising counting pulses on him, and her eyes were slightly upturned and very earnest. There was a strong odour of burnt rags in the air, and the man sniffed. Then he put a hand to his upper lip--the right hand. She was holding...

Words: 75244 - Pages: 301

Free Essay

#### Term Paper for Social Change

...Standard 1: A school administrator is an educational leader who promotes the success of all students by facilitating the development, articulation, implementation, and stewardship of a vision of learning that is shared and supported by the school community. The effective administrator: 1.1 Uses research about best professional practice. Cooperative Learning       "Cooperative learning is the instructional use of small groups so that students         work together to maximize their own and each other's learning." WHAT IS IT? Cooperative learning is a successful teaching strategy in which small teams, each with students of different levels of ability, use a variety of learning activities to improve their understanding of a subject. Each member of a team is responsible not only for learning what is taught but also for helping teammates learn, thus creating an atmosphere of achievement. WHY USE IT? Documented results include improved academic achievement, improved behavior and attendance, increased self-confidence and motivation, and increased liking of school and classmates. Cooperative learning is also relatively easy to implement and is inexpensive. HOW DOES IT WORK? Here are some typical strategies that can be used with any subject, in almost any grade, and without a special curriculum: Group Investigations are structured to emphasize higher-order thinking skills such as analysis and evaluation. Students work to produce a group project, which they may have a hand...

Words: 52057 - Pages: 209

Free Essay

#### Test2

...62118 0/nm 1/n1 2/nm 3/nm 4/nm 5/nm 6/nm 7/nm 8/nm 9/nm 1990s 0th/pt 1st/p 1th/tc 2nd/p 2th/tc 3rd/p 3th/tc 4th/pt 5th/pt 6th/pt 7th/pt 8th/pt 9th/pt 0s/pt a A AA AAA Aachen/M aardvark/SM Aaren/M Aarhus/M Aarika/M Aaron/M AB aback abacus/SM abaft Abagael/M Abagail/M abalone/SM abandoner/M abandon/LGDRS abandonment/SM abase/LGDSR abasement/S abaser/M abashed/UY abashment/MS abash/SDLG abate/DSRLG abated/U abatement/MS abater/M abattoir/SM Abba/M Abbe/M abbé/S abbess/SM Abbey/M abbey/MS Abbie/M Abbi/M Abbot/M abbot/MS Abbott/M abbr abbrev abbreviated/UA abbreviates/A abbreviate/XDSNG abbreviating/A abbreviation/M Abbye/M Abby/M ABC/M Abdel/M abdicate/NGDSX abdication/M abdomen/SM abdominal/YS abduct/DGS abduction/SM abductor/SM Abdul/M ab/DY abeam Abelard/M Abel/M Abelson/M Abe/M Aberdeen/M Abernathy/M aberrant/YS aberrational aberration/SM abet/S abetted abetting abettor/SM Abeu/M abeyance/MS abeyant Abey/M abhorred abhorrence/MS abhorrent/Y abhorrer/M abhorring abhor/S abidance/MS abide/JGSR abider/M abiding/Y Abidjan/M Abie/M Abigael/M Abigail/M Abigale/M Abilene/M ability/IMES abjection/MS abjectness/SM abject/SGPDY abjuration/SM abjuratory abjurer/M abjure/ZGSRD ablate/VGNSDX ablation/M ablative/SY ablaze abler/E ables/E ablest able/U abloom ablution/MS Ab/M ABM/S abnegate/NGSDX abnegation/M Abner/M abnormality/SM abnormal/SY aboard ...

Words: 113589 - Pages: 455