Last modified: March 08, 2023
If you have not done Lab A4.6 Creature AI - Direct Path, Lab A4.7 Creature AI - Scouting Line of Movement and Lab A4.8 Creature AI - Wander, you should go do those first as this lab will build upon those labs.
You are writing the AI for a creature that will wander the world finding and collecting food while avoiding walls. The creature must follow these rules while collecting treats:
At this point the creature moves towards any treats it can directly reach and wanders around otherwise. This is pretty effective at eventually finding all the treats in many worlds, though it still has scenarios where it has a lot of difficulty. Here are some examples:
In this lab, you will attempt to improve your AI so it can reach all the treats faster. In order to do this, you should choose a behavior that is currently not optimal and try to improve it. You don't need to make it perfect, just make it better than the original behavior. Here are some ideas for what to look for when coming up with ideas:
You will develop and implement at least one significant new strategy. Create a google doc and make it shared with anyone with the link so a Teacher or TA can access it to give feedback. In the google doc you will write out a plan for your strategy, discuss the development process including challenges you encountered, and report on the results.
You can use the following prompts to help you develop and explain your strategy:
After attempting to implement the strategy, report on the results. Not every strategy will pan out, but if you find that a strategy didn't work, you should still explain what you tried in the description so you will have a log of ideas you attempted to implement and a detailed explanation of how you tried to implement it. Even a great idea may not seem to work initially due to ineffective implementation details. To make a strategy work optimally, you may need to go through numerous iterations and experiment with multiple tweaks before it is actually implemented effectively.
Here is an example showing how to plan out a strategy:
What is the problem you are trying to address with this strategy? Be as specific as possible.
I noticed that the Creature was sometimes blocked from reaching a treat by a wall that could be skirted past, if only it would slide off the wall instead of sticking.
What new behavior will you implement?
When finding a direct path to a treat, if the creature encounters a wall, the creature will try to move closer to the target either horizontally or vertically along the wall, rather than giving up. See the diagram below for an example showing how the sliding would work.
Predict what effect the new behavior will have? What makes you think it will solve the problem?
Since the creature will be able to move directly to treats that were previously not considered reachable, the creature will spend less time wandering randomly and will therefore find treats much faster. The creature will now be able to reach any treat that can be reached by continuously stepping closer to the target, even if it is not directly moving toward the target. It will still fail to find a direct path to targets in scenarios where the creature has to move away from the target to get around a wall.
Results
When I wrote the code, it didn't work correctly at first because the code got stuck in an infinite loop while trying to find the path to the creature. After adding a breakpoint, and observing what was happening, I could see that the creature kept moving back and forth past the x value of the treat. I resolved this issue by making the creature only move one cell at a time. This causes the creature to go slower, so it might be worth revisiting this to come up with a solution that still allows the creature to move at speed 2 without getting in an infinite loop.
PX_LastName_FirstName_Creature.java
file. For example if you were in 3rd period and named Michael Wang, then you would submit P3_Wang_Michael_Creature.java
.You must Sign In to submit to this assignment