Can you beat my game?

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

No exe, compile it yourself:

Very simple game, I'm not sure how to beat it. You click the array and you can only move like the horse moves in the chess game. F2 resets the game.

My high score is 42
AppTitle "Small game by nawitus - F2 to restart"

Dim Map(8,8)

Map(4,4) = 1
Global C=1,lastx=4,lasty=4

Graphics 288,288,0,2


Repeat

	Rect 0,0,96,96,1
	Rect 0,192,96,96,1
	Rect 192,0,96,96,1
	Rect 192,192,96,96,1

	For x=0 To 8
		For y=0 To 8
			Rect x*32,y*32,32,32,0
			If Map(x,y) Then Text x*32+10,y*32+10,Map(x,y)
		Next
	Next

	If MouseHit(1) Then
		mx=MouseX():my=MouseY()
		tx = Floor(mx/32)
		ty = Floor(my/32)
		If (tx>-1) And (ty>-1) And (tx<9) And (ty<9)
			If Map(tx,ty) = 0
				If Not(tx<3 And ty<3)
				If Not(tx>5 And ty>5)
				If Not(tx<3 And ty>5)
				If Not(tx>5 And ty<3)
				If check(tx,ty)
				C=c+1
				Map(tx,ty) = C
				lastx=tx
				lasty=ty
				EndIf
				EndIf
				EndIf
				EndIf
				EndIf
			EndIf
		EndIf
	EndIf
	
	If KeyHit(60)
		For x=0 To 8
			For y=0 To 8
				Map(x,y)=0	
			Next
		Next
		C=1
		Map(4,4)=1
		lastx=4
		lasty=4
	EndIf


	Flip
	Cls


Until KeyHit(1)

Function Check(tx,ty)
	If (Abs(lastx-tx) = 2) And (Abs(lasty-ty)=1) Return 1
	If (Abs(lastx-tx) = 1) And (Abs(lasty-ty)=2) Return 1
End Function


I got 36 on my first go.

Maybe you should say it's BPlus code. Anyway here's a BMax conversion:

Strict

AppTitle = "Small game by nawitus - F2 to restart"

Global Map[9,9]

Map[4,4] = 1
Global C=1,lastx=4,lasty=4

Graphics 288,288,0,2


Repeat

	DrawRect 0,0,96,96
	DrawRect 0,192,96,96
	DrawRect 192,0,96,96
	DrawRect 192,192,96,96

	For Local x=0 To 8
		For Local y=0 To 8
			ccDrawRectOutline x*32,y*32,32,32
			If Map[x,y] Then DrawText Map[x,y],x*32+10,y*32+10
		Next
	Next

	If MouseHit(1) Then
		Local mx=MouseX()
		Local my=MouseY()
		Local tx = Floor(mx/32)
		Local ty = Floor(my/32)
		If (tx>-1) And (ty>-1) And (tx<9) And (ty<9)
			If Map[tx,ty] = 0
				If Not(tx<3 And ty<3)
				If Not(tx>5 And ty>5)
				If Not(tx<3 And ty>5)
				If Not(tx>5 And ty<3)
				If check(tx,ty)
				C=c+1
				Map[tx,ty] = C
				lastx=tx
				lasty=ty
				EndIf
				EndIf
				EndIf
				EndIf
				EndIf
			EndIf
		EndIf
	EndIf
	
	If KeyHit(KEY_F2)
		For Local x=0 To 8
			For Local y=0 To 8
				Map[x,y]=0	
			Next
		Next
		C=1
		Map[4,4]=1
		lastx=4
		lasty=4
	EndIf


	Flip
	Cls


Until KeyHit(KEY_ESCAPE)

Function Check(tx,ty)
	If (Abs(lastx-tx) = 2) And (Abs(lasty-ty)=1) Return 1
	If (Abs(lastx-tx) = 1) And (Abs(lasty-ty)=2) Return 1
End Function


' -----------------------------------------------------------------------------
' ccDrawRectOutline
' -----------------------------------------------------------------------------
Function ccDrawRectOutline(x,y,w,h)
	'trim
	w = w-1
	h = h-1
	DrawLine(x,y,x+w,y,0)
	DrawLine(x+w,y,x+w,y+h,0)
	DrawLine(x+w,y+h,x,y+h,0)
	DrawLine(x,y+h,x,y,0)	
End Function


My best score was 28

I got 42, same as you. That's the best I can do.

Nice game :). I got 42.

36 on first as well
nice small game :D

40 on second try. Pretty interesting game. Seems like something that would be on one of those "test your brain power" quizzes.

Intresting game, simple concept too. I will not however, post my embarassing low score though...

42 on first go, had 3 squares empty. I just went in spirals.

weee.. got 42 myself..don't know if it's possible to get more.

41 :(

38 on first try, 42 on second :)
trying for more...

Different solution for 42...

aaargh, can't get past 40 :(

I got 45!..... I GOT 45!!!!!

But only in my dreams. :) No matter how many times I have tried, I cannot get past 41

Cool game, why is it so slow?

What do you mean slow?

When you click it takes a while for anything to appear, it's pig slow in fact.

Runs just fine here even in debug mode which is what I use to run anyone else's code snippets. Just in case.

And as a sidenote,just got figured out how to get 42 :)

You should probably think of upgrading your computer if THIS game is too slow

Its just that when I click it can take up to 5 seconds before the number appears, and I have a Mac G5 so I don't think its the computer.

Cool game. I got 40 on my 1st try.

"You should probably think of upgrading your computer if THIS game is too slow"

LOL

29 on my second go... I'll have to keep working on it :)

EDIT: Okay I'm happy- 42 on my third.

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



Hmm, a brute-force method might take a too long time.

Game is slow because Grey forced it to 2 FPS :D
Remove last 2 from graphics command and it will run just fine.

haha didn't notice it, that would explain it