PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 5ms RepoModel.GetById 35ms app.codeStats 1ms

/board.py

https://code.google.com/
Python | 30 lines | 26 code | 4 blank | 0 comment | 11 complexity | cf91b41832c4b322afed95fbc6c968cf MD5 | raw file
 1class board:
 2        def __init__(self, size):
 3                self.size = size
 4                self.board = []
 5		self.stonelist = []
 6                tempvector = []
 7                for i in range(size):
 8                        tempvector.append(0)
 9                for i in range(size):
10                        self.board.append(eval(repr(tempvector)))
11
12        def returnpoint(self, x, y):
13                return self.board[y][x]
14
15        def setpoint(self, x, y, new):
16		if (new == 1 or new == -1) and (self.returnpoint(x,y) == 0):
17			self.stonelist.append([x,y])
18		if new == 0 and self.returnpoint(x,y) != 0:
19			self.stonelist.remove([x,y])
20                self.board[y][x]=new
21
22	def removestones(self, coordlist): #removes a group from the board
23		for i in range(len(coordlist)):
24			self.setpoint(coordlist[i][0], coordlist[i][1], 0)
25
26        def __repr__(self):
27                string = ""
28                for i in range(self.size):
29                        string += '%s = %s\n' % (i+1, self.board[i])
30                return string