Results 1 to 2 of 2
  1. #1
    EscSequenceAlpha is offline Senior Member
    Join Date
    Apr 2012
    Posts
    115
    Rep Power
    0

    Default So... the eight queens problem, can you help set me up on the right path

    I was thinking of attempting this, but I would need a bit of help by which I mean quite a lot.

    first of all I need the logic... this requires recursion, I understand factorial recursion but this is much more complicated. I'm going to wright down how I think the problem might be solved and you guys please look it over and correct me.

    I guess I would need a base case, I think it would be if (queens == 0)... so the method "place" would take in the number of queens

    now, if queens does not equal 0 then find a free position

    check 1,1

    it's free, place queen

    call method again (queen-1)

    check 1,1, check 1,2 check 1,3 check 1,4 etc
    check 2,1, check 2,2

    it's free, place queen

    I do this until I meet a condition where there are no free places... what now? it has to backtrack to the previous queen and replace it. but how do I communicate this to my program? if queen 8 is not placed then the method will return to its previous call and stop there?

    with fibonacci the lowest level returns 1 or 0, something to work with. so my method would have to return a variable to specify no more places to its caller method? you see this is when my head hurts and I dont know what I'm doing anymore...

    do while loop, if varible no more places == true then move queen 7 to the next spot and call queen 8?

    you guys are gonna have to help me now... and remember I'm an idiot, so simple words are nice
    Legend has it the moderators and senior members of java-forums.org were able to code skyrim using only 701 lines of java... or so the legend goes.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,800
    Rep Power
    7

    Default Re: So... the eight queens problem, can you help set me up on the right path

    Quote Originally Posted by EscSequenceAlpha View Post
    check 1,1

    it's free, place queen

    call method again (queen-1)

    check 1,1, check 1,2 check 1,3 check 1,4 etc
    check 2,1, check 2,2
    One way to make the algorithm more efficient: once you have placed n queens you can skip n rows/columns when trying to find where to place the next queen.

Similar Threads

  1. The N Queens Problem
    By IAmDan in forum New To Java
    Replies: 1
    Last Post: 03-19-2012, 09:45 AM
  2. Eight Queens Problem
    By Jtrtoday in forum New To Java
    Replies: 6
    Last Post: 01-29-2012, 12:53 AM
  3. Replies: 2
    Last Post: 03-27-2010, 04:30 AM
  4. Need help with the Eight Queens game
    By kiregad in forum New To Java
    Replies: 11
    Last Post: 03-26-2010, 07:50 PM
  5. Pruning?? (N-Queens problem)
    By n00neimp0rtant in forum New To Java
    Replies: 1
    Last Post: 02-14-2010, 07:41 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •