005 AI Program 10
005 AI Program 10
🧩 Code Breakdown:
✅ Step 1: Define the board
N = 8
chess_board = [[0] * N for _ in range(N)]
Creates an 8x8 board filled with zeros.
0 means empty square, 1 means a queen is placed there.
🧩 Backtracking In Action:
If a configuration fails later (e.g., row 4 has no valid positions), the code:
Removes the last placed queen (board[row][col] = 0)
Tries the next possible column in the previous row.
This continues until a full solution is found or all combinations are tried.
🧩 Output:
The first valid 8-queen configuration is printed like this:
Q . . . . . . .
. . . . Q . . .
. . . . . . . Q
. . . . . Q . .
. . Q . . . . .
. . . . . . Q .
. Q . . . . . .
. . . Q . . . .