Skip to main content

Timeline for Eight queens with Java

Current License: CC BY-SA 3.0

7 events
when toggle format what by license comment
Oct 27, 2017 at 13:58 comment added Imus @IbrahimAli That random placement will always be relatively slow. Like I mensioned in the post: If you want to find a solution fast, use the backtracking idea of CiaPan instead of random placement. If you do so, feel free to post that new code in a new review question here to ask for more pointers on how to speed it up even more.
Oct 27, 2017 at 13:55 comment added Imus Aha true CiaPan. Well spotted. I only did the minimal change to generate one on each row in the original code. That's why I just passed in that i to the method. I also noticed the now redundant check, but that only gains you less than a millisecond in finding the solution. So you can't really tell the difference anyway.
Oct 27, 2017 at 13:39 comment added CiaPan @Imus You don't need the do – while loop, as each placeQueens(i) invoked by the for (int i = 0; i < 8; i++) loop allocates a position in a separate row, hence collisions are impossible and testing for them is a waste of time.
Oct 27, 2017 at 13:31 comment added Ibrahim Ali @CiaPan I'm thinking for n position for n boolean simply i create a boolean array and use it's index by depend on random queens, every generated queens i set illegal index to false in the boolean array which will be short much time.
Oct 27, 2017 at 12:55 comment added CiaPan There is another point worth considering: @IbrahimAli didn't say what actually his aim is, finding any valid arrangement or all valid arrangments of 8 Queens. Systematic search enclosed in a loop will do the latter (return all possible solutions, and each exactly once), while random generating can not (may well repeat answers and we never know if it found all possibilities; with poor RNG quality it may be even unable to find some).
Oct 27, 2017 at 12:34 comment added Ibrahim Ali Thanks for the great answer, but it's seems that i already finished fast one but still have issue with set random queen.
Oct 27, 2017 at 10:59 history answered Imus CC BY-SA 3.0