Ask coding questions

← Back to all posts
Help please!
AlcidesCunha (1)

I found this solution for the problem of "eight queens" in C, but i cant understand this code and it backtracking. Anyone can help me/

CPPStudent7308 (8)

Oh boy. I know C++ and I know this is similar, but first I can't understand the documentation, and second what is eight queens?

heyitsmarcus (287)

@CPPStudent7308 The Eight Queens puzzle is to list all of the solutions where you have an 8 x 8 board with only 8 Queens on it such that no Queen can intercept another queen from their current position. The Queens all have the same "power" that they have in Chess, where the queen can move diagonally, vertically, or horizontally as much as they wish. This means that every solution to the problem must have a Queen in spots where if they were to move from the current position they're in, they could not capture another queen.

This Wikipedia article has more information about the problem itself:

AlcidesCunha (1)

@CPPStudent7308 This is C. And as @heyitsmarcus already explained, this is a problem of Eight Queens. This problem was resolved with backtracking, but I cant understand it logic and I'm lost... I just want understand this logic behind of the backtracking in this code.

CPPStudent7308 (8)

@heyitsmarcus @AlcidesCunha Ok. I think I understand the concept of the game now. Now I'm in the same boat as @AlcidesCunha with no understanding of the logic.