Advertisement
Guest User

Untitled

a guest
Nov 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.50 KB | None | 0 0
  1. 2. Task Specification
  2. You will develop, in Java, a multi-threaded card playing simulation. Within your design you will
  3. need to implement (at least) a thread-safe Card class and a thread-safe Player class
  4. (depending upon your design, you may also implement additional classes, for instance a
  5. CardDeck class). You will also develop an executable CardGame class.
  6. The game has n players, each numbered 1 to n (which for clarity in the illustration below are
  7. named player1, player2, … , playern), with n being a positive integer, and n decks of cards, again,
  8. each numbered 1 to n (which for clarity in the illustration below are named deck1, deck2, … ,
  9. deckn). Each player will hold a hand of 4 cards. Both these hands and the decks will be drawn
  10. from a pack which contains 8n cards. Each card has a face value (denomination) of a nonnegative
  11. integer1.
  12. The decks and players will form a ring topology (see illustration in the figure below for the case
  13. where n = 4). At the start of the game, each player will be distributed four cards in a round-robin
  14. 3
  15. If a player does not start with a winning hand, they will implement a simple game strategy, as
  16. specified below (note, the strategy is not optimal).
  17. Each player will prefer certain card denominations, which reflect their index value, e.g., player1
  18. will prefer 1s, player2 will prefer 2s, etc. After drawing a card from their left, a player will discard
  19. one of their cards to the deck on their right, (e.g. player2 will draw from deck2 and discard to
  20. deck3). The card they discard must display a value which is not of their preferred denomination.
  21. Additionally, a player must not hold onto a non-preferred denomination card indefinitely, so you
  22. must implement your Player class to reflect this restriction (otherwise the game may stagnate).
  23. Developing a solution
  24. You will need to implement an executable class called CardGame, whose main method requests
  25. via the command line (terminal window) the number of players in the game (i.e. ‘n’), and on
  26. receiving this, the location of a valid input pack. A valid input pack is a plain text file, where each
  27. row contains a single non-negative integer value, and has 8n rows. After reading in the input
  28. pack, the CardGame class should distribute the hands to the players, fill the decks and start the
  29. required threads for the players. If the pack is invalid, the program should inform the user of this,
  30. and request a valid pack file.
  31. As a player processes their hand, each of its actions should be printed to an output file which is
  32. named after that particular player (i.e. the output file for the first player should be named
  33. player1_output.txt). In game actions should be printed to the file in a similar form to the
  34. following example:
  35. player 2 draws a 4 from deck 2
  36. player 2 discards a 3 to deck 3
  37. player 2 current hand is 1 1 2 4
  38. Additionally, at the start of the game the first line of the file should give the hand dealt, e.g.
  39. player 2 initial hand 1 1 2 3
  40. and at the end of the game the last lines of the file should read either:
  41. player 2 wins
  42. player 2 exits
  43. player 2 final hand: 2 2 2 2
  44. if for instance player 2 wins, or
  45. player 3 has informed player 2 that player 3 has won
  46. player 2 exits
  47. player 2 hand: 2 2 3 5
  48. in the case where player 3 has won (and the values displayed match the hands and decks
  49. concerned). There should also be a message printed to the terminal window (as is the case when
  50. a player wins immediately), i.e. if the 4th player wins, then
  51. player 4 wins
  52. 4
  53. should be printed to the screen. There should only be one player declaring it has won for any
  54. single game. If the game is won immediately (a winning hand is initially dealt), the output files
  55. should still be written for all players (although each file will only contain four lines). In addition
  56. to the player output files, there should also be n deck output file written at the end of the game
  57. (named, e.g. deck1_output.txt), which should contain a single line of text detailing the contents of
  58. the deck at the end of the game, e.g.
  59. deck2 contents: 1 3 3 7
  60. The combination of a card draw and a discard should be treated as a single atomic action.
  61. Therefore at the end of the game every player should hold four cards, and every deck should
  62. contain four cards. The program developed should follow the object_oriented paradigm.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement