News:

Welcome to RetroCoders Community

Main Menu

Knightsbridge

Started by johnno56, Apr 17, 2023, 10:27 AM

Previous topic - Next topic

johnno56

Here is BAM's version of Tim Hartnell's Knightbridge.

Navigation takes a bit of getting used to... Each move is exactly like a chess knight.
You will be asked to move a piece (randomly selected). For example: If you are asked to move the piece on 14. You could move two up and one left to 33; or two up and one right to 35; or one up and two left to 22; or one up and two right to 26.

Entering a two digit destination is made up of a "Y" axis and an "X" axis.

I will attach a sample screen....

Again, if you find any bugs or you can think of some improvements, just let me know...
(ignore the coloured numbers. Used for text colour reference)

Rem Knightsbridge
Dim H(99), Z(8)
title$ = "KNIGHTBRIDGE"
GoSub Initialise

MainLoop:
	GoSub PrintBoard
	If HU = 5 Or CO = 5 Then GoTo GameOver
	GoSub ComputerMove
	GoSub PrintBoard
	If HU = 5 Or CO = 5 Then GoTo GameOver
	GoSub HumanMove
GoTo MainLoop

HumanMove:
Q = 0

label130:
M = Int(Rnd * 66) + 11
Q = Q + 1
If Q = 500 Then GoTo GameOver
If H(M) <> 72 Then GoTo label130
color 11: Print "You must move the piece on "; M

label180:
Input N
If N = 99 Then Q = 500: GoTo GameOver
Rem *** Check if move legal ***
P = 0
CT = 1

label230:
If M + Z(CT) = N Then P = 1
If CT < 8 Then CT = CT + 1: GoTo label230
If P = 0 Then color 13: Print "Illegal move": GoTo label180
If H(N) = 67 Then HU = HU + 1: color 14: Print "Well played!": _delay 3
H(M) = 46: H(N) = 72
Return

ComputerMove:
Q1 = 0

label320:
Q1 = Q1 + 1
K = Int(Rnd * 66) + 11
If Q1 = 500 Then GoTo GameOver
If H(K) <> 67 Then GoTo label320
color 12: Print "I have to move the piece on "; K: _delay 4
W = 1

label380:
If K + Z(W) < 11 Or K + Z(W) > 77 Then GoTo label400
If H(K + Z(W)) = 72 Then color 14: Print "Gotcha!!": CO = CO + 1: _delay 3: GoTo label450

label400:
If W < 8 Then W = W + 1: GoTo label380
W = 1

label420:
If (K + Z(W) < 11 Or K + Z(W) > 77) And W < 8 Then W = W + 1: GoTo label420

label430:
If H(K + Z(W)) <> 46 And W < 8 Then W = W + 1: GoTo label430
If W = 8 And H(K + Z(W)) <> 46 Then Q1 = 500: GoTo GameOver

label450:
X = K: Y = K + Z(W)
H(X) = 46: H(Y) = 67
Return

PrintBoard:
Cls: color 14: Print: Print "        "; title$: Print: Print
locate ,8: color 2: Print "  My score: ";: color 12: Print CO
locate ,8: color 2: Print "Your score: ";: color 11: Print HU
Print
locate ,8: color 7: Print "1 2 3 4 5 6 7"
locate ,8: color 7: Print "- - - - - - -"
For M = 70 To 10 Step -10
	locate ,6: color 7: Print M / 10;" ";
	For N = 1 To 7
		If Chr$(H(M + n)) = "H" Then color 11
		If Chr$(H(M + n)) = "C" Then color 12
		If Chr$(H(M + n)) = "." Then color 2
		Print Chr$(H(M + N)); " ";
	Next N
	color 7: Print M / 10
Next M
locate ,8: Print "- - - - - - -"
locate ,8: Print "1 2 3 4 5 6 7"
Print

'	Colour test only...
'for col = 1 to 20
'	color col
'	locate col, 35: Print col
'next col
'color 7

Return

GameOver:
GoSub PrintBoard
If HU = 5 Then color 12: Print "Beaten by a mere human...": Print "The shame. The shame of it all..."
If CO = 5 Then color 12: Print "This victory is the first": Print "step in our plan to take": Print "over the entire earth!"
If Q = 500 Then color 12: Print "I accept your wish to concede"
If Q1 = 500 Then color 12: Print "I concede to a Master"
End

Initialise:
Screen 7: Width 40: color 14:Print: locate ,20-len(title$)/2: Print title$
locate 7, 7: color 2: Print "Please stand by ... ";
_delay 2: color 10: Print "human": _delay 3

Cls: Print: locate ,20-len(title$)/2: color 14: Print title$

