/
Interlude 2 - The Greeps Competition Interlude 2 - The Greeps Competition

Interlude 2 - The Greeps Competition - PowerPoint Presentation

calandra-battersby
calandra-battersby . @calandra-battersby
Follow
433 views
Uploaded On 2017-08-13

Interlude 2 - The Greeps Competition - PPT Presentation

Bruce Chittenden The Greeps Competition 121 How to Get Started How to Get Started continued Add Your Name to Greeps Class This method specifies the name of the author for display on the result board ID: 578337

rule greeps greep class greeps rule class greep creature public map flagno private memory int methods val ship boolean

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Interlude 2 - The Greeps Competition" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Interlude 2 - The Greeps Competition

Bruce ChittendenSlide2

The Greeps CompetitionSlide3

12.1 How to Get StartedSlide4

How to Get Started (continued)Slide5

Add Your Name to Greeps Class

/**

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

*/

public static String getAuthorName()

{

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

}

Put your name hereSlide6

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.Slide7

Competition RulesSlide8

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 createdSlide9

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.Slide10

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; }Slide11

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];

}Slide12

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; }Slide13

getMemory

/**

* Retrieve a previously stored value.

*/

public int getMemory()

{

return memory;

}Slide14

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.Slide15

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.)Slide16

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.Slide17

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.Slide18

Rule 7

Rule 7

: No tele-porting. Methods from Actor that cheat normal movement (such as setLocation) may not be used.Slide19

Greeps Spitting PaintSlide20

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.

MichaelSlide21

Creature Class Methods

  Slide22

Creature Class Methods (continued)Slide23

Creature Class Methods (continued)Slide24

Creature Class Methods (continued)Slide25

Creature Class Methods (continued)Slide26

Map 1Slide27

Map 2Slide28

Map 3Slide29

Map 4Slide30

Map 5Slide31

Map 6Slide32

Map 7Slide33

Map 8Slide34

Map 9Slide35

Map 10Slide36

Tomatoes

1

2

3

4

5

6

7

Total

1

40

12

40

40

16

30

 

178

2

10

40

40

10

50

40

 

190

3

10

30

50

40

 

 

 

130

4

40

40

50

 

 

 

 

130

5

30

30

30

30

30

 

 

150

6

20

20

40

30

40

 

 

150

7

6

20

40

40

40

 

 

146

8

50

30

50

 

 

 

 

130

9

50

30

30

 

 

 

 

110

10

20

12

20

20

20

20

20

132

1446Slide37

Final Score (First Run)Slide38

Final Score (Second Run)

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

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.Slide40

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.