/board.py

https://code.google.com/ · Python · 30 lines · 26 code · 4 blank · 0 comment · 9 complexity · cf91b41832c4b322afed95fbc6c968cf MD5 · raw file

  1. class 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. def returnpoint(self, x, y):
  12. return self.board[y][x]
  13. def setpoint(self, x, y, new):
  14. if (new == 1 or new == -1) and (self.returnpoint(x,y) == 0):
  15. self.stonelist.append([x,y])
  16. if new == 0 and self.returnpoint(x,y) != 0:
  17. self.stonelist.remove([x,y])
  18. self.board[y][x]=new
  19. def removestones(self, coordlist): #removes a group from the board
  20. for i in range(len(coordlist)):
  21. self.setpoint(coordlist[i][0], coordlist[i][1], 0)
  22. def __repr__(self):
  23. string = ""
  24. for i in range(self.size):
  25. string += '%s = %s\n' % (i+1, self.board[i])
  26. return string