Back to index

python3.2  3.2.2
Classes | Functions | Variables
turtledemo.nim Namespace Reference

Classes

class  NimModel
class  Stick
class  NimView
class  NimController
class  Nim

Functions

def randomrow
def computerzug
def randommove
def main

Variables

int SCREENWIDTH = 640
int SCREENHEIGHT = 480
int MINSTICKS = 7
int MAXSTICKS = 31
int HUNIT = 12
tuple WUNIT = SCREENWIDTH//((MAXSTICKS // 5) * 11 + (MAXSTICKS % 5) * 2)
tuple SCOLOR = (63, 63, 31)
tuple HCOLOR = (255, 204, 204)
tuple COLOR = (204, 204, 255)
tuple mainscreen = turtle.Screen()

Detailed Description

turtle-example-suite:

    tdemo_nim.py

Play nim against the computer. The player
who takes the last stick is the winner.

Implements the model-view-controller
design pattern.

Function Documentation

def turtledemo.nim.computerzug (   state)

Definition at line 33 of file nim.py.

00033 
00034 def computerzug(state):
00035     xored = state[0] ^ state[1] ^ state[2]
00036     if xored == 0:
00037         return randommove(state)
00038     for z in range(3):
00039         s = state[z] ^ xored
00040         if s <= state[z]:
00041             move = (z, s)
00042             return move

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 220 of file nim.py.

00220 
00221 def main():
00222     nim = Nim(mainscreen)
00223     return "EVENTLOOP!"

Here is the call graph for this function:

def turtledemo.nim.randommove (   state)

Definition at line 43 of file nim.py.

00043 
00044 def randommove(state):
00045     m = max(state)
00046     while True:
00047         z = random.randint(0,2)
00048         if state[z] > (m > 1):
00049             break
00050     rand = random.randint(m > 1, state[z]-1)
00051     return z, rand
00052 

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 30 of file nim.py.

00030 
00031 def randomrow():
00032     return random.randint(MINSTICKS, MAXSTICKS)

Here is the call graph for this function:


Variable Documentation

tuple turtledemo.nim.COLOR = (204, 204, 255)

Definition at line 28 of file nim.py.

tuple turtledemo.nim.HCOLOR = (255, 204, 204)

Definition at line 27 of file nim.py.

Definition at line 23 of file nim.py.

Definition at line 216 of file nim.py.

Definition at line 21 of file nim.py.

Definition at line 20 of file nim.py.

tuple turtledemo.nim.SCOLOR = (63, 63, 31)

Definition at line 26 of file nim.py.

Definition at line 18 of file nim.py.

Definition at line 17 of file nim.py.

tuple turtledemo.nim.WUNIT = SCREENWIDTH//((MAXSTICKS // 5) * 11 + (MAXSTICKS % 5) * 2)

Definition at line 24 of file nim.py.