• Post Reply Bookmark Topic Watch Topic
  • New Topic

Fox hates rabbits  RSS feed

 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,
Im doing an exercise called foxes and rabbits, where they mostly walk around randomly, but foxes search and hunt for rabbits. Main classes I work on are Fox, Sabbit and Simulator class. Here is the method in fox class for foxes to find rabbits



and this method is for fox to act, ie. see if there is any rabbit closeby, and if there is any go for it, but if there isnt any, move randomly.



Now, lets assume foxes hate rabbits and want to stay away from them. (i.e. if there is any rabbit closeby, try to run away to another location).
Which of these classes do I need to change in this case? Where do I need to focus. I feel like im lost. Or do am I looking to wrong methods? Can you guys give me some hints please.

Thank you.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hans Baba wrote:
Now, lets assume foxes hate rabbits and want to stay away from them. (i.e. if there is any rabbit closeby, try to run away to another location).
Which of these classes do I need to change in this case? Where do I need to focus. I feel like im lost. Or do am I looking to wrong methods? Can you guys give me some hints please.


Well, for one thing, you have to not have the fox kill the rabbit -- so, that would be the first change. Second, how would you deal with starvation, as the fox does seem to get hungry.

Third, your algorithm to find food would have to be enhanced. It will need to be modified to run away. The algorithm to go (and eat) food is simple. However, to move away from the rabbit is a lot harder. What happens when there are more than one adjacent rabbits? What should you do? It isn't as simple as picking a rabbit and running in the opposite direction.

Henry
 
Hans Baba
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens when there are more than one adjacent rabbits? What should you do?


Okayn if there is no way to escape then they just stay at the same location.
Also, i am not very clear about findFood() method, can someone tell what really happens in there? I mean, can you tell that in English, not in Java?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!