Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
queens.Queens Class Reference

List of all members.

Public Member Functions

def __init__
def reset
def solve
def safe
def place
def remove
def display

Public Attributes

 n
 y
 row
 up
 down
 nfound

Static Public Attributes

int silent = 0

Detailed Description

Definition at line 14 of file queens.py.


Constructor & Destructor Documentation

def queens.Queens.__init__ (   self,
  n = N 
)

Definition at line 16 of file queens.py.

00016 
00017     def __init__(self, n=N):
00018         self.n = n
00019         self.reset()

Here is the caller graph for this function:


Member Function Documentation

def queens.Queens.display (   self)

Definition at line 55 of file queens.py.

00055 
00056     def display(self):
00057         self.nfound = self.nfound + 1
00058         if self.silent:
00059             return
00060         print('+-' + '--'*self.n + '+')
00061         for y in range(self.n-1, -1, -1):
00062             print('|', end=' ')
00063             for x in range(self.n):
00064                 if self.y[x] == y:
00065                     print("Q", end=' ')
00066                 else:
00067                     print(".", end=' ')
00068             print('|')
00069         print('+-' + '--'*self.n + '+')

Here is the caller graph for this function:

def queens.Queens.place (   self,
  x,
  y 
)

Definition at line 41 of file queens.py.

00041 
00042     def place(self, x, y):
00043         self.y[x] = y
00044         self.row[y] = 1
00045         self.up[x-y] = 1
00046         self.down[x+y] = 1

Here is the caller graph for this function:

def queens.Queens.remove (   self,
  x,
  y 
)

Definition at line 47 of file queens.py.

00047 
00048     def remove(self, x, y):
00049         self.y[x] = None
00050         self.row[y] = 0
00051         self.up[x-y] = 0
00052         self.down[x+y] = 0

Here is the caller graph for this function:

def queens.Queens.reset (   self)

Definition at line 20 of file queens.py.

00020 
00021     def reset(self):
00022         n = self.n
00023         self.y = [None] * n             # Where is the queen in column x
00024         self.row = [0] * n              # Is row[y] safe?
00025         self.up = [0] * (2*n-1)         # Is upward diagonal[x-y] safe?
00026         self.down = [0] * (2*n-1)       # Is downward diagonal[x+y] safe?
00027         self.nfound = 0                 # Instrumentation

Here is the caller graph for this function:

def queens.Queens.safe (   self,
  x,
  y 
)

Definition at line 38 of file queens.py.

00038 
00039     def safe(self, x, y):
00040         return not self.row[y] and not self.up[x-y] and not self.down[x+y]

Here is the caller graph for this function:

def queens.Queens.solve (   self,
  x = 0 
)

Definition at line 28 of file queens.py.

00028 
00029     def solve(self, x=0):               # Recursive solver
00030         for y in range(self.n):
00031             if self.safe(x, y):
00032                 self.place(x, y)
00033                 if x+1 == self.n:
00034                     self.display()
00035                 else:
00036                     self.solve(x+1)
00037                 self.remove(x, y)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 25 of file queens.py.

Definition at line 17 of file queens.py.

Definition at line 26 of file queens.py.

Definition at line 23 of file queens.py.

int queens.Queens.silent = 0 [static]

Definition at line 53 of file queens.py.

Definition at line 24 of file queens.py.

Definition at line 22 of file queens.py.


The documentation for this class was generated from the following file: