Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

EightQueenProblem/용쟁호투: Difference between revisions

From ZeroWiki
imported>Unknown
No edit summary
 
(Repair batch-0002 pages from live compare)
 
Line 26: Line 26:
   
   
  type variables
  type variables
  Integer il_attack [8,8] , il_limit = 1, il_queen_count = 1
  Integer il_attack [8,8] , il_limit = 1, il_queen_count = 1
  String is_solution[8]
  String is_solution[8]
  end variables
  end variables
   
   
Line 48: Line 48:
  END IF
  END IF
  If wf_chack_attack(li_x, li_y) Then CONTINUE;
  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)
  is_solution[il_queen_count] = 'Queen No : ' + String(il_queen_count) + ' / X : ' + String(li_x) + ' / Y : ' + String(li_y)
  il_queen_count++
  il_queen_count++
  il_limit = 1
  il_limit = 1
Line 57: Line 57:
   
   
  public subroutine wf_reset_maze ();Integer li_x, li_y
  public subroutine wf_reset_maze ();Integer li_x, li_y
  String ls_temp[8]
  String ls_temp[8]
   
   
  FOR li_x = 1 TO 8
  FOR li_x = 1 TO 8
  FOR li_y = 1 TO 8
  FOR li_y = 1 TO 8
  il_attack[li_x, li_y] = 0 //공격루트 초기화
  il_attack[li_x, li_y] = 0 //공격루트 초기화
  NEXT
  NEXT
  NEXT
  NEXT
Line 73: Line 73:
  Yield()
  Yield()
   
   
  IF il_attack[ai_x,ai_y] = 1 THEN RETURN TRUE
  IF il_attack[ai_x,ai_y] = 1 THEN RETURN TRUE
   
   
  FOR li_x = 1 TO 8
  FOR li_x = 1 TO 8
  il_attack[li_x,ai_y] = 1 //X Line 공격루트 셋팅
  il_attack[li_x,ai_y] = 1 //X Line 공격루트 셋팅
  NEXT
  NEXT
   
   
  FOR li_y = 1 TO 8
  FOR li_y = 1 TO 8
  il_attack[ai_x,li_y] = 1 //Y Line 공격루트 셋팅
  il_attack[ai_x,li_y] = 1 //Y Line 공격루트 셋팅
  NEXT
  NEXT
   
   
Line 97: Line 97:
  END IF
  END IF
  DO WHILE li_x <= 8 AND li_y <= 8
  DO WHILE li_x <= 8 AND li_y <= 8
  il_attack[li_x,li_y] = 1 //x,y에서 x+n,y+n방향으로 공격루트셋팅
  il_attack[li_x,li_y] = 1 //x,y에서 x+n,y+n방향으로 공격루트셋팅
  li_x++
  li_x++
  li_y++
  li_y++
Line 114: Line 114:
  END IF
  END IF
  DO WHILE li_x <= 8 AND li_y <= 8
  DO WHILE li_x <= 8 AND li_y <= 8
  il_attack[9 - li_x,li_y] = 1 //x,y에서 x-n,y+n방향으로 공격루트셋팅
  il_attack[9 - li_x,li_y] = 1 //x,y에서 x-n,y+n방향으로 공격루트셋팅
  li_x++
  li_x++
  li_y++
  li_y++
Line 144: Line 144:
  IF NOT wf_create_queen() THEN GOTO NS
  IF NOT wf_create_queen() THEN GOTO NS
  beep(5)
  beep(5)
  MessageBox('Solution',is_solution[1] + '~r' + &
  MessageBox('Solution',is_solution[1] + '~r' + &
                       is_solution[2] + '~r' + &
                       is_solution[2] + '~r' + &
                       is_solution[3] + '~r' + &
                       is_solution[3] + '~r' + &
                       is_solution[4] + '~r' + &
                       is_solution[4] + '~r' + &
                       is_solution[5] + '~r' + &
                       is_solution[5] + '~r' + &
                       is_solution[6] + '~r' + &
                       is_solution[6] + '~r' + &
                       is_solution[7] + '~r' + &
                       is_solution[7] + '~r' + &
                       is_solution[8])
                       is_solution[8])
   
   
  end event
  end event

Latest revision as of 00:16, 27 March 2026

왜? 이런짓을 저질럿나?

C, C++, Python, Java, Delphi등이 있었으나...제가 주로사용하는 Powerbuilder로 해보고 싶은 마음에 도전하게 되었습니다...

원리는 공격당하는 위치를 등록하여 퀸이 만들어질때 공격여부를 체크하는 방식입니다...공격안당하는 자리나올때까지 루프루프루프.....

재귀하는것이 귀찮아서 봉인되어있던 GOTO문을 사용했습니다...

디자인 무시,객체지향 무시, 문제 보고 코딩시작,수많은 삽질...전형적인 초보수준입니다...한마디로 쓰레기 입니다! T_T

파워빌더 소스(eightqueenproblem.sra)

$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