CS112、java

55 阅读3分钟

Copyright 2023 Paul Haskell. All rights reserved.CS112 – Spring 2024Project01 – PokerInstructor: Paul HaskellINTRODUCTIONFor Project01 you will develop a program that plays the card game Poker. At the end of the project, wewill have a Casino Day in which everyone’s programs play a tournament together, with a single Dealercoordinating the play. Grading is not based on the outcome of the tournament (maybe we play morethan one), but rather on code quality and sophistication of your approach to planning the game.Your game is not an interface for a person to play Poker. Your program will be the player, making theplaying and betting decisions, playing against another computer program that acts as the Dealer. Yourplayer and the dealer may play hundreds of hands per second!Before the actual Casino Day, you will have an opportunity to test your program in class with a simplifiedDealer.The GameThere are many different variations of Poker. For this project, your program will play a simple versionthat you probably have not played before called "Three card stud". Like all poker games, three card studis a betting game. Each player starts with a stack of money. Every round the player gets cards, placesbets, and wins or loses. The objective of the game is to not run out of money for as long as possible.Multiple players (the entire class?) all play the game together, with the Dealer coordinating game play.AnteThe word "ante" means "before" in Latin. In English, an "ante" is a bet that players must make in abetting game before play starts.In poker, there is a single "pot" of money. Every round begins with every player putting a 1betthe"ante"intothepot.Allotherbetsmadeduringthegamealsoareplacedintothepot.Attheendofeachround,thewinnerorwinnersgetthemoneyinthepot.Thenthenextroundbegins.CardPlayAtthestartofeachround,afteralltheplayersante,eachplayerisdealtonecardvisibleonlytothatplayer("facedown"or"inthehole")andonecardvisibletoeveryone("faceup"or"up").Beginningwiththeplayerwiththehighest"up"card,eachplayerhasanopportunitytoplaceanadditionalbet.Afteraplayermakesanonzerobet,allfollowingplayersmust:match("see")thebetwithanequaloneoftheirownraisethebetbymakingalargerbet"fold"i.e.withdrawfromthecurrentroundofplay,concedingalossintheroundForthisproject,themaximumbetorraiseshallbe1 bet—the"ante"—into the pot. All other bets made during the game also are placed into the pot. At the end ofeach round, the winner or winners get the money in the pot. Then the next round begins.Card PlayAt the start of each round, after all the players ante, each player is dealt one card visible only to thatplayer ("face down" or "in the hole") and one card visible to everyone ("face up" or "up"). Beginningwith the player with the highest "up" card, each player has an opportunity to place an additional bet.After a player makes a nonzero bet, all following players must: match ("see") the bet with an equal one of their own raise the bet by making a larger bet "fold" i.e. withdraw from the current round of play, conceding a loss in the roundFor this project, the maximum bet or raise shall be 10.Copyright 2023 Paul Haskell. All rights reserved.So for example, if we have four players playing, named Amit, Brian, Carlos, and Denise, the followingbets would be legal: Amit bets 10Brianraisesto10 Brian raises to 15 Carlos folds Denise sees the 15betAmitadds15 bet Amit adds 5 to match Brian's bet and also adds 10more,raisingthetotalbetto10 more, raising the total bet to 25 Brian adds 10,to"see"the10, to "see" the 25 bet Denise foldsAt this point, everyone playing either has folded or has matched the current bet.After the first two cards have been dealt and the first round of betting, the Dealer gives one more card,face up (visible to everyone), to each player who has not folded. Then there is another round of betting,conducted with the same rules as the first round.After the second round of betting, a winner is determined.- Three-of-a-kind beat any other hand. If more than one player has three-of-a-kind, then theplayer with the higher card value wins.- The next highest hand is a pair (two cards with the same value). If more than one player has apair, the pair with the highest card value wins (ignoring the third card). If two players have pairswith matching values, then the values of only those players' remaining cards are compared, andthe higher card wins. If all three cards match, then the two players are both winners and splitthe winnings.代 写CS112、java

  • If no player has a pair, then the player with the highest card wins. If more than one player hasthe same highest card, then those players only compare their second-highest (and third-highestif necessary) cards to determine the round's winner.- One more rule to keep things fun: the player who wins the poker hand only wins half the pot!The other half of the pot goes to the player with the highest "spade in the hole", that is, thehighest face-down card whose suit is Spades. If no player has a Spade "in the hole", then thewinner of the poker round wins the entire pot. If the same player wins the poker hand and hasthe highest spade in the hole, that player wins the entire pot.ReshufflingThe Dealer reshuffles the card deck before every round of play.BettingBets must be made in increments of 1.Aplayerisnotpermittedtobetmoremoneythanremainsinherstack,soaplayermaybeforcedtofold.Whenaplayerrunsoutofmoney,i.e.hasnomoneylefttoante,thensheisoutofthegame.BettingZeroAplayermaybetzerochipsonanyopeningbet.Thisisawisebetiftheplayershandisnotverystrong.Sometimes,everyplayerinaroundwillbet1. A player is not permitted to bet more money than remains inher stack, so a player may be forced to fold. When a player runs out of money, i.e. has no money left toante, then she is out of the game.Betting ZeroA player may bet zero chips on any opening bet. This is a wise bet if the player's hand is not very strong.Sometimes, every player in a round will bet 0, and only the ante bets will be claimed by the round'swinner.Copyright 2023 Paul Haskell. All rights reserved.Your ProgramThe instructor has written a Java program that will perform as Dealer. Each of your Poker.javaprograms will communicate with the Dealer over the classroom WiFi network, using Internet Protocol(“IP”). Luckily, Java makes it easy to set up this communication.Communication with SocketsYour Poker.java program should take two command-line arguments: IpAddress: IP network of Dealer IpPort: IP port number of serverYour program should include something similar to the following code—you need not understand all ofthis code, please simply copy it into your program:import java.net.Socket;import java.io.IOException;import java.io.DataInputStream;import java.io.DataOutputStream;Socket socket = new Socket(args[0], Integer.parseInt(args[1]));DataInputStream dis =new DataInputStream(socket.getInputStream());DataOutputStream dos = new DataOutputStream(socket.getOutputStream());private void write(String s) throws IOException {dos.writeUTF(s);dos.flush();}private String read() throws IOException {return dis.readUTF();}Your program will read commands from the Dealer by calling read() and looking at thereturned String. Your program will write responses to the Dealer by calling write(),passing in your program's response.Please think about where in your program to put the code that creates socket, dis, anddos, and the read() and write() methods.Copyright 2023 Paul Haskell. All rights reserved.Game ProtocolA protocol is a set of rules by which two (or more) entities interact with each other. Your program willcommunicate with the Dealer by implementing the following protocol. The Dealer will initiatecommunications every time, by sending a command (along with data) to your program. Your programshould repeatedly try to read from the Dealer. When a command is received, your program interprets itand responds. Several commands require a reply. Here are the Dealer commands and required replies: login – whenever your program receives this command, it must reply with>:>For example StephenCurry:StephYour program may receive the “login” command more than once. You always must reply withthe same values. Your “avatar” name will be shown on a graphics window, to update everyoneon the Casino Day game status. Your GitHubId will be known only to the instructor. bet1:>:>:beat>>:>:>:up:>:player's "up" card>>::etcFor example, bet1:208:24:12:KS:10D:up:AS:8H:10D:QD:2CNotice that your "up" card is in the list of dealt cards.You must reply with one of the following: WX:codehelp