Академический Документы
Профессиональный Документы
Культура Документы
Due Wednesday, 6 November 2013, 11:55 pm Mid-project checkpoint due Wednesday, 16 October 2013, 11:55pm
EuchreisatricktakingcardgamepopularinMichigan.Itismostcommonlyplayedbyfour peopleintwopartnershipswithadeckof24cards.Partnershipsaccumulatepointsforwinning tricks,andthegamecontinuesuntilonesidereachesthemaximumnumberofpoints. Inthisproject,youwillwriteasimulatorforagameofEuchre.Youwillgainexperiencewith composabledatastructures,objectorientedprogrammingtechniquesanddecomposingatask usingfunctions.Whilebuildingthesimulator,youwillusepointers,arrays,structures,strings andfileIO.
Euchre Rules
TherearemanyvariantsofEuchre.TherulesforthisprojectarederivedfromGorensHoyle EncyclopediaofGames[Goren1961],withtheadditionofseveralvariationscommonin Michiganplay.
Number of players
Four,intwopartnerships.
The pack
Apackof24cards,madebydiscardingfromafullpackallcardsbelowthenines.Inother words,ranksninethroughaceofallfoursuits.
Order of cards
Cardsareorderedaccordingtowhichsuitistrump,asuitwhosecardsareelevatedabovetheir normalrankduringplay.Thehighestcardisjackofthetrumpsuit,andiscalledtherightbower. Thesecondhighestcardisthejackoftheothersuitofthesamecolorasthetrump,andis calledtheleftbower.Theleftbowerisalsoconsideredatrumpcard.Forexample,ifDiamonds istrump,theJackofHeartsisalsoconsideredaDiamond,notaHeart.Thesuitoftheleft boweriscallednext,whilethetwosuitsoftheoppositecolorarecalledcrosssuits. Tosimplifydebuggingandensurethateverycorrectsolutionwillgetthesameoutput,weve addedanadditionalrulehere.Inadditiontobeingorderedbyrank,cardsarealsoorderedby suit:diamondsfirst,thenclubs,hearts,spades. Thecompleteorderingofallthecardsis:J(rightbower,high),J(leftbower),A,K,Q,10,9ofthe trumpsuit.Theacesoftheremainingthreesuitsfollowinsuitorder,theremainingkingsinsuit order,,andfinallytheremainingninesinsuitorder.
partnered0&2,and1&3.
The deal
Inourgame,thefirstdealeristhefirstplayer.Eachhand,thedealmovesoneplayertotheleft. Eachplayerreceivesfivecards,dealtinbatchesof32.Thefirstpersontoreceiveacardisleft ofthedealer.Thatis,deal3232cardsthen2323cards,foratotalof5555cards.Afterall handsaredealt,thenextcardofthepackisturneduptoproposethetrumpsuit.
Making trump
Theturnedupcardinfrontofthedealerproposesthetrumpsuit,butitsacceptancedependson uptotworoundsofmaking.Eldesthand(playeratleftofthedealer,e.g.,player3isleftofplayer 2,andplayer0isleftofplayer3)speaksfirst.Hemayeitherpassororderup.Orderup acceptstheturnupsuit.Ifthetrumpsuitisorderedupduringroundone,thedealeraddstheup cardtohishandanddiscardsonecardtobringhishandbacktofivecards,total.Hint:be carefulnottogoofftheendofanarrayhere!Ifaplayerpasses,thenextplayertotheleft speaks. Ifallplayerspassduringthefirstround,thereisasecondroundofdeclaring,againbeginning withtheeldesthand.Thistime,eachplayerinturnmayeitherpassororderupbynamingasuit otherthantherejectedsuit. Ifmakingreachesthedealerduringthesecondround,avariantcalledscrewthedealeris invoked.Thedealermustorderupasuitotherthantherejectedsuit. SidenoteforproEuchreplayers:wehaveomittedgoingaloneinthisproject,asimplification.
The play
Thefirstcard,calledthelead,isplayedbytheeldesthand,regardlessofwhoisthemaker.The leader(personplayingtheleadcard)toanytrickmayleadanycard.Playmovestotheleft aroundthetable,witheachhandplayingonecard.Eachotherhandmustfollowtheledsuit,if able,andotherwisemayplayanycard.Atrickiswonbythehighesttrump,or,ifitcontainsno trump,bythehighestcardofthesuitled.Attheendofatrick,playedcardsarediscarded.The winnerofthetrick(orround)leadsthenext.
Object of play
Theobjectiveistowinamajorityoftricks.
Scoring
Revision20131002 2
Euchre strategy
Making
Inmakingtrump,aplayerconsiderstheupcard,theplayerwhodealt,andwhetheritisthefirst orsecondround.Amorecomprehensivestrategywouldconsidertheotherplayersresponses, butwewillkeepitsimple. Duringroundone,aplayerwillorderupifhehastwoormoretrumpfacecardsinhishand. Trumpfacecardsaretherightandleftbowers,andQ,K,Aofthetrumpsuit,whichisthesuit proposedbytheupcardinthiscase.Ifthetrumpsuitisorderedupduringroundone,thedealer receivesit.Hethendiscardsthelowestcardamonghishandandtheturnup,forafinaltotalof fivecards. Duringroundtwo,aplayerwillorderupthesuitwiththesamecolorastheupcardifhehasone ormorefacecardsofthatsuitinhishand.Forexample,iftheupcardwasaheartandhehad thekingofdiamondsinhishand,hewouldorderupdiamonds.Ifmakingreachesthedealer duringthesecondround,weinvokescrewthedealer,wherethedealerisforcedtoorderup.In thecaseofscrewthedealer,thedealerwillalwaysorderupthesuitwiththesamecolorasthe upcard.
Leading
Whenaplayerleadsatrick,heplaysthehighestnontrumpcardinhishand.Ifhehasonly trump,heplaysthehighesttrumpcardinhishand.
Playing
Whenplayingacard,playersuseasimplestrategythatconsidersonlythesuitthatwasled.A morecomplexstrategywouldalsoconsiderthecardsonthetable,butagain,wewillkeepit simple. Ifaplayercanfollowsuit,heplaysthehighestcardthatfollowssuit.Otherwise,heplaysthe lowestcardinhishand.
Example
Theoutputfor. / e u c h r e p a c k . i n n o s h u f f l e 1 A l i c e B o b C a t h y D r e w issavedin e u c h r e _ t e s t 0 0 . o u t . c o r r e c t .Thissectionexplainstheoutput,linebyline.Makesure thatyoursimulatorproducesonlyoutputcalledforbythisdocument.
Revision20131002
First,printtheexecutableandallargumentsonthefirstline.Printasinglespaceattheend, whichmakesiteasiertoprintanarray. . / e u c h r e p a c k . i n n o s h u f f l e 1 A l i c e B o b C a t h y D r e w Atthebeginningofeachhand,announcethehand,startingatzero,followedbythedealerand theturnup. H a n d 0 A l i c e d e a l s J a c k o f D i a m o n d s t u r n e d u p Printthedecisionofeachplayerduringthemakingprocedure.Printanextranewlinewhen makingiscomplete. B o b p a s s e s C a t h y p a s s e s D r e w p a s s e s A l i c e p a s s e s B o b o r d e r s u p H e a r t s Eachofthefivetricksisannounced,includingthelead,cardsplayedandtheplayerthattookthe trick.Printanextranewlineattheendofeachtrick. J a c k o f S p a d e s l e d b y B o b K i n g o f S p a d e s p l a y e d b y C a t h y A c e o f S p a d e s p l a y e d b y D r e w N i n e o f D i a m o n d s p l a y e d b y A l i c e D r e w t a k e s t h e t r i c k Attheendofthehand,printthewinnersofthehand.Whenprintingthenamesofapartnership, printtheplayerwiththelowerindexfirst.Forexample,Alicewasspecifiedonthecommandline beforeCathy,soshegoesfirst. A l i c e a n d C a t h y w i n t h e h a n d Ifmarchoccurs,printm a r c h ! followedbyanewline.Ifeuchreoccurs,printe u c h r e d ! followed byanewline.Ifneitheroccurs,printnothing. e u c h r e d ! Printthescore,followedbyanextranewline. A l i c e a n d C a t h y h a v e 2 p o i n t s B o b a n d D r e w h a v e 0 p o i n t s Whenthegameisover,printthewinnersofthegame. A l i c e a n d C a t h y w i n !
Code structure
Revision20131002 4
Thecodeisstructuredasanobjectorientedprogram.TheC++structmechanismisusedto represententitiesintheEuchreworld,forexampleC a r d ,P a c k , andP l a y e r .These structuresaredefinedinseveralheaderfiles,andtheyinteractwitheachotherthroughfunctions thatformaproceduralabstraction.Yourtaskistoimplementthesefunctionsin. c p p files, addinganyadditionalhelperfunctionstothe. c p p files.Finally,youwillwriteam a i n ( ) function withacommandlineinterfacetothegame.
toprintanerrormessage,andthencalle x i t ( E X I T _ F A I L U R E ) . c o u t < < " E r r o r o p e n i n g " < < p a c k _ f i l e n a m e < < e n d l AfterthePackfileisopen,youmayassumethatthereareexactly24uniqueandcorrectly formattedcards.Inotherwords,youdonthavetoworryaboutcheckingthecontentsofthefile forerrors.
Restrictions
Inthisproject,itisourgoalforyoutogainpracticewithgoodCstylecode,structs,andpointers. Toencouragethisstyle,wehaveafewrestrictions,describedinthefollowingtable. Dos Modify. c p p files Putanyextrahelperfunctionsinthe. c p p filesanddeclarethems t a t i c Usetheselibraries:< i o s t r e a m > , < f s t r e a m > ,< c s t d l i b > ,< c a s s e r t > , < c s t d i o > , < c s t r i n g > , < s t r i n g > # i n c l u d e alibrarytouseitsfunctions UseC++stringstoreadfromfilesand Cstringseverywhereelse Sendalloutputtostandardout(AKAstdout) byusingc o u t c o n s t globalvariables Donts Modify. h files Modify. h files Useotherlibraries
Revision20131002
Variablesonthestack
Dynamicmemory(n e w ,m a l l o c ( ) ,etc.)
C a r d _ t e s t . c p p . s t a r t e r
P a c k . h P a c k _ t e s t . c p p . s t a r t e r
P l a y e r . h P l a y e r _ t e s t . c p p . s t a r t e r
G a m e . h p a c k . i n M a k e f i l e . s t a r t e r
Revision20131002
Code main
Revision20131002 8
Themainfunctioncodedine u c h r e . c p p willbeverysimple.Itshouldreadthecommandline arguments,checkthemforerrors,andthenprintthem.Next,callG a m e _ i n i t ( ) followedby G a m e _ p l a y ( ) .Finishwithr e t u r n E X I T _ S U C C E S S attheendofmain. Inorderformaintocompile,itwillneedG a m e . c p p tocompile.ForG a m e . c p p tocompile,all thefunctionsfromG a m e . h needtobeinG a m e . c p p .AddfunctionstubstoG a m e . c p p ,which donothingbutreturnaconstantvalue.Thiswillallowyoutocompilethewholeproject,evenif youarentfinishedyet.Hereisanexampleofafunctionstub,fromG a m e . c p p : v o i d G a m e _ p l a y ( G a m e * g a m e _ p t r ) { r e t u r n } Compilethemaineuchreexecutablebytypingm a k e e u c h r e ,whichwillrunthecommand g + + p e d a n t i c W a l l W e r r o r O 1 e u c h r e . c p p G a m e . c p p P l a y e r . c p p P a c k . c p p C a r d . c p p o e u c h r e Runtheprogrambyprovidingcommandlinearguments,forexample: . / e u c h r e p a c k . i n s h u f f l e 1 0 A l i c e B o b C a t h y D r e w
Code Game
Thispartwillrequirethemostplanning.Beforeyoubegin,thinkaboutwhichhelperfunctionsyou wouldliketoaddandwhattheyshoulddo.Forexample,functionsthatshuffle,dealandmake trumpareagoodstartingpoint.Remember,onlyaddfunctionstoG a m e . c p p anddeclarethem static.HereisanexampleofapossiblehelperfunctionfromG a m e . c p p : / / R E Q U I R E S : g a m e _ p t r i s i n i t i a l i z e d / / M O D I F I E S : g a m e _ p t r / / E F F E C T S : I f t h e s h u f f l e o p t i o n i s s e l e c t e d s h u f f l e t h e p a c k . / / O t h e r w i s e , r e s e t t h e p a c k . s t a t i c v o i d G a m e _ s h u f f l e ( G a m e * g a m e _ p t r )
Revision20131002
Submit
Thisprojecthastwosubmissions.Thefirstisamidprojectcheckpoint,whereseveral componentsaredue.Thesecondisthefinaldeadlineforthecompletedproject. Forthemidprojectcheckpoint,submitthefollowingfilesusings u b m i t 2 8 0 3 a .TheC a r d , P a c k andP l a y e r componentsshouldpassthepublishedunittests. C a r d . c p p P a c k . c p p P l a y e r . c p p Forthefinalsubmission,submitthefollowingfilesusings u b m i t 2 8 0 3 .Forthispartofyour grade,wewillnotuseanycodeturnedinatthecheckpoint. C a r d . c p p P a c k . c p p P l a y e r . c p p G a m e . c p p e u c h r e . c p p
Acknowledgements
OriginalprojectwrittenbyAndrewDeOrio,fall2013.ThetextforthebasicrulesofEuchrewas adaptedfromGorensHoyleEncyclopediaofGames[Goren,1961].
Revision20131002
10
Revision20131002
11
Revision20131002
12
everytime.
Disabling assert
Todisabletheassert()statementsinafile,simplyadd# d e f i n e N D E B U G toeach.cppthat usesassert().
Revision20131002
14