Can any one please give me C implementation of the problem immediately if possible:
In a field there are four animals, a dog, a snake, a mouse, a mongoose..dogs kill mongoose
mongoose kills snakes
and snakes kill mice..
The speeds of the mouse snake mongoose and dog are respectively 8, 12, 18 and 30 km/hour...
simulate the chase with different starting positions (x,y) to see which animal gets killed first.......

Recommended Answers

All 6 Replies

Member Avatar for iamthwee

Well it sounds like a problem to do with speed = distance /time.

The 2d starting point might assume some use of vectors although I'm not sure.

Frankly the way you've phrased your question would suggest you have no intention of actually doing it yourself.

So you're unlikely to get much help if you can't help yourself.

Simple word problem. Just like math change your word problem into a mathematical expression.

Each animal has its own X,Y on a graph, so you'll need to enter each coordinate by keyboard.

You know...
dog > mongoose > snakes > mouse
...So you know what chases what!
Nobody is chasing the dog, and the mouse is running for its life!
Coorelate each ones speed to how fast it moves.

Ever hear of Pythgoreans Thereom? Use it to figure distance between each animal.
Also note the you have a travel time so figure out your time base! 1 Second intervals? ms Intervals? Since victims are chasing their prey, (assuming they don't know they're being chased) mouse is cracking the whip!

make the mouse aware he's being chased and have him vector towards the mongoose with some RNG.

Post your code and we'll review!

The thing is i dont get the equation to find the path of mouse..ie. the successive (X,y) positions of moust at each unit of time..can anyone provide me with the required equation
Thanking uu

You don't need the path equation. You just need the distance between the points.

Mouse runs 8km/hr.

Assuming mouse is frightened.
Snake = s, mouse = m
dy = mY-sY dx=mX-sX
So dy/dx is Direction opposite from snake.
Mouse runs 8km/hr = 8000m/hr = 133.33m/min = 2.22m/sec

How big is your grid? What is the grid spacing?
So using one second steps

Assuming dx is not zero!
you have your current mouse position, you have how far it will travel in one second 2.22meters. You have the slope m=dy/dx
Different ways of solving this, including trig.

yaa...but inorder to calculate distance we need the (x,y) co-ordinates. in problem we will be given only the initial points. so in order to calculate the distance at each moment , we need the (x,y) cordinates at each moment right??
because dist = sqrt ( (y2-y1)^2 + (x2-x1)^2)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.