Created
September 9, 2014 13:53
-
-
Save sajithdilshan/e374eaac555e327d15b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Input: Empty 8x8 matrices: Board, Attacked | |
Output: 8x8 matrix with 8 queens placed; Board | |
EightQueenRandomizedAlgo(Board, Attacked) { | |
int[] usedNumbers = [] | |
while (true) { | |
for(int i = 0; i < 8; i++) { | |
int newRandomNum = 0; | |
while(newRandomNum is not in usedNumbers) { | |
newRandomNum = radomNumberGenerator(0,8) | |
} | |
usedNumbers.append(newRandomNum) | |
if(Attacked[i][newRandomNum] == 1) { | |
break for loop | |
} | |
Board[i][newRandomNum) = 1 | |
update Attacked Matrix | |
} | |
if(i == 8) { | |
return Board | |
} | |
clear Board Matrix | |
clear Attacked Matrix | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment