Can you beat my game?

Miscellaneous Forums/Blitz Showcase/Can you beat my game?

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi, nice game! I just wrote a program to solve it.
I left it on for 20 minutes and it only got 41, but it checks every possible sequence so eventually it will solve it, if its possible.

AppTitle "Small game by nawitus - F2 to restart"

Dim Map(8,8)


Local X,Y

;setup map
For X=0 To 8
	For Y=0 To 8
		If (X<3 Or X>5) And (Y<3 Or Y>5) Then Map(X,Y)=-1
	Next
Next



Graphics 288,288,0,2



Type Move
	Field X,Y
	Field Did[8]
End Type


Local M
Local MX,MY
Local TX,TY
Local Move.Move
Local Did
Local C,HighC

Move=New Move
Move\X=4
Move\Y=4
Map(4,4) = 1
C=1


;setup legal moves
Local MoveX[8]
Local MoveY[8]
MoveX[0]=+2: MoveY[0]=+1
MoveX[1]=+1: MoveY[1]=+2
MoveX[2]=-1: MoveY[2]=+2
MoveX[3]=-2: MoveY[3]=+1
MoveX[4]=-2: MoveY[4]=-1
MoveX[5]=-1: MoveY[5]=-2
MoveX[6]=+1: MoveY[6]=-2
MoveX[7]=+2: MoveY[7]=-1

Repeat
	;find a move
	For Did=0 To 7
		If Move\Did[Did]=0 Then
			Move\Did[Did]=1
			X=Move\X+MoveX[Did]
			Y=Move\Y+MoveY[Did]
			If (X>=0) And (Y>=0) And (X<=8) And (Y<=8) Then
				If Map(X,Y)=0 Then
					Move=New Move
					Move\X=X
					Move\Y=Y
					C=C+1
					Map(X,Y) = C
					If C>HighC Then HighC=C
					Exit
				EndIf
			EndIf
		EndIf
	Next
	
	;couldn't find a move
	If Did=8 Then
		If C=45 Then WaitKey:RuntimeError "Solved!"
		Map(Move\X,Move\Y)=0
		C=C-1
		Move=Before Move
		Delete Last Move
		If Move=Null Then WaitKey:RuntimeError "tried everything!"
		If KeyHit(1) Then End
	EndIf
	
	;draw
	If C>=40 Then
		Cls
		
		For X=0 To 8
			For Y=0 To 8
				M=Map(X,Y)
				Rect X*32,Y*32,32,32,(M=-1)
				
				If M>0 Then
					Text X*32+10,Y*32+10,M
				EndIf
			Next
		Next
		
		Text 95,-1,HighC
	EndIf
	
	
Forever


Function CanMove(X1,Y1,X2,Y2)
	If (Abs(X1-X2) = 2) And (Abs(Y1-Y2)=1) Then Return 1
	If (Abs(X1-X2) = 1) And (Abs(Y1-Y2)=2) Then Return 1
End Function


Function SpotOK(X,Y)
	If (X<0) Or (Y<0) Or (X>8) Or (Y>8) Then Return 0
	Return (Map(X,Y)=0)
End Function