Greeps

advertisement
Greeps
A programming Competition
Greeps
• Description
• Greeps Scenario (a .zip file)
• Project 1: modify the Greeps class to increase
your score in the competition
• On-line hint
• Greeps.java
Methods Provided
Greep class
act()
checkFood()
getAuthorName()
Creature class
Actor class
atShip()
atWater()
atWorldEdge()
carryingTomato()
dropTomato()
getFlag(int flagNo)
getMemory()
loadTomato()
move()
randomChance(int percent)
removeTomato()
seePaint(java.lang.String color)
setFlag(int flagNo, boolean val)
setMemory(int val)
spit(java.lang.String color)
turn(int angle)
turnHome()
getIntersectingObjects
(java.lang.Class cls)
getOneIntersectingObject
(java.lang.Class cls)
getRotation()
getWorld()
getX()
getY()
setLocation(int x, int y)
setRotation(int rotation
…
Turning
public void act ()
{
turn (5);
}
Where the action is: act ()
Current plan
if (carryingTomato()) {
if(atShip()) {
dropTomato();
}
else {
turnHome();
move();
}
}
else {
move();
checkFood();
}
}
Possible problems
reaching the world boundary
reaching water
Possible changes
if(atWater() || atWorldEdge()) {
turn (????);
}
Possible States and Strategies
With Respect to the Tomatoes
With Respect to obstacles/location
1) Holding a tomato
Go home (and leave a trail?)
1) At water’s edge
Turn?
Move?
Leave a trail?
Follow a trail?
2) Not holding nor near a tomato
Search for tomatoes (follow a trail?)
3) At a pile of tomatoes
Wait there until they are gone?
2) At world’s edge
Turn?
Move?
Leave a trail?
Follow a trail?
3) At ship (after dropping tomatoes)
Turn?
Move?
Leave a trail?
Follow a trail?
What To Do
1. Devise a strategy
Due Today
– What to do in each state
– How to use “spit” (3 colors)
– How to use memory (1 int variable)
2. Implement your strategy as a program
– Be prepared to make changes
– Report your progress
Due Next Class
3. Test and refine your program
– Turn in final program
Due Next Tuesday
@ midnight
Example Error Messages
1. ‘;’ expected
2. cannot find symbol - method Move()
3. turn(int) in Creature cannot be applied to
(int,int)
4. turn(int) in Creature cannot be applied to
(double)
5. act() in Greep cannot override act() in
Creature; attempting to use incompatible
return type
Download
Random flashcards
Nomads

17 Cards

Marketing

46 Cards

Create flashcards