(updated 3:45am PST, 6-20-2009
Due to possible time constrants and non-availability to a computer, the source code for this projects is released early.
See bottom of this message for the attachment (revision: updated 5:25am PST, 6-19-2009
Latest version now CADArmyAnts-V0.10b.zip, modified section on ACP code and input parameteres)Welcome Recruits to your basic training of being an ant! As recruits you will learn how to most
effectively locate food and bring it back to your ant hill. This will be your only goal during basic
training. Lower scores mean more effective food collection.
During training you will write an Ant Controller Program (ACP) using lisp. The simulator will call
your ACP
for each ant that is at the proving grounds. Ants have limited visibility of 2 squares
(grid units) around them. They can see other ants, food, and obstacles, and smell scent trails
that other ants may have left behind.
Using only the local knowledge provided to the ACP,
the ACP will order the ant to carry out an action.
ACP Data InputThe environment data sent to the ACP, about the current ant, is contained in 8 lists. Each list is a
5 x 5
matrix with sublist rows, and your current ant is located in position 3 x 3. The lists and possible values are:
Main Map | 1 = Location of your ant hills |
| -1 = Location of opponents ant hills |
| -99 = Impassible cell (rocks) |
| 0 = Open space |
Food Map | Location of food items, number will represent amount |
My Ant Map | Location of your ants, there will always be one at 3,3 |
Opponent's Ant Map | Location of opponents ants |
My Scent Map | Where and how much scent your ants have deposited. The number in each cell is decremented by one every cycle. |
Opponent's Scent Map | Where and how much scent your opponents have deposited. The number in each cell decrements by one each cycle |
My Death Map | Where and how much death scent has been deposited by your ants. The number in each cell decrements by one each cycle |
Opponent's Death Map | Where and how much death scent has been deposited by the opponent's ants. The number in each cell is decremented by one every cycle. |
** While in basic training lists about opponents is irrelevant and are only meaningful in future training exercises. **ACP Data OutputUsing just the information provided during the current round your ACP will return an order to the simulation in
in the form of a list:
(list Row Col Action Mark)
The meaning and possible values are:
Row | -1 = Up one (north) |
| 0 = No move (north) |
| 1 = down one (south) |
Col | -1 = Left one (west) |
| 0 = No move (south) |
| 1 = Right one (east) |
Action | -1 = Attack |
| 0 = No action |
| 1 = Ant will attempt to carry a food item |
Mark | 0 true 100 = Amount of scent to leave behind |
** Note: Ants can only attack if it is not moving. Orders that have both move and attack will be carried
out as a move only **** Note: In basic training, orders to attack will in effect be a no action - action **Local ACP Input Grid SampleO | O | O | O | O | S=15 | O | R | F=4 | O | O | O | A=2 | O | A=6 | O | F=10 | O | O | R | AH | O | O | O | S=5 |
|
The grid layout shows 15 scent units at 1,2; a rock at 3,2; 4 food units at 4,2;
2 ants at 3,3 (one is the current ant, the other a teammate); 6 team ants at 5,3;
10 food units at 2,4; a rock at 5,4; your teams ant hill at 1,5;and 5 scent units at 5,5
ACP CodeThis a about as simple as an ACP you can have. ACP's must be written to accept
8 parameters, otherwise the simulator will halt.
(defun c:MyAntController (mainMap foodMap myAntMap opAntMap
myScentMap opScentMap mydeathMap opDeathMap / )
(setq row 0 col 0 action 0 mark 0)
(list row col action mark)
)
Using the parameter decoding information and the local grid sample, the list would look
as follows:
mainMap | ( (0 0 0 0 0) (0 0 -99 0 0) (0 0 0 0 0) (0 0 0 0 -99) (1 0 0 0 0) ) |
foodMap | ( (0 0 0 0 0) (0 0 0 4 0) (0 0 0 0 0) (0 10 0 0 0) (0 0 0 0 0) ) |
myAntMap | ( (0 0 0 0 0) (0 0 0 0 0) (0 0 2 0 6) (0 0 0 0 0) (0 0 0 0 0) ) |
opAntMap | ( (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) ) |
myScentMap | ( (0 0 0 0 0) (15 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 5) ) |
opScentMap | ( (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) ) |
myDeathMap | ( (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) ) |
opDeathMap | ( (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) (0 0 0 0 0) ) |
** Again for basic training information about opponents can be ignored **NOTE: Table updated for version 0.10bRegistering Your ACP With the SimulatorTo register the above sample with the simulator is a two step process, and only needs
to be done with a new drawing or when a drawing is opened. First the function must be
made into an exported function symbol:
(vl-acad-defun 'myAntController)
This allows your ACP to be callable with the simulator, but it still needs to be registered
with the simulator:
(ants_register_controller "c:myAntController")
Now you are ready to run a simulation using the ants_run command.
Running a SimulationThe command to run a simulation is:
(ants_run [map] [realtimeGraphics] [cycles] [sleep] [runAllCycles] [serverMode])
The parameters in brackets are optional, with the most useful near the front. The current
simulator support 5 built in maps (1 - 5) and 1 user map (0). To run a simulation with
map 3, reatimegraphics on, 500 cycles, and a 1/4 second pause between cycles is:
(ants_run 3 1 500 250)
I'll refer you to the "CAD_Army_Ants-r5.pdf" documentation and the "antsSample.lsp" file enclosed
with the download for full details on all available commands and their options.
Submitting a Code Entry to the ForumTo make it as easy as possible for forum members to run and test code submissions the code
should have the following form: Only 1 global ACP function. Any subroutines needed by
the ACP should be local in scope to the ACP function. The code should be commented to
describe it behavior, and your name or forum handle. Along with the ACP function the
code will also define the exported function symbol and automatically register it with the
simulator. Here is a full working example:
;;; xyzMyAntController, about the lazest ants around. They don't do a thing
(defun c:xyzMyAntController (mainMap foodMap myAntMap opAntMap
myScentMap opScentMap mydeathMap opDeathMap / )
(defun myLocalScopeFunction ( / )
(princ))
(setq row 0 col 0 action 0 mark 0)
(list row col action mark)
)
;;; automatically export myAntController as a function symbol
(vl-acad-defun 'myAntController)
;;; automatically register with the simulator when the lisp file is loaded
(ants_register_controller "c:myAntController")
Code Submission and Modifying Existing Submitted CodeSubmit your code as a new post to this thread. Wrap the code in forum
blocks to make it stand out better. Also submit the simulation result list, printed
at the command line after a simulation, wrapped in its own code block as well. Users can
then look at this value to see how efficient the ACP is. The format of the returned
list is:
(Map# #Teams Team1Name Team1Score #CyclesToRun #ActualCyclesRan) (Map# #Teams Team1Name Team1Score #CyclesToRun #ActualCyclesRan TotalFood Team1CollectedFood)
Note: this was revised for version 0.9b of CADArmyAnts.ARX Do not edit submitted code and results once posted. If you have improvements to the
code then submit it as a new message, and make sure the ACP function name is unique.
Anyone can view and copy code that is already submitted. If you make improvements to
code that is already submit, then you are the author of the code for scoring purposes.
You are encouraged to optimized existing entries.
ScoringScoring is based on moving food items to your ant hill(s). At the end of each cycle
the total Euclidean distance is calculated between all food items to the nearest team
ant hill. The overall current running score will be the average of the end of previous cycle
results, and averaged.
Simply put, the lower your score the closer all food items are
to you hill.
GuidelinesFor those that plan to submit ACP results and code to the forum I'd like to offer some
guidelines for everyone to follow.
- Your ACP will only use the simulation data provided to it during the current cycle, previous
cycle data and results will not be retained and used in future cycles. - The ACP function should be the only global function, if your ACP needs extra functions, like
an RNG or something, then make them local to the ACP function. - Make your ACP function names unique so they are identifiable. The initials of your name will
probably be good enough. Just need to keep them identifiable for scoring purposes. - When submitting ACP simulation results to the group use the returned list printed at the command line.
Just copy and paste it to a new message. These can then be collected and made into some sort of
score board or something. The returned list meaning is:
(Map# #Teams Team1Name Team1Score #CyclesToRun #ActualCyclesRan)
(Map# #Teams Team1Name Team1Score #CyclesToRun #ActualCyclesRan TotalFood Team1CollectedFood)
Note: revised for verion 0.9b of CADArmyAnts.zip
- If you submit runtime results, then submit the code as well. This will benifit the colony.
See "Code Submission and Modifying Existing Submitted Code" section for details to improve its visiblity in the forum. - To qualify for placement standings, results submitted need to be run with a cycle count of 1000
- Lets let this run until June 28, 2009 with complete code sharing and collaboration with others, using
maps 1-5. At midnight of the 29th, a single new map will be posted to the forum and for the next
24 hours post your code, results, and optimizations. The ACP with the lowest score after 24
is the proclaimed winner.
Starting the SimulatorThe simulator is an ARX application. Do an "appload" and find the ArmyAnts.ARX that will run in your
version of AutoCAD. If you are running AutoCAD 2004 - 2006 then use the binary located in
\CADArmyAnts\Bin\A2004\ArmyAnts.ARXand if your using AutoCAD 2007 - 2009 use
\CADArmyAnts\Bin\A2007\ArmyAnts.ARXIn the \CADArmyAnts\ directory is the "antsSample.lsp" to help you get started. Also, "SampleMapBuild.lsp"
can get you started with building your own maps. Pretty much everything you want to know about
the program, functions, and parameters can be found in "CAD_Army_Ants-r5.pdf".
Sorry, but I don't have any AutoCAD 2010 binaries to distribute. If someone would like to compile the
simulator for that version, I'll be more than happy to send the source code.Finding and Reporting BugsHate to say it, but you might find one or two. If you do, shoot me a personal message as
as soon as possible. Include the version of AutoCAD your running, a description of the bug, and what
might have triggered it, and if it is something with messed up graphics while the simulator is running
then send me the dwg file as well. I'll fix it as fast as I can and post revised binaries to this message.
Source CodeThe source code for the simulator will be posted on June 22nd. This will give enough time for any bugs
to be found and fixed, keeping the number of source revisions low.
What's the Deal With Enemy AntsThat's for after basic training. The next round will put team against team. It's already built into the
simulator.
Have fun and TIA.
Paul