Print: Print: color 10
Print "In this game we will play on a 7x7 board";
Print "using seven Chess set Knights each. We"
Print "will take turns by trying to remove each";
Print "other's pieces by landing on them."
Print: color 18
Print "All pieces MUST move in the same manner"
Print "as real chess knights. The first player"
Print "to reach 5 points will be the winner."
Print: Print: color 14
Print "     Press ";: color 10: Print"ENTER ";: color 14: Print "when you are ready."
Do while inkey$ <> chr$(13)
_delay 0.01
loop
Cls
Rem
X = 0: Q1 = O: Q = 0
Randomize Timer
HU = O: CO = O: Rem Scores
For A = 1 To 99
If A > 77 Or A = 70 Or A = 60 Or A = 68 Or A = 69 Or A = 50 Or A = 59 Or A = 40 Or A = 48 Or A = 49 Then GoTo label880
If A = 30 Or A = 38 Or A = 39 Or A = 20 Or A = 28 Or A = 29 Or A = 18 Or A = 19 Or A < 11 Then GoTo label880
H(A) = 46
If A > 70 And A < 78 Then H(A) = 67
If A > 10 And A < 18 Then H(A) = 72

label880:
Next A
For A = 1 To 8: Read Z(A): Next A
Data -8,-21,-12,-19,19,12,21,8
Return

May your journey be free of incident.  Live long and prosper.

CharlieJV

Just played my first game, and I somehow managed to beat the program.

That was a blast!


johnno56

Just played it again and was soundly thrashed... 5 to 1.... *sigh*
May your journey be free of incident.  Live long and prosper.

CharlieJV

I still want to test this new _DEFCHR$ statement a bit before I roll it out.

How about an 8x8 chess piece?

You cannot view this attachment.

CharlieJV

Quote from: johnno56 on Apr 19, 2023, 06:03 AMJust played it again and was soundly thrashed... 5 to 1.... *sigh*

Only my third game, but I am really having a lot of fun playing this game.

You cannot view this attachment.


johnno56

I had an Amstrad CPC464 that could "define" a character. Efficient way of printing "tiles" of 8x8 instead of taking the time to individually plot all 64 pixels...

I see... Beating the machine by the third game? Now you are just showing off... lol  Glad you are enjoying it...
May your journey be free of incident.  Live long and prosper.

johnno56

UPDATE:

Used the LETCHR$() to define the Knights. Thank you for the idea. Looks a little better! (IMHO) lol

Rem Knightsbridge
Dim H(99), Z(8)
Screen 7: Width 40:
title$ = "KNIGHTSBRIDGE"
GoSub Initialise

MainLoop:
	GoSub PrintBoard
	If HU = 5 Or CO = 5 Then GoTo GameOver
	GoSub ComputerMove
	GoSub PrintBoard
	If HU = 5 Or CO = 5 Then GoTo GameOver
	GoSub HumanMove
GoTo MainLoop

HumanMove:
Q = 0

label130:
M = Int(Rnd * 66) + 11
Q = Q + 1
If Q = 500 Then GoTo GameOver
If H(M) <> 72 Then GoTo label130
color 11: Print "You must move the piece on "; M

label180:
Input N
If N = 99 Then Q = 500: GoTo GameOver
Rem *** Check if move legal ***
P = 0
CT = 1

label230:
If M + Z(CT) = N Then P = 1
If CT < 8 Then CT = CT + 1: GoTo label230
If P = 0 Then color 13: Print "Illegal move": GoTo label180
If H(N) = 67 Then HU = HU + 1: color 14: Print "Well played!": _delay 3
H(M) = 46: H(N) = 72
Return

ComputerMove:
Q1 = 0

label320:
Q1 = Q1 + 1
K = Int(Rnd * 66) + 11
If Q1 = 500 Then GoTo GameOver
If H(K) <> 67 Then GoTo label320
color 12: Print "I have to move the piece on "; K: _delay 4
W = 1

label380:
If K + Z(W) < 11 Or K + Z(W) > 77 Then GoTo label400
If H(K + Z(W)) = 72 Then color 14: Print "Gotcha!!": CO = CO + 1: _delay 3: GoTo label450

label400:
If W < 8 Then W = W + 1: GoTo label380
W = 1

label420:
If (K + Z(W) < 11 Or K + Z(W) > 77) And W < 8 Then W = W + 1: GoTo label420

label430:
If H(K + Z(W)) <> 46 And W < 8 Then W = W + 1: GoTo label430
If W = 8 And H(K + Z(W)) <> 46 Then Q1 = 500: GoTo GameOver

label450:
X = K: Y = K + Z(W)
H(X) = 46: H(Y) = 67
Return

