~cpp $PBExportHeader$eightqueenproblem.sra $PBExportComments$Generated Application Object forward global type eightqueenproblem from application end type global transaction sqlca global dynamicdescriptionarea sqlda global dynamicstagingarea sqlsa global error error global message message end forward global type eightqueenproblem from application string appname = "eightqueenproblem" end type global eightqueenproblem eightqueenproblem type variables Integer il_attack [8,8] , il_limit = 1, il_queen_count = 1 String is_solution[8] end variables forward prototypes public function boolean wf_create_queen () public subroutine wf_reset_maze () public function boolean wf_chack_attack (integer ai_x, integer ai_y) end prototypes public function boolean wf_create_queen ();Integer li_x,li_y Randomize(0) Do While il_queen_count <= 8 li_x = Rand(8) li_y = Rand(8) il_limit++ IF il_limit >= 30000 THEN il_queen_count = 1 RETURN FALSE END IF If wf_chack_attack(li_x, li_y) Then CONTINUE; is_solution[il_queen_count] = 'Queen No : ' + String(il_queen_count) + ' / X : ' + String(li_x) + ' / Y : ' + String(li_y) il_queen_count++ il_limit = 1 LOOP RETURN TRUE end function public subroutine wf_reset_maze ();Integer li_x, li_y String ls_temp[8] FOR li_x = 1 TO 8 FOR li_y = 1 TO 8 il_attack[li_x, li_y] = 0 //공격루트 초기화 NEXT NEXT is_solution = ls_temp end subroutine public function boolean wf_chack_attack (integer ai_x, integer ai_y);//32767 Integer li_x, li_y Yield() IF il_attack[ai_x,ai_y] = 1 THEN RETURN TRUE FOR li_x = 1 TO 8 il_attack[li_x,ai_y] = 1 //X Line 공격루트 셋팅 NEXT FOR li_y = 1 TO 8 il_attack[ai_x,li_y] = 1 //Y Line 공격루트 셋팅 NEXT li_x = ai_x;li_y = ai_y; IF li_x > li_y THEN li_x = li_x + (1 - li_y) li_y = 1 ELSEIF li_x < li_y THEN li_y = li_y + (1 - li_x) li_x = 1 ELSE li_x = 1 li_y = 1 END IF DO WHILE li_x <= 8 AND li_y <= 8 il_attack[li_x,li_y] = 1 //x,y에서 x+n,y+n방향으로 공격루트셋팅 li_x++ li_y++ LOOP li_x = 9 - ai_x;li_y = ai_y; IF li_x > li_y THEN li_x = li_x + (1 - li_y) li_y = 1 ELSEIF li_x < li_y THEN li_y = li_y + (1 - li_x) li_x = 1 ELSE li_x = 1 li_y = 1 END IF DO WHILE li_x <= 8 AND li_y <= 8 il_attack[9 - li_x,li_y] = 1 //x,y에서 x-n,y+n방향으로 공격루트셋팅 li_x++ li_y++ LOOP RETURN FALSE end function on eightqueenproblem.create appname="eightqueenproblem" message=create message sqlca=create transaction sqlda=create dynamicdescriptionarea sqlsa=create dynamicstagingarea error=create error end on on eightqueenproblem.destroy destroy(sqlca) destroy(sqlda) destroy(sqlsa) destroy(error) destroy(message) end on event open;NS: wf_reset_maze() IF NOT wf_create_queen() THEN GOTO NS beep(5) MessageBox('Solution',is_solution[1] + '~r' + & is_solution[2] + '~r' + & is_solution[3] + '~r' + & is_solution[4] + '~r' + & is_solution[5] + '~r' + & is_solution[6] + '~r' + & is_solution[7] + '~r' + & is_solution[8]) end event