subject

Multithreaded application: Elephant vs Mouse It is common knowledge that elephants are deathly afraid of mice. What is not so common knowledge is the reason why. Clearly it can't be that the elephant is afraid of stepping on the mouse as the mouse cannot, in any way, pose a risk to the substantially larger mammal in such an encounter. Some argue that the reason is that the elephant is afraid that the mouse will go inside its trunk. This is ridiculous because in one simple puff the elephant could eject the mouse for several hundred yards. In fact, this would seem the perfect way to deal with mice: when they approach, simply snort them up gently and then blow them out as far as you can. Multiple mice could be handled simultaneously. Heck, the elephants could set up competitions for distance or quantity.
The real reason is that mice have a strong taste for elephant flesh. Although there have been no visual recordings of mice attacking elephants as a tasty snack it does in fact happen. What's more surprising is that the mice have a very strong appetite for elephants. It only requires two mice to devour a single adult male elephant (clearly competitions involving quantity is not a good idea for the elephants). It's not a pretty sight either. Faced against the voracious feeding frenzy of a pair of mice the elephant has no hope of survival. A single mouse cannot take on an elephant and survive so they must coordinate their attack. The coordination is quite simple.
Using a multithreaded application written in Java you are to simulate mice hunting elephants in the wild:
Instructions:
You are to use three different thread functions. One to represent elephant, one for mice and the original main thread. The hunt occurs on a discrete, square grid.
The dimensions of the grid are passed as the first two command line arguments. The third is the striking distance. The fourth is the number of elephants spawned at the start and fifth is the number of mice spawned at the start. The command C:/> java hunt 300 400 6 4 7 results in a grid that is 300 squares wide and 400 squares tall. The striking distance is set to 6 units. There are 4 elephants and 7 mice at the start.
Animals can move and be snot shot launched in eight directions. The directions are the same as those that a king or queen can move in chess. Adjacent squares in the diagonal direction are considered to be separated by a distance of 1 unit for purposes of movement.
Mice are sneaky and fast. They make two moves for every move the elephant makes. An animal can only move to a square adjacent to the square it currently occupies. Elephants start in random squares.
The mice start in random squares not already occupied by an elephant. Every time an animal moves itself it prints its movement to stdout in the format: Mouse 2 to 233 345 or Elephant 1 to 223 345.
The hunt ends when elephants have been eaten. Note that mice die because of starvation. Also for distance, For movement and throwing all distances are discrete squares, regardless of direction. Like kings and queens in chess. For measurements, such as farther and within, the distance is computed according to the standard formula \sqrt{\left(x1-x2\right)^2+\left(y1 -y2\right)^2}
The game occurs on a global 2-dimensional array of squares. java. math. Random is a good random number generator.
Some rules for the movement:
Mice basically move randomly unless they aren't alone and within striking distance of the elephant in which case they attack -If the mouse is not within striking distance of the elephant then it moves to a random adjacent square.
If the mouse is within the striking distance of the elephant then:
A) If the mouse is within the striking distance of the other mouse then the mouse is not alone and makes a move that brings it as close to the elephant as possible.
B) Otherwise, the mouse is alone and it freezes and stands still for fear of being launched with snot all over itself.
The elephant is basically afraid of mice and seeks to maximize its closest distance to a mouse. But he's also irrational so his movement is always random.
If the elephant finds a single mouse on itself occupies the same square as itself then the elephant simply snorts it up and ejects it in a random direction a distance equal to twice the striking distance not to exceed the edges of the board. After such an act the elephant makes his move normally.
If a mouse is within striking distance then it makes a random move that would increase the closest distance to any mouse. If no squares take it further away then the elephant stands still, trembling meaning that; any move that bring him closer to any mouse than he is currently would not be valid; otherwise, it makes a random move.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 15:10
David is in week 3 of his current ashford course and has a paper due by monday night at midnight. he has finished everything but the concluding paragraph. as he boots up his computer to work on it, he sees a flash across the screen and then the screen goes black. he begins to panic as he tries desperately to turn the laptop back on. david should have saved his work on what kind of portable device?
Answers: 2
question
Computers and Technology, 22.06.2019 17:00
Annie is creating a corporate report for a company’s annual meeting. in the report, she wants to add the signature of various department heads. which device can annie use to capture signatures to include in the report? a. printer b. monitor c. e-reader d. digitizing tablet
Answers: 1
question
Computers and Technology, 23.06.2019 06:10
The head restraint should be adjusted so that it reaches a.the top of your ears b.the base of your skull c.the top of the head
Answers: 1
question
Computers and Technology, 23.06.2019 07:00
Why were most movies from the late 1890s until the early 1930s only filmed in black and white? there were only a few people who could afford the technology to produce color motion pictures back then. audiences did not want color motion pictures until later. the film used to make color motion pictures often overheated, which was a safety hazard, so it was generally not allowed. color films had to be hand-colored, frame by frame.
Answers: 3
You know the right answer?
Multithreaded application: Elephant vs Mouse It is common knowledge that elephants are deathly afra...
Questions
question
Mathematics, 20.09.2019 19:20
question
Mathematics, 20.09.2019 19:20
question
English, 20.09.2019 19:20
Questions on the website: 13722362