Variables
---------
A = Cursor X
B = Cursor Y
C = 2nd cursor X
D = 2nd cursor Y
E = Temporary X
F = Temporary Y
Q = X for checking around king
R = Y for checking around king
Z = currently selected piece
3 if attacker
4 if defender
5 if king
T = 0 if attacker's turn
1 if defender's turn
X = Various temporary uses
K = getKey
O = Attacker captures
N = Defender captures
V = 0 normally
1 if attacker wins
2 if defender wins
Θ = Main loop variable
L = Turn loop variable
Matrix [A]
0 = blank tile
1 = corner
2 = throne (once the king moves off the throne it will change to 2)
3 = attacker (black)
4 = defender (white)
5 = king
Pic1 = Title
Pic2 = Starting board
Pic3 = Current board (temporary)
L1 = User's window setting
L2 = Pieces around the pieces you moved. Used in prgmHCHK (temporary)
L3 = Very temporarily used for checking for on the king
_________________________________________________________________________
Source for prgmA ≠ Δ
----------------
// Typical startup.
ClrHome
ClrDraw
AxesOff
0→Θ:0→O:0→N
0→V:0→K
// Storing user's window for convenience
{Xmin,Xmax,Ymin,Ymax→L1
0→Xmin
94→Xmax
-62→Ymin
0→Ymax
// Title screen code
RecallPic 1
50→X
Repeat K=105 or K=21
getKey→K
If X=50
Text(40,27,"PRESS ENTER.
If X=25
Text(40,27,"
X-1→X
If X=0
50→X
End
// Sets up the GUI
ClrDraw
RecallPic 2
Line(62,-30,92,-30
Text(32,62,"CAPTURES
Text(39,69,0
Text(39,84,0
Line(62,-47,92,-47
0→T // 0 = attacker's turn
// 1 = defender's turn
// Matrix for the board
//// 0 = blank tile
//// 1 = corner
//// 2 = throne (once the king moves off the throne it will change to 2)
//// 3 = attacker (black)
//// 4 = defender (white)
//// 5 = king
[[1,0,0,3,3,3,3,3,0,0,1][0,0,0,0,0,3,0,0,0,0,0][0,0,0,0,0,0,0,0,0,0,0][3,0,0,0,0,4,0,0,0,0,3][3,0,0,0,4,4,4,0,0,0,3][3,3,0,4,4,5,4,4,0,3,3][3,0,0,0,4,4,4,0,0,0,3][3,0,0,0,0,4,0,0,0,0,3][0,0,0,0,0,0,0,0,0,0,0][0,0,0,0,0,3,0,0,0,0,0][1,0,0,3,3,3,3,3,0,0,1→[A]
1→A // X coordinate of the cursor
1→B // Y coordinate of the cursor
// Main loop
Repeat Θ
If T
Then
Text(49,65,"WHITE'S
Text(55,70,"TURN
Else
Text(49,65,"BLACK'S
Text(55,70,"TURN
End
0→L
StorePic 3 // Temporary pic of the current board setup
// Turn loop
Repeat L
RecallPic 3
// Draws box (cursor) around current location
Line(5A-1,-(5B),5A+4,-(5B
Line(5A+4,-(5B),5A+4,-(5B+5
Line(5A+4,-(5B+5),5A-1,-(5B+5
Line(5A-1,-(5B+5),5A-1,-(5B
Repeat max(K={21,24,25,26,34,45,105
getKey→K
End
// If you hit 'clear', exits both loops
If K=45
Then
1→Θ
1→L
End
// Erases cursor
Line(5A-1,-(5B),5A+4,-(5B),0
Line(5A+4,-(5B),5A+4,-(5B+5),0
Line(5A+4,-(5B+5),5A-1,-(5B+5),0
Line(5A-1,-(5B+5),5A-1,-(5B),0
// Movement code
min(11,max(1,A+max(ΔList(K={24,26→A
min(11,max(1,B+max(ΔList(K={25,34→B
[A](B,A→Z // Piece on current location
If (K=105 or K=21) and (Ans=3+T or Ans=3+2(T
Then
A→C
B→D
Repeat max(K={45,105,21
// Keeps cursor around piece you're moving
Line(5A-1,-(5B),5A+4,-(5B
Line(5A+4,-(5B),5A+4,-(5B+5
Line(5A+4,-(5B+5),5A-1,-(5B+5
Line(5A-1,-(5B+5),5A-1,-(5B
// Draws cursor around spot you're moving to
Line(5C-1,-(5D),5C+4,-(5D
Line(5C+4,-(5D),5C+4,-(5D+5
Line(5C+4,-(5D+5),5C-1,-(5D+5
Line(5C-1,-(5D+5),5C-1,-(5D
Repeat K
getKey→K
End
// Erases 2nd cursor
Line(5C-1,-(5D),5C+4,-(5D),0
Line(5C+4,-(5D),5C+4,-(5D+5),0
Line(5C+4,-(5D+5),5C-1,-(5D+5),0
Line(5C-1,-(5D+5),5C-1,-(5D),0
// Code to force your only options to be moving
// in one direction.
If D=B
Then
max(ΔList(K={24,26
C+Ans→E
min(11,max(1,Ans→E
not((A=E and B=D
Ans*[A](D,E
If (Z=5)(Ans=1 or Ans=2) or not(Ans
E→C
End
If C=A
Then
max(ΔList(K={25,34
D+Ans→F
min(11,max(1,Ans→F
not((A=C and B=F
Ans*[A](F,C
If (Z=5)(Ans=1 or Ans=2) or not(Ans
F→D
End
End
// Once again, ends loops on 'clear'
If K=45
Then
1→Θ
1→L
End
// Changes position of piece you move and ends the loop if it's not
// the same spot.
If K=105 or K=21
Then
0→[A](B,A
Z→[A](D,C
If A≠C or B≠D
1→L
End
// Erases old cursor
Line(5A-1,-(5B),5A+4,-(5B),0
Line(5A+4,-(5B),5A+4,-(5B+5),0
Line(5A+4,-(5B+5),5A-1,-(5B+5),0
Line(5A-1,-(5B+5),5A-1,-(5B),0
End
End
// If you didn't hit clear, it checks for captures and winning
// in prgmHCHK
If not(Θ
prgmHCHK
// If someone, get out.
If V
Goto V
// Changes turns.
If T
Then
0→T
Else
1→T
End
End
Lbl V
// Draws a box to hold the text
Line(28,-28,69,-28
Line(69,-28,69,-36
Line(69,-36,28,-36
Line(28,-36,28,-28
Line(29,-35,68,-35,0
// Shows who won in the box...
If V=2
Text(29,29," WHITE WINS!
If V=1
Text(29,29," BLACK WINS!
If V
Pause
// Returns their windows back to normal.
L1(1→Xmin
L1(2→Xmax
L1(3→Ymin
L1(4→Ymax
// Clearing and all that.
ClrDraw
Output(1,1,"
_________________________________________________________________________
Source for prgmHCHK
(you shouldn't need to change this, it handle both sides perfectly
just make sure that after the person has made a valid move, run this
program and it will capture any pieces necessary also, make sure to
add "If V:Goto V" after prgmHCHK or it will run the player's turn
before letting anyone know if they won.)
-------------------
Line(5A,-(5B+1),5A+3,-(5B+1),0
Line(5A,-(5B+2),5A+3,-(5B+2),0
Line(5A,-(5B+3),5A+3,-(5B+3),0
Line(5A,-(5B+4),5A+3,-(5B+4),0
If Z=3
Then
Line(5C+1,-(5D+1),5C+2,-(5D+1
Line(5C,-(5D+2),5C+3,-(5D+2
Line(5C,-(5D+3),5C+3,-(5D+3
Line(5C+1,-(5D+4),5C+2,-(5D+4
End
If Z=4
Then
Line(5C+1,-(5D+1),5C+2,-(5D+1
Line(5C+3,-(5D+2),5C+3,-(5D+3
Line(5C+2,-(5D+4),5C+1,-(5D+4
Line(5C,-(5D+3),5C,-(5D+2
End
If Z=5
Then
Line(5C,-(5D+1),5C+3,-(5D+1),0
Line(5C+1,-(5D+1),5C+2,-(5D+1
Line(5C,-(5D+2),5C+3,-(5D+2
Line(5C+1,-(5D+3),5C+2,-(5D+3
Line(5C,-(5D+4),5C+3,-(5D+4
End
{0,0,0,0üL2
If C≠1
[A](D,C-1→L2(2
If C≠11
[A](D,C+1→L2(3
If D≠1
[A](D-1,C→L2(1
If D≠11
[A](D+1,C→L2(4
If Z>3
Then
3.6→W
Else
4.5→W
End
0→U
For(X,1,4
If L2(X
Then
0→E
0→F
If X=1
-1→F
If X=2
-1→E
If X=3
1→E
If X=4
1→F
[A](D+F,C+E→I
If Ans=iPart(W) or Ans=fPart(W
Then
{min(11,max(1,D+F+F)),min(11,max(1,C+E+E→L3
[A](L3(1),L3(2
If Ans=1 or (L3(1)=6 and L3(2)=6) or Ans=Z or Ans=Z+(Z=4) or Ans=Z-(Z=5
Then
If Z=3
Then
N+1→N
Text(39,69-2(N>9),N
Else
O+1→O
Text(39,84-2(O>9),O
End
0→[A](D+F,C+E
Line(5(C+E),-(5(D+F)+1),5(C+E)+3,-(5(D+F)+1),0
Line(5(C+E),-(5(D+F)+2),5(C+E)+3,-(5(D+F)+2),0
Line(5(C+E),-(5(D+F)+3),5(C+E)+3,-(5(D+F)+3),0
Line(5(C+E),-(5(D+F)+4),5(C+E)+3,-(5(D+F)+4),0
End
End
End
End
// Checks around the king
1→Q:1→R
While 5≠[A](Q,R
Q+1→Q
If Q>11
Then
1→Q
R+1→R
End
End
// If the king is surrounded, 1 = V
{[A](min(11,Q+1),R),[A](max(1,Q-1),R),[A](Q,min(11,R+1)),[A](Q,max(1,R-1→L2
If 4=sum(3=L2)+sum(5=L2)+sum(2=L2)+sum(1=L2
1→V
// If king got to a corner, 2 = V
If max(5={[A](1,1),[A](1,11),[A](11,1),[A](11,11
2→V
// If center square don't have the king on it, it equals 2
// and draws the throne in.
If 0=[A](6,6
Then
2→[A](6,6
Line(30,-31,33,-34
Line(30,-34,33,-31
End