This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Five Lines of Code and have Christian Clausen on-line!
See this thread for details.
Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Eating monsters problem solution

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
I need java source for this problem..

Eating monsters, rules:
- There are 5 monsters, each monster having 5 calories to start with.
- Each monster is served a packet of food per round
- The food packet contains everything from 0 to 2 calories
- Each monster waits some random time before starting to eat their food
- When the food is eaten by a monster, it's number of calories will
increase with the number of calories contained in the food packet
- A monster will burn one calorie each time it eats
- Statistically, every 5th packet of food is poisoned
- If a monster eats a poisoned packet of food, it will loose that number of calories
- All monsters must finish eating before the next round of servings
- The strongest monsters eats statistically first, the time to wait from they
are served their food is calculated from how many calories they have in them.
- One monster will also steal food from another random monster per round of serving.
It is the first monster waking up that will steal from the others. This is done before
it will eat its own packet of food.
- If either the monsters food or the stolen food, the combimed food packet
will also be poisoned.
- A monster is dead if it no longer has any calories, and it will no
longer be a participant in the food fight

Out put example :
Monster 0 stole the food from monster 3
Oh no, monster 1 was poisoned: 2 calories left
monster 0(6) monster 1(2) monster 2(4) monster 3(4) monster 4(6)
Monster 2 stole the food from monster 4
Oh no, monster 2 was poisoned: 1 calorie left
monster 0(6) monster 1(3) monster 2(1) monster 3(3) monster 4(5)
Monster 4 stole the food from monster 1
Oh no, monster 4 was poisoned: 3 calories left
Oh no, monster 3 was poisoned: 2 calories left
Oh no, monster 2 was poisoned and died
monster 0(6) monster 1(2) monster 2(X) monster 3(2) monster 4(3)
Monster 0 stole the food from monster 1
Oh no, monster 4 was poisoned and died
monster 0(8) monster 1(2) monster 2(X) monster 3(1) monster 4(X)
Monster 1 stole the food from monster 0
monster 0(7) monster 1(2) monster 2(X) monster 3(X) monster 4(X)
Monster 1 stole the food from monster 0
monster 0(7) monster 1(5) monster 2(X) monster 3(X) monster 4(X)
Monster 0 stole the food from monster 1
monster 0(6) monster 1(5) monster 2(X) monster 3(X) monster 4(X)
Monster 0 stole the food from monster 1
monster 0(7) monster 1(5) monster 2(X) monster 3(X) monster 4(X)
Monster 0 stole the food from monster 1
monster 0(7) monster 1(5) monster 2(X) monster 3(X) monster 4(X)
Monster 1 stole the food from monster 0
Oh no, monster 1 was poisoned: 3 calories left
monster 0(7) monster 1(3) monster 2(X) monster 3(X) monster 4(X)
Monster 1 stole the food from monster 0
Oh no, monster 1 was poisoned and died
monster 0(7) monster 1(X) monster 2(X) monster 3(X) monster 4(X)
The winner is monster 0 with 7 calories left
[ November 24, 2008: Message edited by: Bear Bibeault ]
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please remember that JavaRanch is NotACodeMill and you are always encouraged to DoYourOwnHomework.

So if you can tell us what you have written so far and ask a more direct question if you are stuck we will help all we can.
 
Marshal
Posts: 69748
277
  • Mark post as helpful
  • send pies
  • Report post to moderator
And welcome to JavaRanch and Beginners'
 
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Report post to moderator
Welcome to JavaRanch, if you are having problems starting off I would recommend using a PriorityQueue to hold each monster with the priority set based on the monsters strength.

Hope this gets you started, sounds like a fun assignment compared to a lot of other ones I've seen handed out.
 
lowercase baba
Posts: 12869
62
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Report post to moderator
This is a duplicate of this thread.
 
Campbell Ritchie
Marshal
Posts: 69748
277
  • Mark post as helpful
  • send pies
  • Report post to moderator
No it isn't, that thread is a duplicate of this one. This thread's getting closed, anyway.
 
I like tacos! And this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic