Attachment 'nim.py'
Download
Toggle line numbers
1 class Game:
2 def __init__(self, initialBoard):
3 self.board = initialBoard
4 def takeMatches(self, matches, pile):
5 if matches < 1:
6 raise MustTakePositiveMatchesError("Get real")
7 if self.board[pile] < matches:
8 raise NotEnoughMatchesError("Oh dear: pile " + str(pile) + " not big enough")
9 self.board[pile] -= matches
10 nonZeroPiles = [pile
11 for pile in self.board
12 if pile > 0]
13 return len(nonZeroPiles) == 0
14
15 class NotEnoughMatchesError(Exception):
16 pass
17 class MustTakePositiveMatchesError(Exception):
18 pass
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.