Posted By

ltlgrn on 10/09/10


Tagged


Versions (?)

Python gameboard class


 / Published in: Python
 

  1. import copy
  2.  
  3. class GameBoard:
  4. number_of_rows = 3
  5. rows = []
  6. global random_puzzle
  7.  
  8. def __getstate__(self):
  9. return self.rows
  10.  
  11. def __setstate__(self, rows):
  12. self.rows = rows
  13.  
  14. def __init__(self):
  15. return
  16.  
  17. def getgameboard(self):
  18. return self.rows
  19.  
  20. def perform(self, move):
  21. self.rows.append(move)
  22. return
  23.  
  24. def legalmoves(self):
  25. return ['a1', 'a2', 'a3']
  26.  
  27. seq = 1
  28. gb = GameBoard()
  29. moves = []
  30. while seq < 4:
  31. possibilities = gb.legalmoves()
  32. gb.perform(possibilities[0])
  33. moves.append(copy.deepcopy(gb))
  34. seq = seq + 1
  35.  
  36. for move in moves:
  37. print move.getgameboard()

Report this snippet  

You need to login to post a comment.