Forum > Programming

Lua Eight Queens Program

(1/3) > >>

America:


Can anyone help me understand this further? I don't get how the function isplaceok works. I know the arguments come from the addqueen function, but I don't understand how they are computed.

DarthTyrael:
As far as I see it (correct me if I'm wrong):

- isplaceok is the argument for placing the queens, checking if the places don't intervene.
- addqueen adds the queen at the spot to a column, then isplaceok checks if the spot is available, from n to N until N+1 queens have been placed.

Update: Edited 2nd part, sorry for that.

America:

--- Quote from: DarthTyrael on September 01, 2016, 15:25:32 ---As far as I see it (correct me if I'm wrong):

- isplaceok is the argument for placing the queens, checking if the places don't intervene.
- addqueen adds the queen at the spot to a column, then isplaceok checks if the spot is available, from n to N until N+1 queens have been placed.

Update: Edited 2nd part, sorry for that.

--- End quote ---

Yeah, I understand that, but how does it compute isplaceok? I fail to understand how it references the index i of table a. When it returns false, does it repeat the function with the next cycle of i? Or does it return false, quit the function and do the next cycle of for c = 1, N?

Manuster:
sooo? is this a game? whats the aim?

DarthTyrael:

--- Quote from: America on September 01, 2016, 16:44:03 ---
--- Quote from: DarthTyrael on September 01, 2016, 15:25:32 ---As far as I see it (correct me if I'm wrong):

- isplaceok is the argument for placing the queens, checking if the places don't intervene.
- addqueen adds the queen at the spot to a column, then isplaceok checks if the spot is available, from n to N until N+1 queens have been placed.

Update: Edited 2nd part, sorry for that.

--- End quote ---

Yeah, I understand that, but how does it compute isplaceok? I fail to understand how it references the index i of table a. When it returns false, does it repeat the function with the next cycle of i? Or does it return false, quit the function and do the next cycle of for c = 1, N?

--- End quote ---

Table a is a table that has a list of colums where in the queens are placed. It then checks for each row whether the position is clear (i, n-1)
That's the step.
If a[ i ] == c1 or diagonal etc., the place can be attacked therefore, no queen can be placed.
It returns false.
No queen placed.

Then moves to placing the queen in a different column (c1 =/= c2)
And a new cycle begins.



--- Quote from: Manuster on September 01, 2016, 16:46:37 ---sooo? is this a game? whats the aim?

--- End quote ---

@Manuster A riddle/puzzle with queens upon a chess board.

Navigation

[0] Message Index

[#] Next page

Go to full version