![]() The QueueArray class is an array-based, iterable version of a queue, supporting the methods guaranteed by the Queue interface. It also overrides the toString() method so that the cards in the pile can be displayed efficiently. The Pile class is a subclass of QueueArray that adds a constructor for creating a pile of cards from a string of two-character abbreviations for the cards the pile is supposed to contain. The Card class can be used to represent individual cards from a standard deck and implements the Comparable interface, which uses the compareTo() method to compare to cards by their aforementioned rank. To this end, complete the War.java class by using the classes and interfaces described by Card.java, Pile.java, Queue.java, and QueueArray.java. You wish to simulate this game to predict on what turn the game ends and who wins given the initial states of the two players' piles. Should a player not have enough cards to complete their turn, they lose. In the unlikely event that there should still be a tie, this process is repeated until there is no tie or until someone doesn't have enough cards to continue. ![]() Should this second pair compared result again in a tie, three more face-down cards are played, and then one more face-up, with the player whose last card played is higher taking the entire stack of now 18 cards. Whenever cards are added to the bottom of a player's pile, they are always added in the exact same order as the cards were played - specifically, player 1's first card, player 2's first card, player 1's second card, etc. These last two cards added face-up are again compared, and the player with the higher card takes all of the cards on the table (10 cards in total now) and adds them to the bottom of their pile. Finally, they each add one more card, face-up. When this happens, the initial cards played stay on the table to form a small pile to which the players alternatively add their next three cards face-down. When the face-up cards on any given turn are of the same rank, there is a war. This continues until one player wins by taking all of the cards. Both players then flip over the next card in their respective piles, again moving them to the center of the table and the process is repeated. For the purposes of deciding which card is the higher card, cards are ranked in the normal way (with the Ace being the card of highest rank) : 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A. ![]() Whoever flipped over the higher ranked card takes both cards in the center and adds them to the bottom of their packet in the same order they were revealed. Player 2 does the same with the top card from his or her pile. Instead, player 1 removes the top card of his or her pile and places it face-up in the center of the table. Niether player looks at his or her cards. One wins the game by taking all of one's opponent's cards. In the card game War, a standard 52-card deck is dealt to two players so that each player ends up with a pile of 26 cards. Here are the people killed, in the order they died: ![]() Of course, if a person in the circle is killed - that's more like removing them without adding them back.Įnter the total number of people in a circle:Įvery nth person will be killed. Hints: Note how similar moving through a circle is to moving someone from the front of a line to its end. Use the QueueArray implementation of the Queue interface to accomplish this task. Write a class Josephus that prompts the user for a number of people in a circle, and a value $n$, where every $n^$ person will be killed, and then finds (using a queue) and displays the positions of those people killed, in the order they died, in a manner similar to the one shown in the sample run below. The precise mechanism for choosing the order of the executions was not completely described in Josephus' account, however in 1612 Claude Gaspar Bachet (the writer of books on mathematical puzzles and tricks that formed the basis for almost all later books on mathematical recreations) suggested that the men arranged themselves in a circle, and then started counting by threes from a randomly selected man. Josephus states that by luck or possibly the hand of God, he and another man remained until the end and surrendered to the Romans rather than killing themselves. Choosing suicide over capture, they settled on a serial method of committing suicide where each person to die would be killed by the next person to die. A Jewish historian living in the 1st century named Flavius Josephus gave an account of the siege of Yodfat, where he and his 40 soldiers were trapped in a cave by Roman soldiers. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |