botsworld

 
Move your mouse into this window

Click to stop all animation

 

This applet displays some randomly generated mobile colored polygons, or bots. Each bot is controlled by a separate thread (of class Bot). Each bot pays attention to where it is, where the mouse is, and whether it's about to hit the container walls or another bot.
Parameters: numBots (the number of bots to be displayed; default = 1)
Globals: offscreen, thingy[], numBots
Public Methods:

* init()
* mouseMove()
* update()
* paint()
Implementation Comments

Mac Java can't create many simultaneous threads. On the Mac, giving Java 6MBs only buys you about 40 bots. Further, that number depends on the size of the bots created. In a 500x500 display, the Mac can only support about 5 big bots, but about 50 small ones. Finally, the higher the number, the more likely the display is to freeze when the mouse is moved (threads are starved for cycles) and as the number increases the whole display will eventually freeze right at the beginning of the run. So there are three bottlenecks: in memory allocated, in screen update, and in mouse handling.
 
General Comments

So far this program implements the following:

* the first kind of bot sensor: "where is the mouse in relation to me?"
* the second kind of bot sensor: "where are the other bots in relation to me?"
* the first kind of bot memory: "where was the mouse on the last time step?"
* the second kind of bot memory: "where were the other bots on the last time step?"
* the first kind of bot behaviour: "move around in straight lines"
* the second kind of bot behaviour: "increase speed when the mouse approaches"
* the third kind of bot behaviour: "avoid other bots"
* the first law of bot physics: "bounce off any walls i hit and conserve momentum"
* the second law of bot physics: "every bot experiences constant friction"
Notes

Here's where i'd like to go with this: take the array of previous positions of bots plus mouse and clip it based on who is nearby.

* If none are nearby, go about your own business.
* If any are nearby, check whether any of them are moving closer.
* If there are no convergers, go about your own business.
* If there are convergers, run away in some direction not already covered by any of the convergers.
* The faster a converger approaches, the faster the bot runs away in some other direction.

Later we can add more complex avoidance-attraction behavior. For example, purple bots may be attracted to other purples and repelled by reds, but be indifferent to other colours. Similarly for size.

Perhaps bots should move in an approximation to Brownian motion? Also, when a bot hits something perhpas it should deform into a new bot? Bots should also play a sound when they hit a wall. They can also change colour briefly (or permanently?). Bots could change color as the mouse approaches too close, then change back as it goes away. Could even put a face on the bot and have it snarl or smile.

Bot shape should determine behaviour. Bots should live, reproduce, and die. Genetic change should be allowed. Bots should preferentially pay attention only to chosen subsets of the other bots rather than all bots. Subsets of bots should be encouraged to cooperate to accomplish tasks in the face of opposition from other subsets of bots.

We can make display three-dimensional and let the viewer move the viewpoint inside the container volume.

The environment should also have immobile objects in it and the mobiles should bounce off them (and each other). The immobiles should be at least partly created and destroyed by the mobiles (otherwise it's too boring).

When immobile bots are added, they should sleep longer and should redraw themselves without calling moveSelf() Or maybe they shouldn't even be separate objects? that would be more efficient but less ideologically pure.

Average human reaction time is about 1/10 of a second, so it's probably safe for each bot to sleep for 1/25 of a second per cycle (that should give about 24 fps for the animation) except that this must be biased by the number of threads running at any one time. Also need to worry about temporal aliasing of the mobiles.
 
Long-term Framework

Ultimately, i want an infinitely reconfigurable world of bots and other objects. It should be easy for other programmers to add or modify bot species to the world. In this world, each bot has different senses and those senses allow it to note what's nearby. (Note: "nearby" may be defined in different ways for each species). Some of the objects in the bot's world will be immovable, some movable.

Fun Stuff:

* The user could herd bots and pen them in, then let them escape in various constrained ways.
* The system could implement naive physics so that we could have a domino world, for example, where the user places dominoes in various places and then knocks one over. Dominoes then fall as they are hit by other dominoes.

Needed---a general Bot object.
This object has various attributes:

* position
* senses (what things it can sense about its surroundings) long-range and short-range senses to detect appearance/position
* behaviors (what things it can do) for example: follow the mouse or run away from the mouse or pick/drop a nearby immobile
* appearance (what it looks like on the screen and to its neighbours)
* weight? smell? genome? offspring?
* state (awake? asleep? happy? sad? hungry? full?)
* lifetime (how long will it live?)

Behaviors may be dependent on sensed information, which may be dependent on previous behaviors.

There are a number of species in the world and a number of other objects. Those objects also have behaviors but no senses. (There's no point having a object with senses but no behaviors.)

Objects have a state:

* movable or immovable
* appearance
* position
* velocity (if in motion) [so one bot could pelt another with a stone]
* momentum
* memory (at least of where they last were--this includes rocks)

Bots, which extends Objects, have even more state, depending on the complexity of the bot:

* hungry/full
* awake/asleep
* damaged/fit
* alive/dead

Yet more complex bots could have personality traits: (1) timidity/agression quotient

Note: could have a sign: "Do Not Prod the Tiger" and when the user inevitably prods it, it growls (like a cartoon growing from small to huge). Another idea: could have a button with a label that says "Please don't press this button" which when pressed changes to "Please don't press this button again". Or a switch and a hand with a note that say: "Please don't flip this switch" which when flipped causes the hand to flip it back.