Important News

We have released Shinobi Life Online Pre-Alpha Version 1.1.0.0! This update features Earth Release: Earth Dome Jutsu, Aiming Mode and more! Try it out and tell us what you think.

User

Welcome, Guest.
Please login or register.
 
 
 
Forgot your password?

Discord

Statistics

Members
Total Members: 64081
Latest: Irintqw
New This Month: 4174
New This Week: 140
New Today: 24
Stats
Total Posts: 73945
Total Topics: 20793
Most Online Today: 1675
Most Online Ever: 4232
(January 14, 2020, 07:47:33)
Users Online
Members: 1
Guests: 1074
Total: 1078
Irintqw
Google (3)

Author Topic: Lua Eight Queens Program  (Read 7871 times)

0 Members and 1 Guest are viewing this topic.

Offline America

  • Hidden Metal Kage
  • Patriotic Sennin Donator
  • Jonin Poster
  • ***
  • Posts: 532
  • Reputation Power: 5
  • America has no influence.
  • Gender: Male
  • 初代目金属影 - First Kinzokukage
    • View Profile
  • Clan: Hinode
Lua Eight Queens Program
« on: September 01, 2016, 14:55:52 »


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.


  • Character Name: Onoyari Hinode

Offline DarthTyrael

  • Hidden Dust Kage
  • Hidden Village Kage
  • Special Jonin Poster
  • ***
  • Posts: 412
  • Reputation Power: 4
  • DarthTyrael has no influence.
  • Gender: Male
  • I try to assist wherever I can.
    • View Profile
  • Clan:
  • Organization:
Re: Lua Eight Queens Program
« Reply #1 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.
« Last Edit: September 01, 2016, 15:28:25 by DarthTyrael »




"A village without a Kage is lost for some time, but a Kage without a village is lost forever"



Join Hidden Dust's Discord server!







Offline America

  • Hidden Metal Kage
  • Patriotic Sennin Donator
  • Jonin Poster
  • ***
  • Posts: 532
  • Reputation Power: 5
  • America has no influence.
  • Gender: Male
  • 初代目金属影 - First Kinzokukage
    • View Profile
  • Clan: Hinode
Re: Lua Eight Queens Program
« Reply #2 on: September 01, 2016, 16:44:03 »
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.

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?
  • Character Name: Onoyari Hinode

Offline Manuster

Re: Lua Eight Queens Program
« Reply #3 on: September 01, 2016, 16:46:37 »
sooo? is this a game? whats the aim?
RIP my old sig, got too annoying for even me

Offline DarthTyrael

  • Hidden Dust Kage
  • Hidden Village Kage
  • Special Jonin Poster
  • ***
  • Posts: 412
  • Reputation Power: 4
  • DarthTyrael has no influence.
  • Gender: Male
  • I try to assist wherever I can.
    • View Profile
  • Clan:
  • Organization:
Re: Lua Eight Queens Program
« Reply #4 on: September 01, 2016, 17:11:49 »
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.

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?

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.


sooo? is this a game? whats the aim?

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




"A village without a Kage is lost for some time, but a Kage without a village is lost forever"



Join Hidden Dust's Discord server!







Offline America

  • Hidden Metal Kage
  • Patriotic Sennin Donator
  • Jonin Poster
  • ***
  • Posts: 532
  • Reputation Power: 5
  • America has no influence.
  • Gender: Male
  • 初代目金属影 - First Kinzokukage
    • View Profile
  • Clan: Hinode
Re: Lua Eight Queens Program
« Reply #5 on: September 01, 2016, 17:26:14 »
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.

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?

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.


sooo? is this a game? whats the aim?

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

So does it repeat the for i, n - 1 with c as 2 and i as 2 or does it go back to the for c = 1, N and repeat the first loop with c as 2 and i as 1?
  • Character Name: Onoyari Hinode

Offline DarthTyrael

  • Hidden Dust Kage
  • Hidden Village Kage
  • Special Jonin Poster
  • ***
  • Posts: 412
  • Reputation Power: 4
  • DarthTyrael has no influence.
  • Gender: Male
  • I try to assist wherever I can.
    • View Profile
  • Clan:
  • Organization:
Re: Lua Eight Queens Program
« Reply #6 on: September 01, 2016, 17:42:49 »
Sorry... I misunderstood the code as well... Let me try it again. There are no rows in this code (besides printing the board).


You start the command with addqueen({},1} with a = {} and n = 1. n being the queen number and c being the columns.

It will start with c = 1, then look through at the board for arguments (in isplaceok).

If result = false it will  loop the isplaceok again for a different i.
If result = true it will add the column number (c) to the n-th place in table a. Then it will do c+1 and repeat the loop again.

Spoiler: show
Though the addqueen command has an issue though...
It says:
for c= 1, N do
    if isplaceok(a,n,c) then.
       <rest of code>

It needs to say (iirc)

if isplaceok(a,n,c)==true then
      <rest of code>


Hope this helped.


Update: EDITED ONCE MORE FFS I HAVEN'T CODED IN FOREVER!
« Last Edit: September 01, 2016, 17:48:16 by DarthTyrael »




"A village without a Kage is lost for some time, but a Kage without a village is lost forever"



Join Hidden Dust's Discord server!







