There is nothing obviously wrong with your code. And, in fact, replacing chessBoard
with a list
of list
s and changing the rest of the code appropriately, it works for all legal inputs.
See this pastebin for the adapted code. See this one for a modified version that just loops over all valid inputs. If you run it, it prints out exactly 36 completed boards.
So, if there is a problem either you're not running the same code you posted here, or there's a bug in your Array2D
implementation.
There are a few weird things about your code.
First, you almost never want to check == None
. If you really need to check whether something is None
, use the is
operator, not ==
. If all of your "real" values are truthy, just use the value itself as a boolean (because None
is falsey). See Programming Recommendations in PEP 8 for details.
Next, you have your global setup split between a main
function, and global module scope. Usually you want to do it all in the same place.
Finally, having a recursive function that mutates a global variable is an odd thing to do. Not that it doesn't work in your case (but only because you can only ever run one test before exiting), but usually in a recursive function you want to either pass the value down as an "accumulator" argument, or do everything immutably (by passing copies down and back up).