interlude 2 the greeps competition n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Interlude 2 - The Greeps Competition PowerPoint Presentation
Download Presentation
Interlude 2 - The Greeps Competition

Loading in 2 Seconds...

play fullscreen
1 / 40

Interlude 2 - The Greeps Competition - PowerPoint PPT Presentation


  • 241 Views
  • Uploaded on

Interlude 2 - The Greeps Competition. Bruce Chittenden. The Greeps Competition. 12.1 How to Get Started. How to Get Started (continued). Add Your Name to Greeps Class. Put your name here. /** * This method specifies the name of the author (for display on the result board). */

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Interlude 2 - The Greeps Competition' - misha


Download Now An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
add your name to greeps class
Add Your Name to Greeps Class

Put your name here

/**

* This method specifies the name of the author (for display on the result board).

*/

public static String getAuthorName()

{

return "Anonymous"; // write your name here!

}

12 2 programming your greeps
12.2 Programming Your Greeps

To program your Greeps to collect as many tomatoes as possible, you should improve their behavior. The Greep class, which is included in the scenario, already includes some behavior (albeit not very clever) that you can look at to get started.

We can see that Greep is a subclass of Creature. Class Creature provides a number of very useful methods that we can use.

rule 1
Rule 1

import greenfoot.*; // (World, Actor, GreenfootImage, and Greenfoot)

/**

* A Greep is an alien creature that likes to collect tomatoes.

*

* @author (your name here)

* @version 0.1

*/

public class Greep extends Creature

{

// Remember: you cannot extend the Greep's memory. So:

// no additional fields (other than final fields) allowed in this class!

/**

* Default constructor for testing purposes.

*/

public Greep()

{

this(null);

}

/**

* Create a Greep with its home space ship.

*/

public Greep(Ship ship)

{

super(ship);

}

Rule 1: Only change the class ‘Greep’. No other classes may be modified or created

rule 2
Rule 2

public abstract class Creature extends Actor

{

private static final double WALKING_SPEED = 5.0;

private static final int TIME_TO_SPIT = 10;

/** Indicate whether we have a tomato with us */

private boolean carryingTomato = false;

/** The creature's home ship */

private Ship ship;

private boolean moved = false;

private boolean atWater = false;

private int timeToSpit = 0;

/** General purpose memory */

private int memory;

private boolean[] flags;

  • Rule 2: No additional fields. You cannot extend the Greeps’ memory. That is: You are not allowed to add fields to the class (except final fields). You can use the one byte memory that is provided.
setflag
setFlag

/**

* Store a user defined boolean value (a "flag"). Two flags are available,

* i.e. 'flagNo' may be 1 or 2.

*/

public void setFlag(int flagNo, boolean val)

{

if(flagNo < 1 || flagNo > 2)

throw new IllegalArgumentException("flag number must be either 1 or 2");

else

flags[flagNo-1] = val;

}

getflag
getFlag

/**

* Retrieve the value of a flag. 'flagNo' can be 1 or 2.

*/

public boolean getFlag(int flagNo)

{

if(flagNo < 1 || flagNo > 2)

throw new IllegalArgumentException("flag number must be either 1 or 2");

else

return flags[flagNo-1];

}

setmemory
setMemory

/**

* Store a user defined value. Attention: even though the parameter type is int,

* only byte size values (0 <= val <= 255) are accepted.

*/

public void setMemory(int val)

{

if(val < 0 || val > 255)

throw new IllegalArgumentException("memory value must be in range [0..255]");

else

memory = val;

}

getmemory
getMemory

/**

* Retrieve a previously stored value.

*/

public int getMemory()

{

return memory;

}

rule 3
Rule 3

/**

* Do what a greep's gotta do.

*/

public void act()

{

super.act(); // do not delete! leave as first statement in act().

if (carryingTomato()) {

if(atShip()) {

dropTomato();

}

else {

turnHome();

move();

}

}

else {

move();

checkFood();

}

}

  • Rule 3: You cannot move more than once per ‘act’ round.
rule 4
Rule 4
  • Rule 4: You cannot communicate directly with other Greeps. That is: no field accesses or method calls to other Greep objects are allowed. (Greeps can communicate indirectly via the paint spots on the ground.)
rule 5
Rule 5

/**

* Is there any food here where we are? If so, try to load some!

*/

public void checkFood()

{

// check whether there's a tomato pile here

TomatoPile tomatoes = (TomatoPile) getOneIntersectingObject(TomatoPile.class);

if(tomatoes != null) {

loadTomato();

// Note: this attempts to load a tomato onto *another* Greep. It won't

// do anything if we are alone here.

}

}

  • Rule 5: No long vision. You are allowed to look at the world only at the immediate location of the Greep. Greeps are almost blind, and cannot look any further.
rule 6
Rule 6
  • Rule 6: No creation of objects. You are not allowed to create any scenario objects (instances of user-defined classes, such as Greep or Paint). Greeps have no magic powers - they cannot create things out of nothing.
rule 7
Rule 7
  • Rule 7: No tele-porting. Methods from Actor that cheat normal movement (such as setLocation) may not be used.
strategy from michael kolling
Strategy from Michael Kolling

In the handout version, Greeps just run more or less straight, and when they hit an obstacle (water or the screen edge) they are stuck and stay there.

The first thing I suggest to my students to do is to turn when they hit water, so they don’t get stuck. Then turn if you hit the screen edge.

The next thing is that Greeps can only pick up tomatoes when two of them are at the tomato pile together. So I suggest that they wait at the pile when they find one.

That is usually enough to get them started and to generate more ideas.

You can then (that will be a day or two in) also have discussion where they describe their ideas of how to improve it.

Michael

final score second run
Final Score (Second Run)

Use the total scores to determine if you Greeps logic is improving

12 3 running the competition
12.3 Running the Competition

To make the competition interesting, there should be two versions of the Greeps scenario. One gets handed out to all contestants. (This is the one included in the book scenarios.) This scenario includes three different maps. The Greeps land and forage on each of the three maps in turn. (So the challenge for contestants is to develop movement algorithms that are flexible enough to work on different maps, not just a known one.) We recommend running the competition with 10 different maps.

12 4 technicalities
12.4 Technicalities

For submissions of an entry to the judge, the easiest mechanism is that contestants submit only the Greeps.java file. The judge then copies that file into his full (10-map) scenario, recompiles and runs it.