The Occasional Occurence
The planets have aligned...
June 21, 2004 at 10:18 PM | categories: PythonHoly cow. I happened to check out CivFanatics today and found some exciting info: According to Civilization IV lead programmer Soren Johnson, Civ IV is going to be scriptable with Python!! I am certain that I find this much more exciting than you, my readership, but since this is my blog, I had to gush about it.
In other news, I haven't done much on my game in the last few days. Here is a snippet of code I put together for creating a matrix with one type of element on the edges and another type inside.
def edgeMatrix(width, height, edge='E', interior='I'):
"""Create a matrix with different elements on the edges"""
em = []
for x in range(height):
em.append([])
for y in range(width):
if x in (0, height-1):
em[x].append(edge)
elif y in (0, width-1):
em[x].append(edge)
else:
em[x].append(interior)
return em
Here is an example from the interactive interpreter:
matrix = edgeMatrix(8,8, 'ext', 'int')
for row in matrix: print row
['ext', 'ext', 'ext', 'ext', 'ext', 'ext', 'ext', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'int', 'int', 'int', 'int', 'int', 'int', 'ext']
['ext', 'ext', 'ext', 'ext', 'ext', 'ext', 'ext', 'ext']
That function should help with my grid/map creation routines. Seriously.
cw