initial commit
[applet-bots.git] / applets / gatherers.html
blobd83f66e1c186eb86c8f3823bcf8f9250a2f058f6
1 <html>
2 <head>
3 <title>Gatherers</title>
4 <link rel="stylesheet" type="text/css" href="../styles.css"/>
5 </head>
6 <body>
7 <div id="content">
8 <h2>Gatherers</h2>
9 <h3>Agent Algorithm</h3>
10 <p>
11 A gatherer agent chooses the closest visible piece of food
12 that is currently not being carried by anyone (and is not
13 already in the agent's home base) and accelerates towards it.
14 If no "uncarried" food can be found, the agent tries to find
15 food carried by a member of the opposing team to accelerate
16 towards. If no food is visible the agent sets his acceleration
17 to a random vector to search for food. When it gets close
18 enough to pick up a piece of food, it picks it up and carries
19 it towards its home base corner for 20 time cycles, and drops
20 it again. The gatherer must then rest for 10 time cycles
21 before picking up another piece of food. During these 10
22 time cycles, the "exhausted" agent does not accelerate.
23 </p>
24 <h4>Pseudocode</h4>
25 <div class="pseudocode">
26 <pre>if have food
27 if have carried food for 20 time cycles
28 drop food
29 else
30 accelerate towards home base
31 else if have rested for 10 time cycles
32 if can see uncarried food not in home base
33 if am close enough to pick it up
34 pick up food
35 else
36 accelerate towards closest uncarried food
37 else if can see food carried by opponent
38 accelerate towards opponent with food
39 else
40 accelerate in random direction
41 else
42 set acceleration to zero</pre>
43 </div>
44 <h3>Observed Behavior</h3>
45 <p>
46 The result of this algorithm is a kind of "Capture the Flag"
47 game, except with multiple flags (and that the flags are called
48 "food"). The applet is set to stop play if one team wins the game
49 by getting all the food items into its home base.
50 </p>
51 <p>
52 Since one agent cannot carry a piece of food from the
53 opponent's base without setting it down and resting for a bit, it
54 is very likely that if an attempt is made by lone agent to steal
55 a piece of food from the opponents' base, the food with be
56 snatched back up by the enemy when he sets it down to rest. So,
57 of course, the better strategy is to steal food in teams of two
58 or more.
59 </p>
60 <p>
61 If the teams have close to the same number of members, the
62 result is pretty much a stalemate. However, if the teams are
63 significantly unevenly matched, one will almost always win.
64 If there are too many players on a team, they can get in
65 the way and hinder, rather than help, efforts. Another problem
66 that happens (especially when team sizes are high) is that agents
67 get trapped in their own bases because they don't know to pick up
68 a piece of food that is in their way. Since the pieces of food are
69 defined as stationary by default, colliding with them does no good
70 to free trapped agents. A trapped agent will only be freed if an
71 opponent removes one of the pieces of food blocking his path.
72 </p>
73 <p>
74 One unexpected observation is the benefit of the default drop
75 spot (the place the food is placed when the agent drops it) being
76 directly in front (in the direction of the velocity vector) of the
77 agent. What often happens is that an agent carrying a piece of
78 food will be pursued by one or more of his opponents. When the
79 agent drops the food to rest, his body is between the food and the
80 pursuers, so unless his opponents can figure a way to go around
81 him and pick up the food within 10 time cycles, the agent can
82 simply pick up the food again and continue!
83 </p>
84 <p>
85 For added fun, try unchecking the "Stationary Food" box to allow
86 the food to drift around and respond to collisions. The resulting
87 behavior is that several agents from a team take on "food control
88 duty" and stay around the home base moving food back inside that
89 has drifted out. If the ratio of agents to food is sufficiently
90 low, "food containment" will occupy all of their time, and there
91 will be no missions to steal the other team's food at all!
92 </p>
93 <h3>The Applet</h3>
94 <applet archive="../dist/appletbots.jar"
95 code="appletbots.gatherers.GatherersApplet"
96 alt="Gatherers Applet"
97 width="600"
98 height="450">
99 <div>
100 If you see this, you need to either enable java, or install the Sun Java
101 Virtual Machine in your browser. To do so,
102 <a href="http://java.sun.com/getjava/download.html">click here</a>.
103 </div>
104 </applet>
105 <h3>Source Code</h3>
106 <ul>
107 <li>
108 <a href="../src/GatherersApplet.java.html">GatherersApplet.java</a>
109 </li>
110 <li>
111 <a href="../src/Gatherer.java.html">Gatherer.java</a>
112 </li>
113 <li>
114 <a href="../src/Food.java.html">Food.java</a>
115 </li>
116 <li>
117 <a href="../src/GatherersWorld.java.html">GatherersWorld.java</a>
118 </li>
119 </ul>
120 <a href="../" class="return">Back to the Applet Bots Home</a>
121 </div>
122 <div class="official">
123 The official version of this file is at <a href="http://applet-bots.sourceforge.net/applets/gatherers.html">applet-bots.sourceforge.net</a>
124 <a href="http://sourceforge.net" class="sf-logo"><img border="0" alt="SourceForge.net Logo" src="http://sflogo.sourceforge.net/sflogo.php?group_id=205988&amp;type=1"/></a>
125 </div>
126 </body>
127 </html>