apr 13
0) progress reports
1) Jim's example : current status
- buttons swap things around
2) epydoc - API html pages generated automatically from python doc strings
We did this in class, talking about FUNCTIONS and BREAKING THINGS UP INTO SMALLER PARTS and TESTING EACH PART!!!! (Yeah, this means you.)
N = 3
# There's an N x N grid of cells whose labels
# are in order, top to bottom, left to right,
# starting at 0 :
#
# 0 1 2
# 3 4 5
# 6 7 8
def index2coord(i):
""" Return (x,y) coordinate of a 0..N**2-1 index.
>>> index2coord(0)
(0, 0)
>>> index2coord(2 + 1 * N)
(2, 1)
"""
x = i % N
y = int(i / N)
return x, y
def adjacent(i, j):
"""Return true if cells i and j are adjacent.
>>> adjacent(0, 4)
False
"""
i_coords = index2coord(i)
j_coords = index2coord(j)
if abs(i_coords[0]-j_coords[0])==1 and i_coords[1]==j_coords[1]:
return True
if abs(i_coords[1]-j_coords[1])==1 and i_coords[0]==j_coords[0]:
return True
return False
if __name__ == '__main__':
from doctest import testmod
testmod()