MCPcopy Index your code
hub / github.com/python/cpython / NimModel

Class NimModel

Lib/turtledemo/nim.py:51–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49
50
51class 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
87class Stick(turtle.Turtle):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…