5 queens

cf29 fcharlypillai at gmail.com
Sat Dec 22 20:12:24 EST 2007


Sorry again I forgot a part of the function in my previous post:
---
# add nbQueens (5) new queens on safe squares
def newQueens(nbQueens=5):
	solution = []						# one solution
	for i in range(len(board)):			# 64 squares
		if len(solution) < nbQueens:	# 5 queens
			if board[i][2]==0:			# free square
				solution.append(i)		# a queen position
				queenCtrl(board[i])		# the queen controls squares
	if calcCtrl() == len(board):		# whole board controlled
		allSolutions.append(solution)	# add this solution to the list
	resetCtrl()							# reset the controled squares




More information about the Python-list mailing list