Use the new map generator mechanism to generate rooms via cellular atomata. Create a new CellularAtomatonRoomMethod class that uses the Cellular Atomton class to create a room. Add a FreefromRoom class that draws a room based on an ndarray of tiles. Along the way I discovered I have misunderstood how numpy arrays organize rows and columns. The numpy array creation routines take an 'order' argument that specifies whether arrays should be in C order (row major) or Fortran order (column major). Fortran order lets you index arrays with a more natural [x, y] coordinate order, and that's what the tutorials I've read have shown. So I've been using that. When I was developing the Cellular Atomaton, I wrote some code that assumed row- major order. I think I want to move everything to row-major / C-style, but that will take a bit more time.
44 lines
945 B
Python
44 lines
945 B
Python
# Eryn Wells <eryn@erynwells.me>
|
|
|
|
'''
|
|
Run the cellular atomaton from ErynRL and print the results.
|
|
'''
|
|
|
|
import argparse
|
|
|
|
from erynrl import log
|
|
from erynrl.geometry import Point, Rect, Size
|
|
from erynrl.map.generator.cellular_atomata import CellularAtomataMapGenerator
|
|
|
|
|
|
def parse_args(argv, *a, **kw):
|
|
'''Parse command line arguments'''
|
|
parser = argparse.ArgumentParser(*a, **kw)
|
|
parser.add_argument('--rounds', type=int, default=5)
|
|
args = parser.parse_args(argv)
|
|
return args
|
|
|
|
|
|
def main(argv):
|
|
'''The script'''
|
|
|
|
args = parse_args(argv[1:], prog=argv[0])
|
|
|
|
log.init()
|
|
|
|
bounds = Rect(Point(), Size(60, 20))
|
|
|
|
config = CellularAtomataMapGenerator.Configuration()
|
|
config.number_of_rounds = args.rounds
|
|
|
|
gen = CellularAtomataMapGenerator(bounds, config)
|
|
|
|
gen.generate()
|
|
|
|
print(gen)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
import sys
|
|
result = main(sys.argv)
|
|
sys.exit(0 if not result else result)
|