python - Why are the values being made into "None" instead of "LIVE"? -


this game of life program. when tested it, surrounding(row,col) function returned 0 if configuration file indicated 8 squares made "live." ran test printing board after opening configuration file, , turns out instead of making indicated squares 'live,' ones 'live' 'none' no 'live' values being counted.

[[none, none, none, 0, 0, 0, 0], [none, 0, none, 0, 0, 0, 0], [none, none, none, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]] when print board. can't see i'm missing here?

live = 1 dead = 0  def board(canvas, width, height, n):     row in range(n+1):         col in range(n+1):             canvas.create_rectangle(row*height/n,col*width/n,(row+1)*height/n,(col+1)*width/n,width=1,fill='black',outline='green')                        n = int(raw_input("enter dimensions of board: ")) width = n*25 height = n*25  tkinter import * import math  window=tk() window.title('game of life')  canvas=canvas(window,width=width,height=height,highlightthickness=0) canvas.grid(row=0,column=0,columnspan=5)  board = [[dead row in range(n)] col in range(n)]  rect = [[none row in range(n)] col in range(n)]   row in range(n):     col in range(n):               rect[row][col] = canvas.create_rectangle(row*height/n,col*width/n,(row+1)*height/n,(col+1)*width/n,width=1,fill='black',outline='green')   #canvas.itemconfigure(rect[2][3], fill='red') #rect[2][3] rectangle id  #print rect  f = open('filename','r') #filename whatever configuration file chosen gives step() function work off of first time line in f:     parsed = line.split()     print parsed     if len(parsed)>1:         row = int(parsed[0].strip())         col = int(parsed[1].strip())         board[row][col] = live         board[row][col] = canvas.itemconfigure(rlist[row][col], fill='red')          def surrounding(row,col):     count = 0     if board[(row-1) % n][(col-1) % n] == live:         count += 1     if board[(row-1) % n][col % n] == live:         count += 1     if board[(row-1) % n][(col+1) % n] == live:         count += 1     if board[row % n][(col-1) % n] == live:         count += 1     if board[row % n][(col+1) % n] == live:         count += 1     if board[(row+1) % n][(col-1) % n] == live:         count +=1     if board[(row+1) % n ][col % n] == live:         count += 1     if board[(row+1) % n][(col+1) % n] == live:         count += 1     print count     return count  surrounding(1,1) 

you're assigning items of board nested list twice:

    board[row][col] = live     board[row][col] = canvas.itemconfigure(rlist[row][col], fill='red') 

the first assigns 1 appropriate value, second replaces 1 none, since that's return value of canvas.itemconfigure when called arguments. suspect (without testing it) should remove assignment second statement:

    board[row][col] = live     canvas.itemconfigure(rlist[row][col], fill='red') 

this might still have issues (such rlist needing rect, perhaps?), issue none values should resolved.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -