| 49 | |
| 50 | |
| 51 | class NimModel(object): |
| 52 | def __init__(self, game): |
| 53 | self.game = game |
| 54 | |
| 55 | def setup(self): |
| 56 | if self.game.state not in [Nim.CREATED, Nim.OVER]: |
| 57 | return |
| 58 | self.sticks = [randomrow(), randomrow(), randomrow()] |
| 59 | self.player = 0 |
| 60 | self.winner = None |
| 61 | self.game.view.setup() |
| 62 | self.game.state = Nim.RUNNING |
| 63 | |
| 64 | def move(self, row, col): |
| 65 | maxspalte = self.sticks[row] |
| 66 | self.sticks[row] = col |
| 67 | self.game.view.notify_move(row, col, maxspalte, self.player) |
| 68 | if self.game_over(): |
| 69 | self.game.state = Nim.OVER |
| 70 | self.winner = self.player |
| 71 | self.game.view.notify_over() |
| 72 | elif self.player == 0: |
| 73 | self.player = 1 |
| 74 | row, col = computerzug(self.sticks) |
| 75 | self.move(row, col) |
| 76 | self.player = 0 |
| 77 | |
| 78 | def game_over(self): |
| 79 | return self.sticks == [0, 0, 0] |
| 80 | |
| 81 | def notify_move(self, row, col): |
| 82 | if self.sticks[row] <= col: |
| 83 | return |
| 84 | self.move(row, col) |
| 85 | |
| 86 | |
| 87 | class Stick(turtle.Turtle): |
no outgoing calls
no test coverage detected
searching dependent graphs…