PrintBoard:
Cls: color 14: Print: Print "        "; title$: Print: Print
locate ,8: color 2: Print "  My score: ";: color 12: Print CO
locate ,8: color 2: Print "Your score: ";: color 11: Print HU
Print
locate ,8: color 7: Print "1 2 3 4 5 6 7"
locate ,8: color 7: Print "- - - - - - -"
For M = 70 To 10 Step -10
	locate ,6: color 7: Print M / 10;" ";
	For N = 1 To 7
		If Chr$(H(M + n)) = "H" Then
			color 11
			Print CHR$(human);" ";
		end if
		If Chr$(H(M + n)) = "C" Then
			color 12
			Print CHR$(comp);" ";
		end if
		If Chr$(H(M + n)) = "." Then
			color 2
			Print Chr$(H(M + N)); " ";
		end if
	Next N
	color 7: Print M / 10
Next M
locate ,8: Print "- - - - - - -"
locate ,8: Print "1 2 3 4 5 6 7"
Print

'	Colour test only...
'for col = 1 to 20
'	color col
'	locate col, 35: Print col
'next col
'color 7

Return

GameOver:
GoSub PrintBoard
If HU = 5 Then color 12: Print "Beaten by a mere human...": Print "The shame. The shame of it all..."
If CO = 5 Then color 12: Print "This victory is the first": Print "step in our plan to take": Print "over the entire earth!"
If Q = 500 Then color 12: Print "I accept your wish to concede"
If Q1 = 500 Then color 12: Print "I concede to a Master"
End

Initialise:
'
'		Define the characters - New function!
'
comp = 0
human = 1
_LETCHR$(0, _
	"....X..." + _
	"..XXXX.." + _
	".XXXXXX." + _
	"XXXX..XX" + _
	"XXXXX..." + _
	".XXXXX.." + _
	"..XXXX.." + _
	"XXXXXXXX")
	
_LETCHR$(1, _
	"...X...." + _
	"..XXXX.." + _
	".XXXXXX." + _
	"XX..XXXX" + _
	"...XXXXX" + _
	"..XXXXX." + _
	"..XXXX.." + _
	"XXXXXXXX")

CLS: color 14:Print: locate ,20-len(title$)/2: Print title$
locate 7, 7: color 2: Print "Please stand by ... ";
_delay 2: color 10: Print "human": _delay 3

Cls: Print: locate ,20-len(title$)/2: color 14: Print title$

Print: Print: color 10
Print "In this game we will play on a 7x7 board";
Print "using seven Chess set Knights each. We"
Print "will take turns by trying to remove each";
Print "other's pieces by landing on them."
Print: color 18
Print "All pieces MUST move in the same manner"
Print "as real chess knights. The first player"
Print "to reach 5 points will be the winner."
Print: Print: color 14
Print "     Press ";: color 10: Print"ENTER ";: color 14: Print "when you are ready."
Do while inkey$ <> chr$(13)
_delay 0.01
loop
Cls
Rem
X = 0: Q1 = O: Q = 0
Randomize Timer
HU = O: CO = O: Rem Scores
For A = 1 To 99
If A > 77 Or A = 70 Or A = 60 Or A = 68 Or A = 69 Or A = 50 Or A = 59 Or A = 40 Or A = 48 Or A = 49 Then GoTo label880
If A = 30 Or A = 38 Or A = 39 Or A = 20 Or A = 28 Or A = 29 Or A = 18 Or A = 19 Or A < 11 Then GoTo label880
H(A) = 46
If A > 70 And A < 78 Then H(A) = 67
If A > 10 And A < 18 Then H(A) = 72

label880:
Next A
For A = 1 To 8: Read Z(A): Next A
Data -8,-21,-12,-19,19,12,21,8
Return
May your journey be free of incident.  Live long and prosper.

CharlieJV

That kind of makes it look spiffy for character-based graphics.

I updated the published version.

Of course, I had to play a couple of games in order to get spanked both times...

CharlieJV

There's a bug somewhere.

Twice now tonight, the piece played by the computer disappears.  I'm suspecting, both times, the computer moved the piece to a position that already has a computer piece.

Is that a bug or a design feature (as in a player can have multiple knights at the same position?)


You cannot view this attachment.

CharlieJV

Ah, computer just moved a hidden piece from position 58 !!!

johnno56

#11
Ha! Assassin! Must be a random feature! I do not believe that I am clever enough to code that one! lol

But, just to be certain, I will go over the original and converted codes... Chances are it was probably my fault... lol
May your journey be free of incident.  Live long and prosper.

CharlieJV

I'm still enjoying this something silly.

You cannot view this attachment.

ZXDunny

Does anyone mind if I do a version of this for SpecBAS? I'm gonna probably add graphics and mouse control though?

CharlieJV

Quote from: ZXDunny on Jul 26, 2023, 01:28 PMDoes anyone mind if I do a version of this for SpecBAS? I'm gonna probably add graphics and mouse control though?

I think that would be very cool, but I have no say in it: this is johnno56's baby.