Offline America

  • Hidden Metal Kage
  • Patriotic Sennin Donator
  • Jonin Poster
  • ***
  • Posts: 532
  • Reputation Power: 5
  • America has no influence.
  • Gender: Male
  • 初代目金属影 - First Kinzokukage
    • View Profile
  • Clan: Hinode
Re: Lua Eight Queens Program
« Reply #7 on: September 01, 2016, 17:47:05 »
Sorry... I misunderstood the code as well... Let me try it again. There are no rows in this code (besides printing the board).


You start the command with addqueen({},1} with a = {} and n = 1. n being the queen number and c being the columns.

It will start with c = 1, then look through at the board for arguments (in isplaceok).

If result = false it will go to c = 2 and loop the isplaceok again for a different i.
If result = true it will add the column number (c) to the n-th place in table a.

Spoiler: show
Though the addqueen command has an issue though...
It says:
for c= 1, N do
    if isplaceok(a,n,c) then.
       <rest of code>

It needs to say (iirc)

if isplaceok(a,n,c)==true then
      <rest of code>


Hope this helped.


From what I understand, the first Queen goes at the top in the first row/column because for = 1 , n - 1 is basically for = 1 , 0, which means that it doesn't even run the code. ( it goes from 1 to 0, which doesn't work.)

I don't think that there is a problem with the code, as the guy who wrote the code also created the language.
  • Character Name: Onoyari Hinode

Offline DarthTyrael

  • Hidden Dust Kage
  • Hidden Village Kage
  • Special Jonin Poster
  • ***
  • Posts: 412
  • Reputation Power: 4
  • DarthTyrael has no influence.
  • Gender: Male
  • I try to assist wherever I can.
    • View Profile
  • Clan:
  • Organization:
Re: Lua Eight Queens Program
« Reply #8 on: September 01, 2016, 17:51:41 »
Aye I see. Anycase, updated my previous post again bc I'm a dumbass coder.


----
You start the command with addqueen({},1} with a = {} and n = 1. n being the queen number and c being the columns.

It will start with c = 1, then look through at the board for arguments (in isplaceok).

If result = false it will  loop the isplaceok again for a different i.
If result = true it will add the column number (c) to the n-th place in table a. Then it will do c+1 and repeat the loop again.

----


That should be the answer to your question.




"A village without a Kage is lost for some time, but a Kage without a village is lost forever"



Join Hidden Dust's Discord server!







Offline America

  • Hidden Metal Kage
  • Patriotic Sennin Donator
  • Jonin Poster
  • ***
  • Posts: 532
  • Reputation Power: 5
  • America has no influence.
  • Gender: Male
  • 初代目金属影 - First Kinzokukage
    • View Profile
  • Clan: Hinode
Re: Lua Eight Queens Program
« Reply #9 on: September 01, 2016, 17:58:38 »
Aye I see. Anycase, updated my previous post again bc I'm a dumbass coder.


----
You start the command with addqueen({},1} with a = {} and n = 1. n being the queen number and c being the columns.

It will start with c = 1, then look through at the board for arguments (in isplaceok).

If result = false it will  loop the isplaceok again for a different i.
If result = true it will add the column number (c) to the n-th place in table a. Then it will do c+1 and repeat the loop again.

----


That should be the answer to your question.

Ok, that makes sense for returning false, but returning true is where I run into an issue. When it returns true, it says that it runs the whole addqueen function again with the arguments (a, n+1), which would reset the c?
  • Character Name: Onoyari Hinode

Offline DarthTyrael

  • Hidden Dust Kage
  • Hidden Village Kage
  • Special Jonin Poster
  • ***
  • Posts: 412
  • Reputation Power: 4
  • DarthTyrael has no influence.
  • Gender: Male
  • I try to assist wherever I can.
    • View Profile
  • Clan:
  • Organization:
Re: Lua Eight Queens Program
« Reply #10 on: September 01, 2016, 18:05:47 »
Yeah exactly... Let me correct myself then.

If result = false it will  loop the isplaceok again for a different i.
If all i's are used, it will move to the next column (c+1)

If result = true it will add the column number (c) to the n-th place in table a. then, it will move to placing the next queen (n+1), resetting the column count.

Reason this makes sense: you cannot place the queen in the same column, or they can attack each other.




"A village without a Kage is lost for some time, but a Kage without a village is lost forever"



Join Hidden Dust's Discord server!







Offline America

  • Hidden Metal Kage
  • Patriotic Sennin Donator
  • Jonin Poster
  • ***
  • Posts: 532
  • Reputation Power: 5
  • America has no influence.
  • Gender: Male
  • 初代目金属影 - First Kinzokukage
    • View Profile
  • Clan: Hinode
Re: Lua Eight Queens Program
« Reply #11 on: September 01, 2016, 18:48:15 »
Yeah exactly... Let me correct myself then.

If result = false it will  loop the isplaceok again for a different i.
If all i's are used, it will move to the next column (c+1)

If result = true it will add the column number (c) to the n-th place in table a. then, it will move to placing the next queen (n+1), resetting the column count.

Reason this makes sense: you cannot place the queen in the same column, or they can attack each other.


I get it now, thanks for your help
  • Character Name: Onoyari Hinode