/board.py
https://code.google.com/ · Python · 30 lines · 26 code · 4 blank · 0 comment · 9 complexity · cf91b41832c4b322afed95fbc6c968cf MD5 · raw file
- class board:
- def __init__(self, size):
- self.size = size
- self.board = []
- self.stonelist = []
- tempvector = []
- for i in range(size):
- tempvector.append(0)
- for i in range(size):
- self.board.append(eval(repr(tempvector)))
- def returnpoint(self, x, y):
- return self.board[y][x]
- def setpoint(self, x, y, new):
- if (new == 1 or new == -1) and (self.returnpoint(x,y) == 0):
- self.stonelist.append([x,y])
- if new == 0 and self.returnpoint(x,y) != 0:
- self.stonelist.remove([x,y])
- self.board[y][x]=new
- def removestones(self, coordlist): #removes a group from the board
- for i in range(len(coordlist)):
- self.setpoint(coordlist[i][0], coordlist[i][1], 0)
- def __repr__(self):
- string = ""
- for i in range(self.size):
- string += '%s = %s\n' % (i+1, self.board[i])
- return string