-
Notifications
You must be signed in to change notification settings - Fork 0
/
Nim.py
39 lines (32 loc) · 1.32 KB
/
Nim.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import sys
if sys.version_info[:2] < (3, 4):
sys.stderr.write("This code requires Python version 3.4 or later")
exit(1)
from NimReport import NimReport
from NimBase import PlayCondition
class Nim(NimReport):
""" This is the 'top-level' or 'user-level' (sub)class of this project
Make sure you run this class with python3. If you are getting weird
messages about super(), then you probably tried to use this class
with python2.
"""
def __init__(self, dimensions=3, rulecode=None, play = PlayCondition.Normal):
# TODO make dimensions have a default of None
super().__init__(); # calls super class inits
self.rulecode = rulecode
self.playCondition = play
# Test for non-full parameters, since we cant run without them
# Todo: Enter an interactive mode
if dimensions is None:
return False
self.setDimensions(dimensions)
def setDimensions(self, dim):
self.max_dimensions = dim
self.origen = self.fillTuple((None,))
self.rectangle = self.origen
self.preperiod = self.origen
if self.playCondition is PlayCondition.Normal:
self.outcomes[self.origen] = 'P'
if self.playCondition is PlayCondition.Misere:
self.outcomes[self.origen] = 'N'
self.setMoves(self.rulecode)