Shall we play?

  • 18
  • Locked
Three people play the game. Each player (Gamer) is characterized by two parameters: last name (name) and the actions-per-second (rating). Display the actions taken and determine the winner and the losers. Let's begin... 1. Figure out what the program does. 1.1. List actions stores the sequen
You can't complete this task, because you're not signed in.
Comments (11)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Karas Java Developer
16 September, 22:35
Hope I am not giving it away, some pointers, if you are at this level, will be able to figure out what I say here: Use enhanced loop to iterate through all of the list of actions, when it reaches the final item thats the end of the game. Put all the threads to sleep divided by the rate of the player. Do not forget sleep throws an interrupted exeption... catch it and use it to display a custom message... Check isWinner otherwise set it and display the final message. Easy 18 pieces of dark matter.
Justin Smith
Level 19 , Greenfield, USA, United States
14 September, 15:47
This task is poorly defined. Do they want it to sleep before or after printing a message? It doesn't say, and it makes a big difference on the output. It turns out it is before. So pretend there is a requirement 2.25 that says "Each message should be displayed AFTER the thread is told to sleep." There are also several ways of going through it that produce the correct results, but the validation is specifically looking for a for-loop. If you do it differently, it won't pass validation.
DarthGizka
Level 24 , Wittenberg, Germany
5 June, 11:50
task1627 (Shall we play?) validation failure: validation of the requirement The run methods of all players who did not win (those who were interrupted) should display [getName() + ":lost"]. For example: [Gates:lost] seems to be broken. Here's the tail of what my code prints (via println):
Gates:Kill enemies
Gates:won!
Smith:lost
Jones:lost
This is exactly what the requirement says. I also tried several obvious variations (blank after the colon, exclamation mark at the end and so on) but to no avail. Can anyone help? @@@ SOLVED! @@@ With the help of Guadalupe I managed to isolate the problem, which was that my players did not wait for an interrupt to declare that they lost (instead they exited their game loops and printed the "lost" messages as soon as isWinnerFound became true). Ergo: the losing players must wait for the interrupt before they print their "lost" messages.
Jurij Thmsn
Level 26 , Flensburg, Germany
23 March, 15:38
I don't understand the logic of the validation criteria on this exercise. Why do I need an extra check for the isWinnerFound boolean within the Gamer run() implementation? The OnlineGame run() implementation already prevents the "losers" of printing "winner". And why do I have to use [Thread.sleep()] and not simply [sleep()] in the gamers' run() implementation? It doesn't change output and seems illogical to me. Nice exercise apart from that.
Maria
Level 22 , Moscow, Russian Federation
15 April, 10:49
Agree!)
Roman Grygorczuk
Level 19 , Cracow, Poland
7 February, 20:34
if you have been having problem with validating a third step then think about the sequence of calling OnlineGame.isWinnerFound
Liliane Top Backend Developer at Procura
26 December 2020, 11:30
Tip. If you get the validation suggestion that : At regular intervals (1000ms/rating), the Gamer class's run method should display the player's last name (getName()), followed by a colon, and then the text in OnlineGame.actions. Example: [Smith:Game start] do NOT change the text of the first action as you will fail the test. The first action should remain Start game. Maybe the validation suggestion can be corrected?
Switch/Cypher
Level 25 , Bexleyheath, United Kingdom
29 September 2020, 18:05
Something I learnt here. Sending an interrupt() triggers an Interruption exception, but doesn't actually stop the thread from running.
Baurzhan Konurbayev
Level 40 , United States
11 August 2020, 03:53
Curious how race conditions is not the case here, because checking and increment of isWinnerFound variable is not atomic operation. Is it because sleep duration is good enough?
Lukaniek
Level 16 , Wadowice, Poland
24 June 2019, 17:59
Hi guys, could You please take a look what is wrong here? I have absolutely no idea why it's not verifying even I get good result
Roman
Level 41
25 June 2019, 05:33
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.