home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / games / ant21.zip / ANT21.INF < prev    next >
Text File  |  1991-04-04  |  16KB  |  300 lines

  1. ANTS! ant21.exe by Rudy Rucker
  2. Copyright (C) Autodesk 1991.
  3.  
  4.      This is an artificial life program inspired by the notion of
  5. "an electronic ant farm."  The ants are active graphics objects
  6. that are deterministic finite state machines with multiple inputs
  7. and outputs.  Numerous program parameters can be adjusted by
  8. using keyboard "hot keys."
  9.  
  10.      The ants interact with the environment through a single
  11. pixel-sized  read/write head.  An ant's "body" is normally drawn
  12. as a single white pixel at its head location.  There is also the
  13. option of showing an ant's body as a colored string of dots.  In
  14. this case the string's direction is the ant's current direction
  15. of motion, and the string's color corresponds to the ant's
  16. current state.  You can toggle between the two body
  17. representations with the T key.
  18.  
  19.      The ants leave trails which are either a) single colored
  20. dots, or b) colored line segments connecting two successive ant
  21. positions.  The I key toggles between these two trailmodes.
  22. Normally, all ant-trails "evaporate" or disappear after some
  23. fixed number of steps that is controlled by the "traillength"
  24. parameter, adjustable by using the L and Shift+L keys.  One can
  25. toggle the trail-erasing feature off and back on with the Shift+T
  26. key.
  27.  
  28.      With each cycle of the program each ant calculates where to
  29. move next and what kind of trail mark to leave.  The ant bodies
  30. are then erased and replaced with the correct trail marks.  Each
  31. ant then "looks" at the color of the pixel found at its new
  32. position.  Once this information is stored in their "brains," the
  33. ants redraw their bodies onto the screen.  Then the cycle repeats
  34. itself, with each ant using its new information to calculate
  35. where to move next and so on.
  36.  
  37.      The ants are grouped into 1 to 6 colonies; each colony has 2
  38. to 7 ants.  At startup we have four colonies of five ants each.
  39. In EGA or VGA mode, ants in the same colony all have the same
  40. color trails, and no two colonies have the same trailcolor.  In
  41. CGA mode there are only three possible trail colors, so different
  42. colonies may have the same trailcolor.  In general it is better
  43. to just use three colonies in CGA mode.
  44.  
  45.      An ant's calculation is really a set of lookup tables which
  46. take as input i) the ant's present state number and ii) the
  47. "readcolor", which codes the color the ant's present pixel was
  48. before the ant moved to it.
  49.  
  50.      The outputs of an ant's lookup table calculations are: i)
  51. the ant's new state number, ii) the "writecolor", which is the
  52. color or trail mark which the ant will leave on its current
  53. pixel, iii) the direction change, which is an amount by which the
  54. ant changes its direction, and iv) a (positive or negative)
  55. change in the ant's running score.
  56.  
  57.      The score change is a fixed function of the readcolor, and
  58. the function is the same for all ants in a given colony, so the
  59. computation of the score change is not really part of the
  60. behavior of an individual ant.
  61.  
  62.      Our ants have up to 256 states, and move in up to 128
  63. directions --- though the available number of directions N can
  64. also be set to 4, 6, 8, 12, 16, 32, or 64.  If an ant has N
  65. possible directions, a "change in direction" has the form  TURN
  66. LEFT 360 * I / N DEGREES, where I is a number between 0 and N-1.As our directions are given in terms of a horizontal and a
  67. vertical pixel move, the idea of degree is only a way of
  68. speaking; in fact what a change in direction really does is to
  69. move an index through two tables of possible x-changes and
  70. possible y-changes.  In the 16-direction case, we tried two
  71. different pairs of tables, one of these is distiguished as the
  72. "fast 16" direction table.
  73.  
  74.      If an ant is about to move onto a wall cell, then we forbid
  75. the move and make the ant bounce back to the cell it started
  76. from.  In this case, however, its readcolor is set to wallcolor,
  77. so the ant knows it has bounced off a wall.  In all other cases,
  78. the readcolor is based on a new cell which the ant actually moves
  79. to.
  80.  
  81.      An ant distinguishes among seven kinds of readcolors: blank,
  82. its own colony's trail color, a prey colony's trail cells, a
  83. predator colony's trail cells, walls, food cells, and crap cells.
  84. It treats the trail cells of those alien ants who are not
  85. predator or prey as no different than blank.
  86.  
  87.      An ant has three writecolor options: leave a blank, leave
  88. its own trailcolor, or leave a crap cell.  Some design decisions
  89. that cut down on the range of possible ants are the following:
  90. if the readcolor is blank, the writecolor is always the ant's own
  91. trailcolor; if the readcolor is a predator or prey trail cell the
  92. writecolor is always blank; if the readcolor is foodcolor or
  93. crapcolor the writecolor is always crapcolor.  If the readcolor
  94. happens to be the ant's own trail color, the ant has a choice of
  95. whether leave the cell alone or change it to a blank.  Thus it
  96. can erase its own trails or not.
  97.  
  98.        As mentioned above, we store our ants as three lookup
  99. tables that exhaustively specify an ant's output for each
  100. possible input.  These tables are in effect an ant's genetic
  101. material.  Two doubly indexed arrays specify the output state and
  102. the change in direction as functions of the input state and the
  103. readcolor.  And for the cases where the readcolor is the ant's
  104. own trailcolor, there is a singly indexed array to specify the
  105. writecolor as a function of the input state.  The array entries
  106. are (inefficiently) represented as bytes.  If there are S states
  107. and C possible readcolors, this means that the an ant's genetic
  108. material consists of (2*C+1)*S bytes.  In the general case, C is
  109. 7, so the gene size is 15*N, but in the cases where there are no
  110. walls, food, or crap, C is effectively 4, and the gene size is
  111. 9*N.  Values of N as low as 2 (or even 1!) can give quite
  112. interesting behavior.
  113.  
  114.        When you use the hot keys or the parameter control menu to
  115. change the colonies' state count, this is done with as little
  116. change in the genes as possible.  In particular, when you change
  117. from N to 2*N states, this is done simply by copying the N old
  118. state behaviors into N new states.  As time goes by and mutations
  119. take effect, the new states may come to act differently from the
  120. old ones.  In the passage from 2*N to N states, the lookup tables
  121. for the low N states are used with all mentions of states K
  122. higher than above N replaced by K/2.  Similar tricks are used
  123. when you change the direction counts --- the goal in every case
  124. is to try and preserve as much of the ants' personalities as
  125. possible.  One method for evolving good ants which has worked in
  126. the past is to evolve a world at some low state count, to then
  127. double the state count, let the world re-adjust, perhaps
  128. continuing this process through several iterations.  Another
  129. interesting thing to do is to cut a highly evolved many-direction
  130. world down to a low-direction world; much of the many-direction
  131. behavior will carry over, at least for a time.
  132.        The ants remember and erase their own trails.  The
  133. "traillength" can be set as high as 800.  After an ant has turned
  134. on 800 pixels it begins erasing the oldest of its trail dots
  135. before turning a new pixel on.  Using self-erasing trails keeps
  136. the screen from getting completely covered, and has the pleasant
  137. side-effect of making an ant and its trail appear as a single
  138. entity.  In the food regions of the screen the old crap cells are
  139. eventually restored to food cells, so the food never runs out.  (
  140. If you overlay food onto an ant's trail, the food will have black
  141. holes in it where the colored trail was because the trail
  142. "remembers" having been written over black cells and restores
  143. itself to that state. )  The pixel locations are integers, so the
  144. trail information uses 3200 bytes per ant.
  145.  
  146.       Taken together, the gene and trail requirements come to
  147. about 7K bytes per ant.  Our program allocates room for up to 42
  148. ants, which is a net runtime memory demand of about 300K.
  149.  
  150.      There are two basic kinds of "games" the ants can play:
  151. FreeForAll or EatCycle.  In the FreeForAll game, each ant regards
  152. all other colonies as its prey, and its score is increased by the
  153. preyvalue for each alien trailcell it lands on.  In the EatCycle
  154. game, each colony regards the trails of the colony with the next
  155. higher index number as predators, and the trails of the colony
  156. with the cyclically next lower index number as prey.  Thus if you
  157. had four colonies numbered 1 through 4, colony 1 would prey on
  158. colony 4, be preyed on by colony 2, and be indifferent to colony
  159. 3.  Typically the value of a prey cell is +2 and the value of a
  160. predator cell is -1, though other values can be set.  It is
  161. better not to have predator and prey values equal, as the game is
  162. then "zero-sum" and dull ants who do nothing at all score as well
  163. on the average their more active colony-mates!
  164.  
  165.       Additional effects on the ants can be gotten by putting
  166. food and wall cells on the screen, and assigning various score
  167. values to these kinds of cells.  Note that if you turn the wrap
  168. off, then all the offscreen cells are thought of as wall cells.
  169. If an ant steps onto a wall cell, it is moved back to the
  170. position that it just stepped from, and if wallvalue is negative,
  171. then the ant has its score level reduced as well.
  172.  
  173.       If you press the K key the program will draw a randomly
  174. positioned spiral maze on the screen with food cells at its
  175. center.  If you press the J key the program will overlay an
  176. ellipse of food onto the screen.
  177.  
  178.       The antcolonies available directions can also be varied.
  179. At present, this is changed for all the colonies at once.  1
  180. makes all be 4 direction ants, 2 makes all be 6 direction ants, 3
  181. for 8 direction, 4 for 12, 5 for 16, 6 for fast 16, 7 for 32, 8
  182. for 64, 9 for 128, and 0 makes a mixture.
  183.  
  184.      At startup, or after you press the Shift+X key, the ants'
  185. genetic lookup tables are randomly filled with appropriate
  186. values, each ant is set into state 0, each ant's readcolor is set
  187. to 0, each ant's current direction is randomized, and each ant is
  188. drawn on screen.  Next the ants begin repeating the cycle :
  189. compute new outputs, erase self, post outputs, change location
  190. coordinates, read inputs, redraw self.  After some set number of
  191. cycles, the ants of the individual colonies are ranked within the
  192. colony.  (The set number, called "breedtime" starts out at 2K.)
  193.  
  194.      Once the ants in each colony are scored, the ants are ranked
  195. from highest to lowest score.  If all the scores are zero, then
  196. the ants' rankings are not changed.  The scores displayed on thescreen at this time are the average score per ant of each colony.
  197. Zero to three of three kinds of "reproduction" are then applied
  198. within each colony.
  199.  
  200.      1) SEX  The worst ant is replaced by a "sexual" combination
  201. of the best two ants.  The sexual combination is achieved by
  202. having the child ant act like parent #1 in about half of its
  203. states, and act like parent #2 in the rest of its states.
  204.  
  205.      2) CLONING The gene array of the best ant are copied into
  206. the gene array of the worst remaining ant.  The cloned gene array
  207. is then MUTATED by changing a certain percentage of its entries.
  208. How big a percentage?  Each colony holds a variable called
  209. "temperature".  If the colony's temperature is 0, then none of
  210. the clone's entries are mutated, and if the colony temperature is
  211. 100, then all of the clone's entries are mutated.  We start all
  212. colony temperatures out at 10.  Whenever a colony comes in last
  213. in the overall score average it's temperature is incremented by 1
  214. (up to a limit of 20), and if a colony comes in first in overall
  215. score its temperature is decremented by 1 (to as low as the
  216. "frozen" value 0).
  217.  
  218.      3) ZAPPING The worst remaining ant has its gene tables
  219. completely rerandomized.  This is effectively a 100% mutation.
  220.  
  221.      If we have five or more ants, then all ants better than the
  222. third worst ant are left undisturbed.  For each colony, you can
  223. select which combination of CLONING, ZAPPING, and SEX you want
  224. that colony to use in its breeding.  This is done using the Shift
  225. + a number key.
  226.  
  227.     We do not yet have any firm data on which combination of
  228. evolutionary methods works best.  One would expect that the
  229. fastest evolution happens if you use all three, but one certainly
  230. gets more stable colonies if only SEX is used.  If you find a
  231. colony whose appearance you particularly like, you can preserve
  232. it for awhile by turning all breeding methods off, thus leaving
  233. its genepool unchanged from cycle to cycle.
  234.  
  235.      The ants can evolve purely according to their skill at the
  236. "game" they are presently playing, or the user can influence the
  237. ants according to personal criteria.  In order to breed your own
  238. idiosyncratic strain of ants, set the values of prey, predator,
  239. food, crap and walls all to zero, using the active parameter
  240. change menu (accessed by pressing the Y key).  The ants' only
  241. source of score points will now be the scores you give them.  The
  242. way in which you change an ant's score is to move the mouse.
  243. Whenever you touch the mouse, the ants stop moving and a white
  244. square cursor becomes visible.  You can still move the ants a
  245. step at a time by pressing the space bar.  To reward or punish a
  246. particular ant, you move the mouse square until it includes the
  247. head of the ant you are after, and then you left click to add
  248. 1000 points to that ant's score, or right click to subtract 1000
  249. points from that ant's score.  If more than one ant head is in
  250. the selection square, the select operation will be disallowed.
  251. You can tell when the score changing works because the machine
  252. makes a high noise when you add score and a low noise when you
  253. subtract score.  After touching the mouse, you must press ENTER
  254. or press both mouse keys at once to make the simulation start
  255. running again.
  256.  
  257.      You can also use the mouse clicks to encourage or discourage
  258. individual ants even if the other scoring possibilities are
  259. active.  If there are no other scoring possibilities, however,
  260. then an ant which you select at the best ant will keep its
  261. position as best ant of its colony ( and thus will keep being theant who is mutatedly cloned ) until you change things with
  262. further selections.
  263.  
  264.      You can save parameter files that include all the parameter
  265. settings, plus the value of the seed which was last fed to the
  266. randomizer, as well as the positions of any globs or mazes.
  267. These are called *.anp files.  They are only about 100 bytes
  268. each.  If you load the same *.anp file twice in a row, you will
  269. see the same evolution of ants.
  270.  
  271.      If you have used mouse selection and have made on-the-fly
  272. changes to the running of the ants, then the only way to be sure
  273. of getting the same ants back is to save the whole ant world,
  274. meaning the parameters plus the current genetic information of
  275. the ants.  We call these files *.anw files.  If the ants use 8
  276. states each, the *.anw file is about 3K.  If the ants use 256
  277. states each the *.anw file will be about 500K.  If there is not
  278. enough room on your disk for an *.anw file, it is possible that
  279. the program may crash.
  280.  
  281.      Note that if you have let an ant simulation run for a very
  282. long time (several days), you will also want to save the
  283. information as an *.anw file so that you can immediately come
  284. back to the point you'd evolved to.
  285.  
  286.      You can go into an *.anw file with your text editor and
  287. examine the ants' gene tables, possibly also changing them by
  288. hand.  When doing this, you must be sure to leave the file in the
  289. same format, not adding extra carriage returns, etc., or the
  290. program will crash when this file is reloaded.
  291.  
  292.      The idea for these ANTS was arrived by applying the
  293. artificial life notion of genetic algorithm evolution to the idea
  294. of deterministic two-dimensional Turing machines (which have been
  295. called Vants by Christopher Langton and Turmites by Keewatin
  296. Dewdney).  The particular design choices used here are the result
  297. of a good bit of experimentation by the author, aided by his
  298. students at San Jose State University and his colleagues at
  299. Autodesk, Inc.
  300.