in reply to Re: "Attack" -- Find Solutions for N Non-Attacking Chess Pieces
in thread "Attack" -- Find Solutions for N Non-Attacking Chess Pieces
I implemented the data structure before anything else, including the original Eight Queens Problem, and one of my foremost priorities for it was speed. That would rule out function references; if you're trying to make things as fast as possible, you can't make each legal move a function call.
As far as why I didn't define things in terms of diagonals versus horizontal/vertical moves: the data structure needed to contain AoA for each square for each piece rather than simply an array, and the reason for that was, when calculating the directions for a piece such as a bishop, rook or queen, you have to stop as soon as you hit another piece (if the piece is of the opposite color, it can be captured, of course). Besides which, pawns, knights and kings wouldn't follow those same rules, so what would be the point?
When I created the data structure, I *did* actually calculate the rook moves and bishop moves first, and then just "added" them together to get the queen.
So I hope you understand my reasoning. Maybe if you try running the program, you'll see why optimizing for speed was my primary goal.
|
|---|