Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Mister Dix [Python]

Name: Anonymous 2009-11-24 21:09

# -*- coding: utf-8 -*-
# access format is "pfield[row][column][item]
# map form is [food,waste]
# uses command line arguments for number of simulations
# currently just randomly wanders and eats stuff
# someday it will have the capability to starve to death
# i'd also like to make it shit- unfortunately, i need to run
#          this Chi-Square
#    python dix.py [# moves]


import random, sys
print "-- Generating 4x4 field of food and waste"
pfield = [[[9,9],[9,9]],[[9,9],[9,9]]]
print "-- Putting our man in the bottom left"
manplace = [0,0]

nMoves = int(sys.argv[1])

def eat():
  food = get_food(manplace[0],manplace[1])
  if pfield[manplace[0]][manplace[1]][0] >= 1:
    pfield[manplace[0]][manplace[1]][0] = pfield[manplace[0]][manplace[1]][0]-1
    print "Mr. Dix grazes."
  if pfield[manplace[0]][manplace[1]][0] == 0:
    print "There is no food here!"

def place(row,column):
  return pfield[row][column]

def get_food(row,column):
  return pfield[row][column][0]

def get_waste(row,column):
  return pfield[row][column][1]

def move():
  roll = random.randint(0,2)
  x = manplace[0]
  y = manplace[1]
  if roll == 0:
    if x < 1:
    print "Mr. Dix  moves up"
    manplace[0]=manplace[0]+1
    if x > 0:
    print "Mr. Dix  moves down"
    manplace[0]=manplace[0]-1
  if roll == 1:
    if y < 1:
    print "Mr. Dix  moves right"
    manplace[1]=manplace[1]+1
    if y > 0:
    print "Mr. Dix moves left"
    manplace[1]=manplace[1]-1
  if roll == 2:
    print "Mr. Dix decides to stay put"
  eat()

def man():
  food = get_food(manplace[0],manplace[1])
  filth = get_waste(manplace[0],manplace[1])
  print "Food:" + str(food) + " | " + "Filth:" + str(filth) + " X:"+str(manplace[0]),"Y:"+str(manplace[1])
  move()

if __name__ == "__main__":
    print "-- Letting our man go for",str(nMoves),"moves"
    print "="*45+"\n\n"
    for x in range(0,nMoves-1):
        print "----#"+str(x)
        man()
    print "\n\n\n        ~End map of [food,waste]~"
    print "        -------------------"
    print "        | "+str(pfield[0][1])+" | "+str(pfield[1][1])+" |"
    print "        -------------------"
    print "        | "+str(pfield[0][0])+" | "+str(pfield[1][0])+" |"
    print "        -------------------"

Name: Anonymous 2009-11-29 0:47

marc@box:~/prog$ python alife.py
  File "alife.py", line 41
    print "Mr. Dix moves up"
        ^
IndentationError: expected an indented block

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List