chaged langton's ant README
This commit is contained in:
parent
c045621618
commit
5e36886570
@ -22,7 +22,7 @@ livingSpaceHeight = 36
|
|||||||
creatureW = window_w/(livingSpaceWidth)
|
creatureW = window_w/(livingSpaceWidth)
|
||||||
creatureH = window_h/(livingSpaceHeight)
|
creatureH = window_h/(livingSpaceHeight)
|
||||||
|
|
||||||
FPS = 60
|
FPS = 30
|
||||||
|
|
||||||
NORTH = 0
|
NORTH = 0
|
||||||
EAST = 1
|
EAST = 1
|
||||||
@ -246,12 +246,14 @@ def update_ant():
|
|||||||
activate(antPosition[0], antPosition[1])
|
activate(antPosition[0], antPosition[1])
|
||||||
|
|
||||||
# turn
|
# turn
|
||||||
if isAlive(antPosition[0], antPosition[1]):
|
code_index = 1 if isAlive(antPosition[0], antPosition[1]) else 0
|
||||||
|
|
||||||
|
if code[code_index]:
|
||||||
# turn right
|
# turn right
|
||||||
antRotation = (antRotation + 1) % 4
|
antRotation = (antRotation + 3) % 4
|
||||||
else:
|
else:
|
||||||
# turn left
|
# turn left
|
||||||
antRotation = (antRotation + 3) % 4
|
antRotation = (antRotation + 1) % 4
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# if we have more than 3 colors, we use the color code
|
# if we have more than 3 colors, we use the color code
|
||||||
@ -304,7 +306,7 @@ def main():
|
|||||||
global code
|
global code
|
||||||
|
|
||||||
# parsing args:
|
# parsing args:
|
||||||
parser = argparse.ArgumentParser(description="langton's ant simulation tool", formatter_class=argparse.RawTextHelpFormatter)
|
parser = argparse.ArgumentParser(description="langton\'s ant simulation tool", formatter_class=argparse.RawTextHelpFormatter)
|
||||||
parser.add_argument('--steps', dest='steps', default = 20 , help='steps per second')
|
parser.add_argument('--steps', dest='steps', default = 20 , help='steps per second')
|
||||||
parser.add_argument('--w', dest='w', default = livingSpaceWidth, help = 'field width')
|
parser.add_argument('--w', dest='w', default = livingSpaceWidth, help = 'field width')
|
||||||
parser.add_argument('--h', dest='h', default=livingSpaceHeight, help = 'field height')
|
parser.add_argument('--h', dest='h', default=livingSpaceHeight, help = 'field height')
|
||||||
@ -313,7 +315,7 @@ def main():
|
|||||||
parser.add_argument('--window_w', dest='win_w', default=window_w, help='window width')
|
parser.add_argument('--window_w', dest='win_w', default=window_w, help='window width')
|
||||||
parser.add_argument('--window_h', dest='win_h', default=window_h, help='window height')
|
parser.add_argument('--window_h', dest='win_h', default=window_h, help='window height')
|
||||||
parser.add_argument('--configurator', dest='configurator', action='store_true', help='start in field edit mode')
|
parser.add_argument('--configurator', dest='configurator', action='store_true', help='start in field edit mode')
|
||||||
parser.add_argument('--code', dest='code', default='01', help='binary code for the ant (\'01\' corresponds to the starndard ant behaviour)')
|
parser.add_argument('--code', dest='code', default='10', help='binary code for the ant (\'10\' corresponds to the starndard ant behaviour). 1 means \'turn left\', 0 means \'turn right\'')
|
||||||
parser.add_argument('--file', dest='file', default='', help='writing number of living cells per step in this file')
|
parser.add_argument('--file', dest='file', default='', help='writing number of living cells per step in this file')
|
||||||
parser.add_argument('--pattern', dest='pattern', default='0',
|
parser.add_argument('--pattern', dest='pattern', default='0',
|
||||||
help='initial pattern for the field. Possible values:\n' +
|
help='initial pattern for the field. Possible values:\n' +
|
||||||
|
@ -1,9 +1,22 @@
|
|||||||
# Langton's Ant Simulator
|
# Langton's Ant Simulator
|
||||||
|
|
||||||
|
## install dependencies:
|
||||||
|
|
||||||
|
this python program needs pygame and PyOpenGL for the displaying stuff.
|
||||||
|
|
||||||
|
this can be done via pip (on ubuntu-linux pip3 for using python 3):
|
||||||
|
|
||||||
|
```
|
||||||
|
pip install PyOpenGL PyOpenGL_accelerate pygame
|
||||||
|
```
|
||||||
|
|
||||||
|
## run the program:
|
||||||
|
|
||||||
```
|
```
|
||||||
usage: Main.py [-h] [--steps STEPS] [--w W] [--h H] [--calc CALC]
|
usage: Main.py [-h] [--steps STEPS] [--w W] [--h H] [--calc CALC]
|
||||||
[--fullscreen] [--window_w WIN_W] [--window_h WIN_H]
|
[--fullscreen] [--window_w WIN_W] [--window_h WIN_H]
|
||||||
[--configurator] [--code CODE] [--pattern PATTERN]
|
[--configurator] [--code CODE] [--file FILE]
|
||||||
|
[--pattern PATTERN]
|
||||||
|
|
||||||
langton's ant simulation tool
|
langton's ant simulation tool
|
||||||
|
|
||||||
@ -17,7 +30,8 @@ optional arguments:
|
|||||||
--window_w WIN_W window width
|
--window_w WIN_W window width
|
||||||
--window_h WIN_H window height
|
--window_h WIN_H window height
|
||||||
--configurator start in field edit mode
|
--configurator start in field edit mode
|
||||||
--code CODE binary code for the ant ('01' corresponds to the starndard ant behaviour)
|
--code CODE binary code for the ant ('10' corresponds to the starndard ant behaviour). 1 means 'turn left', 0 means 'turn right'
|
||||||
|
--file FILE writing number of living cells per step in this file
|
||||||
--pattern PATTERN initial pattern for the field. Possible values:
|
--pattern PATTERN initial pattern for the field. Possible values:
|
||||||
* 0: all fields inactive
|
* 0: all fields inactive
|
||||||
* 1: all fields active
|
* 1: all fields active
|
||||||
@ -25,7 +39,6 @@ optional arguments:
|
|||||||
* horizontal: horizontal stripes
|
* horizontal: horizontal stripes
|
||||||
* vertical: vertical stripes
|
* vertical: vertical stripes
|
||||||
* random: random values
|
* random: random values
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
keys:
|
keys:
|
||||||
@ -39,3 +52,30 @@ keys:
|
|||||||
| ctrl left / ctrl right | rotate ant (in configuration mode) |
|
| ctrl left / ctrl right | rotate ant (in configuration mode) |
|
||||||
| escape | exit program |
|
| escape | exit program |
|
||||||
|
|
||||||
|
## examples
|
||||||
|
|
||||||
|
* run standard langton's ant and write number of living cells per timestep to 'out.txt':
|
||||||
|
|
||||||
|
```
|
||||||
|
./Main.py --file out.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
* run standard langton's and with checkboard pattern:
|
||||||
|
|
||||||
|
```
|
||||||
|
./Main.py --pattern check
|
||||||
|
```
|
||||||
|
|
||||||
|
* run on a fieldsize of 16x9 and start in configuration mode to adjust the ant's position and rotation:
|
||||||
|
|
||||||
|
```
|
||||||
|
./Main.py --w 16 --h 9 --configurator
|
||||||
|
```
|
||||||
|
|
||||||
|
* run the multicolored ant 'RRLLLRLLLRRR' on a field with size 320x180 and perform 1000 steps per second:
|
||||||
|
|
||||||
|
```
|
||||||
|
./Main.py --w 320 --h 180 --code 110001000111 --steps 1000
|
||||||
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user