Skip to main content
留学咨询

墨尔本大学COMP90041课业解析

By May 15, 2020No Comments

墨尔本大学COMP90041课业解析题意: 使用JAVA编写一个扑克牌游戏。从52张扑克(除了大小王)中抽取5张牌,这五张手牌可能会有9种得分从高到低的组合:同花顺,有四张一样,三带二,同花,顺子,三张一样,两双,一双,除以上之外的任意手牌。这个程序就是提示玩家输入5张牌,然后按照这些组合特定的输出格式进行输出,如果有多个玩家,则还会对手牌进行判断最后谁会赢。 
解析: 这是一个字符处理问题,五个字符串当作一个玩家的手牌,如果输入的字符串不符合卡牌的规则或者少于多余5张都应该输出一些报错信息。而且需要支持多个玩家,就应该对输入的每五个字符串当作一个组手牌,private boolean check()与 private int index(String[] arr, String key) 作为检查函数判断内容与长度是否合理,每五张进行一次处理,首先是查找字符串在数组的位置然后判断是否是顺序(等差数列的判断),按照给定的顺序进行冒泡排序即可比较大小,其次用private boolean is_same(String[] arr)判断数组元素是否一致(同花判断),其他玩法类似。将手牌对应到9种组合中,给每个玩家一个分数,最后分数高的胜出。  涉及知识点: 字符串处理,JAVA,数组更多可加微信讨论微信号:yzr5211234pdf
The University of MelbourneSchool of Computing and Information SystemsCOMP90041Programming and Software DevelopmentSecond Semester, 2019ProjectDue Friday, 4 October 2019, 5:00PMObjectiveThe objective of this project is to practice your Java programming skills. This project is adeparture from the earlier assessed labs, in that the assessment will focus on code quality,as well as correctness. You should allocate a few hours to tidying up your code after yourimplementation is complete. You will make comments on three of your peers’ projects’ codingand documentation style, and will receive feedback from your peers on your submission.The Game of PokerPoker is a gambling card game dating back to the early 19th century. There are a great manyvariations of the game, but for this project we will just consider the simple 5-card game,leaving out much of the subtlety of the game involving betting and bluffing.A poker hand consists of five cards from a standard 52-card deck (without jokers). Theranks, in order of increasing value, are 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, and Ace,and the suits are Clubs (♣), Diamonds (♦), Hearts (♥), and Spades (♠). Each card has arank and a suit, and all combinations are valid cards.There are 9 classifications of hands, as follows, in order of decreasing value:Straight flush consists of 5 cards of the same suit whose ranks form a sequence, such as 7♥,8♥, 9♥, 10♥, J♥. If two players both have a straight flush, the one with the highestcard wins. If both players have the same ranks of cards (but different suits), the playersdraw. Suits are never used to decide the winner in poker.Four of a kind consists of a set of four cards of the same rank, and any other card, such as3♥, 3♠, 3♦, 3♣, 7♥. If two players both have four of a kind, the one with the highestrank of their set of four wins. In some varieties of poker it is possible for two playersto both have 4 of the same rank; in this case the one with the higher rank of their fifthcard wins. If the fifth cards are also the same rank, it is a draw.Full house consists of three cards of one rank and two of another; that is three of a kindplus a pair, for example Q♥, Q♣, Q♦, 7♠, 7♣. If two player both have a full house,the one with the higher rank of their set of three wins. If two players to each have threecards of the same rank, then the rank of the pair is used to decide.Flush consists of any 5 cards of the same suit, regardless of their rank, for example K♣, 9♣,3♣, J♣, 4♣. If two players both have a flush, then their highest ranking card is used todecide the winner. If their highest ranking cards have the same rank, then their second1highest ranking cards, followed by their, third, fourth, and fifth highest ranking cardsare used in turn.Straight consists of 5 cards whose ranks form a sequence, regardless of their suits, for example, 6♠, 7♣, 8♦, 9♠, 10♥. If two players both have a straight, the one with the highestranking card wins. If two hands have the same highest ranking card, they draw.Three of a kind consists of 3 cards of the same rank, and any other 2 cards, for example,6♦, 6♠, 6♥, 9♥, J♦. If two players both have three of a kind, the player whose threeof a kind have the highest rank wins. If this is a tie, then the higher ranking other cardis used, and if this, too, is a tie, then the rank of last card decides.Two pair consists of 2 cards of one rank, 2 cards of another rank, and any other card, suchas 5♦, 5♠, 9♣, 9♠, A♥. If two players both have two pair, the ranks of their highestranking pairs decide the winner; if their highest ranking pairs are the same rank, thesecond ranking pair decides; if they are also the same, the rank of the final cards decides.One pair consists of 2 cards of one rank, and any other 3 cards, for example, A♠, A♣, 6♠,J♥, 2♦. If two players both have one pair, the rank of the pair decides, with the ranksof their other cards, from high to low, used if their pairs are of the same rank.High card consists of any 5 cards. If two players both have a high card hand, the ranks ofthe cards, from high to low, are used to decide the winner.Note that the best (earliest in the list) description of a hand should be used. For example,a hand with three of a kind and a pair must always be classified as a full house, even thoughit could also be called three of a kind or a pair (or a high card hand).There are innumerable sources of information about poker available online. One that maybe helpful for this project is http://en.wikipedia.org/wiki/List_of_poker_hands, butthe information in this description should be enough the complete the project.The ProgramThere are two difficulty levels for this project. All students must complete the simpler version.Students wishing for a greater challenge may also undertake the second part of the assignment.Each student will be assessed on the part or parts they have undertaken. Students completingonly the less challenging part of the project can still receive full marks.For this project, you will write a program that will correctly characterise a poker handaccording to the list of hands above. For students undertaking the more advanced project, ifmore than one hand is given as input, the program will also decide which hand wins.In either case, your main program should be called Poker.java, and should expect somemultiple of 5 cards on the command line (at least 5 cards). Cards should be entered on thecommand line as two-character strings, the first being an A for Ace, K for King, Q for Queen,J for Jack, T for Ten, or digit between 2 and 9 for ranks 2–9. The second character should bea C for Clubs (♣), D for Diamonds (♦), H for Hearts (♥), or S for Spades (♠). Your programshould handle both upper and lower case characters (or even a mixture).We make one small change to the rules of poker to make the project easier: we alwaystake Aces to be the highest rank. Most versions of the rules of poker would consider Ace, 2,3, 4, 5 to be a straight (or straight flush), but we do not.2The output generated by your program should include, for each hand specified on thecommand line, one line of the form:Player n: description of handwhere n is 1 when describing the first 5 cards, 2 for the next 5, and so on, and space is shownas . The description of hand gives both the hand category and some indication of how todecide ties using standard Poker lingo as follows:Category Description DetailStraight flush r-high straight flush r is highest rank in handFour of a kind Four rs r is rank of 4 cardsFull house r1s full of r2s r1 is rank of 3 cards; r2 is rank of 2Flush r-high flush r is highest rank in handStraight r-high straight r is highest rank in handThree of a kind Three rs r is rank of 3 cardsTwo pair r1s over r2s r1 is rank of higher pair; r2 is rank oflower pairOne pair Pair of rs r is rank of pairHigh card r-high r is highest rank in handIn all of the above, ranks (r, r1 and r2 above) should be shown as numerals, or fullcapitalised rank names for face cards: 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, King, or Ace.Note that this is different from the way ranks are specified on the command line. Also notethat the information conveyed in these hand descriptions is not always enough to decidethe winner; for example, in deciding the winner between two Queen-high hands, the secondhighest ranked cards in the two hands must be consulted, but these are not shown in the handdescriptions. Nevertheless, you must correctly decide the winner between two such hands, ifyou undertake the more challenging project.For students choosing to complete the simpler version of the project, if more than 5command line arguments are supplied, the program should output only NOT UNDERTAKEN asa single line, and then exit. They will not be assessed on the tests for more than one hand;however, it is important that they output exactly the line NOT UNDERTAKEN, so that the testingscript does not take the output to be an erroneous attempt to handle the harder version ofthe project.For students choosing to complete the more challenging assignment, if more than onehand
is specified on the command line, the lines indicating each hand’s description must befollowed by a single line sentence indicating the winner. When player number n wins, thisshould have the form “Player n wins.” When two players draw, the sentence should havethe form “Players n1 and n2 draw.” where n1 and n2 are the player numbers of the tiedwinning players, in order of ascending player number. If three or more players draw, thesentence should have the form “Players n1, n2 . . . and nk draw.” where n1–nk are thewinning player numbers in ascending order. In all of this, Player 1 corresponds to the first5 cards, Player 2 to the next 5, and so on.If the number of command line arguments is not greater than zero or not a multiple offive, your program should print outError: wrong number of arguments; must be a multiple of 53and exit. If any of the command line arguments is not a valid card name, as specified above,the program should print outError: invalid card name ’c’and exit, where c is the (first) invalid card entered on the command line.Note well: Since some forms of poker allow the same card to be considered to be part ofmany players’ hands, you should not assume that no cards appear in more than one hand. Ifit is useful to you, you may assume that no cards are repeated in a single hand, but you donot need to check for this.ExamplesFor example, this input:java Poker 2H TH AS AD TCshould produce this output:Player 1: Aces over 10sThis input:java Poker 2H TH 1S 1D TCShould produce this output:Error: invalid card name ’1S’This input:java Poker KS 9S QS AS JS 3D 7C 3S 3H 7SShould produce this output:Player 1: Ace-high flushPlayer 2: 3s full of 7sPlayer 2 wins.This input:java Poker qc jc 2h 7s 9h qd jd 2s 7c 9s 9c 7d 2c jh qh 9d 7h 2d js qsShould produce this output:Player 1: Queen-highPlayer 2: Queen-highPlayer 3: Queen-highPlayer 4: Queen-highPlayers 1, 2, 3 and 4 draw.4SubmissionYou will submit your work twice almost identically both times. The first submission willbe for assessing correctness and code quality, and should include your name and login ID(but not your student ID) on all files. The second submission will be for anonymous peerassessment, and so should not include your name or login ID in any of the files.The first submission will be done similarly to the assessed labs. You must submit yourproject from any one of the student unix servers. Make sure the version of your programsource files you wish to submit is on these machines (your files are shared between all ofthem, so any one will do), then cd to the directory holding your source code and issue thecommand:submit COMP90041 proj all your source fileswhere all your source files is the names of all your .java files, including Poker.java, in anyorder, separated by spaces.Important: you must wait a minute or two (or more if the servers are busy) after submitting,and then issue the commandverify COMP90041 proj | lessThis will show you the test results and the marks from your submission, as well as the file(s)you submitted. If the test results show any problems, correct them and submit again. Youmay submit as often as you like; only your final submission will be assessed.If you wish to (re-)submit after the project deadline, you may do so by adding “.late”to the end of the project name (i.e., proj.late) in the submit and verify commands. Butnote that a penalty, described below, will apply to late submissions, so you should weigh thepoints you will lose for a late submission against the points you expect to gain by revising yourprogram and submitting again. It is your responsibility to verify your submission.Instructions for the second, anonymised, submission will be posted closer to the due date.AssessmentYour project will be assessed on the following criteria:35% The quality of your code and documentation;40% The correctness of your program based on the output produced;25% The quality of the anonymous feedback you give the peer projects you are assigned.Note that timeouts will be imposed on all tests. You will have at least 1 second per testcase, which should be ample.The quality of your code is an important part of your assessment. Please read the ProjectCoding Guidelines on the LMS Project page for an explanation of the factors we consider inassessing code quality. This will also be discussed in a later lecture.5Hints1. Start by implementing a class to represent cards. I suggest using an enum to representthe ranks and suits.2. For the simpler project, you will need to classify a hand. For the more challengingproject, you also need to compare two hands to see which wins. I suggest writinga class to represent a poker hand description, including the classification and extrainformation that needs to be displayed (such as the rank of a pair or the ranks of thetriple and pair in a full house). For the more challenging project, this will need tocontain more information, such as the ranks of all the cards in a high-card hand, todecide which of two hands of the same category wins. Write a static method for thisclass that takes an array of five instances of your card class and constructs and returnsthe appropriate description object.Again, an enum is good way to handle the classifications. As for the extra information, italways comes down to comparing ranks (suits never matter), so I suggest using an arrayof ranks to provide the extra information. If two hands have different classifications, thenthe extra information is not needed to determine the winner. When the classificationsare the same, the extra information needed depends on the actual classification. Forexample, for a straight or straight flush, only the highest ranking card is needed, so onlythat rank needs to be in the array. For a full house, the ranks of the triple and pairare considered, in that order, so those ranks should be in the array. And so on for theother classifications. Implemented this way, you can compare two hand descriptions tochoose the winner by first comparing the classifications; if one is higher, that one wins.If they are the same, then compare the first rank in the extra information arrays. If oneis greater, that hand wins; if not, consider the two second ranks in the array, and so on.If you get to the end of the array without finding a difference, the two hands draw.3. Despite there being nine possible classifications ranging from high card up to straightflush, there are really only three things you need to look for in a hand: straights, flushes,and n-of-a-kind. I suggest writing a method for each of these.4. Only for flushes do the suits of the cards matter; when looking for runs and n-of-akinds it is only necessary to consider the ranks of the cards. Also notice that both ofthese are much easier to check for if the ranks are sorted first. To sort an array, youcan use the standard library method java.util.Arrays.sort that takes an array ofobjects as its only argument, and leaves the array sorted. Documentation is availableat http://docs.oracle.com/javase/1.4.2/docs/api/java/util/Arrays.html. Touse this method, your class needs to implement a compareTo method, as we will discuss in lecture. Note, however, that java enums automatically implement a compareTomethod that will do what you want (as long as you enumerate the ranks in order), so ifyou define your rank type as an enum, you will be able to sort an array of ranks.Once the ranks are sorted, you can check for a run by just checking that each rank butthe first is the next greater rank than the previous rank. To look for n-of-a-kind, justlook for runs of adjacent identical ranks.To handle full houses and two pairs, you will need to find two n-of-a-kinds in a singlehand. This means your n-of-a-kind code needs to find the start and end position of the6n-of-a-kind so you can look for another one after the first one. Note that there cannotbe more than two n-of-a-kinds in a single hand (since n must be at least 2).Late PenaltiesLate submissions will incur a penalty of 0.5% of the possible value of that submission perhour late, including evening and weekend hours. This means that a perfect project thatis a bit more than 4 days
late will lose half the marks. If you have a medical or similarcompelling reason for being late, you should contact the head tutor, Nai Wang (ylu11 ATstudent.unimelb.edu.au) as early as possible to ask for an extension.Academic HonestyThis project is part of your final assessment, so cheating is not acceptable. Any form ofmaterial exchange between students, whether written, electronic or any other medium, isconsidered cheating, and so is the soliciting of help from electronic newsgroups. Providingundue assistance is considered as serious as receiving it, and in the case of similarities thatindicate exchange of more than basic ideas, formal disciplinary action will be taken for allinvolved parties.7  

admin

Author admin

More posts by admin