# An 8 queen puzzle solver

Email
 Submitted on: 1/3/2015 1:48:00 AM By: KYG (from psc cd) Level: Beginner User Rating: By 2 Users Compatibility: C++ (general), Microsoft Visual C++ Views: 2630

solves the 8 queen puzzle using random generator and recursion. results in very fast answers for a chess board of any size, specified in the code

code:
Can't Copy and Paste this?
 ``` //************************************** // Name: An 8 queen puzzle solver // Description:solves the 8 queen puzzle using random generator and recursion. results in very fast answers for a chess board of any size, specified in the code // By: KYG (from psc cd) //************************************** //By koon yiak //feel free to use the code and //to tell me about possible improvements #include #include #include const int chessboardsize=40; //size of chessboard enum{empty, queen, used}; //status struct move{ //movement direction int x; int y; }; struct chessboard{ //chessboard type int size; int square[chessboardsize][chessboardsize]; int usedsquares; int noqueens; }; void setqueenmovdi(move *whatmove, chessboard *board, move *curcoor); void main() { move curcoor; move NE; NE.x=1; NE.y=1; //define digonal movements move NW; NW.x=-1; NW.y=1; move SE; SE.x=1; SE.y=-1; move SW; SW.x=-1; SW.y=-1; chessboard board; board.size=chessboardsize; // srand(time(0)); while(board.noqueens!=board.size ){ board.usedsquares=0; board.noqueens=0; for(int i=0;ix+whatmove->x; next.y=curcoor->y+whatmove->y; if(next.x<0||next.x>board->size-1||next.y<0||next.y>board->size-1)return; if(board->square[next.x][next.y]==empty){ board->square[next.x][next.y]=used; ++board->usedsquares; } setqueenmovdi(whatmove,board,&next); return; }```

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)