fixed source code links to go to repo.or.cz repository
[applet-bots.git] / applets / friendly.html
blob0d664f6f8442140fc05a7884de1f9fda8cfafdfb
1 <html>
2 <head>
3 <title>Friendly Bots</title>
4 <link rel="stylesheet" type="text/css" href="../styles.css"/>
5 </head>
6 <body>
7 <div id="content">
8 <h2>Friendly Bots</h2>
9 <h3>Agent Algorithm</h3>
10 <p>
11 A friendly agent looks at all the other agents he can see and
12 randomly selects one to be his friend. However, he can only make
13 another agent his friend if the other agent does not already have
14 the agent selected as his friend. The friendly agent then tries
15 to move toward his friend by accelerating towards him. The agent
16 remembers who his friend is and continues to accelerate towards
17 him as long as the friend remains visible. If the agent ever
18 loses sight of his friend he simply selects another one at random
19 given the selection criteria stated above. If ever a friend
20 cannot be found the agent accelerates in a random direction to
21 search for one.
22 </p>
23 <h4>Pseudocode</h4>
24 <div class="pseudocode">
25 <pre>if !haveFriend or friend not in visibleAgents
26 availableFriends = {}
27 for all visibleAgents
28 if visibleAgent.friend != me
29 availableFriends <-- visibleAgent
30 friend = selectRandom(availableFriends)
31 if haveFriend
32 accelerate towards friend
33 else
34 accelerate in random direction</pre>
35 </div>
36 <h3>Observed Behavior</h3>
37 <p>
38 Since friendship cannot be mutual, there will never be agents
39 accelerating towards each other. An agent's friend will always be
40 trying to get to another agent (or moving about randomly searching
41 for a friend). What happens is kind of a "love triangle"
42 phenomenon where agent A is accelerating towards agent B is
43 accelerating towards agent C is accelerating towards agent A.
44 When there is enough space for one of these chains they will spin
45 around in circles chasing one another. When the chains get bigger
46 they tend to look like a snake chasing after his tail with his
47 body getting in the way.
48 </p>
49 <p>
50 Note that if the Agent Sight setting is set too high they tend
51 to choose friends that are to far away and the "friendship snakes"
52 can get knotted to the point where they can no longer move.
53 </p>
54 <h3>The Applet</h3>
55 <applet archive="../dist/appletbots.jar"
56 code="appletbots.friendly.FriendlyApplet"
57 alt="Friendly Applet"
58 width="600"
59 height="450">
60 <div>
61 If you see this, you need to either enable java, or install the Sun Java
62 Virtual Machine in your browser. To do so,
63 <a href="http://java.sun.com/getjava/download.html">click here</a>.
64 </div>
65 </applet>
66 <h3>Source Code</h3>
67 <ul>
68 <li>
69 <a href="http://repo.or.cz/w/applet-bots.git?a=blob;f=src/appletbots/friendly/FriendlyApplet.java">FriendlyApplet.java</a>
70 </li>
71 <li>
72 <a href="http://repo.or.cz/w/applet-bots.git?a=blob;f=src/appletbots/friendly/FriendlyAgent.java">FriendlyAgent.java</a>
73 </li>
74 </ul>
75 <a href="../" class="return">Back to the Applet Bots Home</a>
76 </div>
77 <div class="official">
78 The official version of this file is at <a href="http://applet-bots.sourceforge.net/applets/friendly.html">applet-bots.sourceforge.net</a>
79 <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>
80 </div>
81 </body>
82 </html>