# http://www.ex-parrot.com/~tom/calcs/calcs/encyc/progs/src/colony.ctf
# ========================================================================
# Program name: Colony
#
# Version: 1.0
# Author: Tom Lynn
# Date: 1995-1998
# Models: 9700
#
#
# Description:
#
# A two-player "board game".
#
# This program also works with 9750, 9850 or 9950 calculators, but for those
# models it is better to use "Colony 3".
#
# * Rules *
#
# This game is played on a hexagonal grid. Players take turns putting 'seeds'
# into hexagons. Once a seed has been put into a hexagon, that hexagon is
# considered to have been 'colonised' by that player. This means that their
# opponent can't put any seeds there. The object of the game is to colonise
# the entire board by wiping out all of your opponent's colonies.
#
# Players can continue putting seeds into a hexgon until it contains the same
# number of seeds as it has neighbouring hexagons. When this happens, the
# hexagon 'explodes', sending one seed into each neighbouring hexagon. This
# leaves the exploded hexagon empty, at which point it can be colonised by
# either player again.
#
# If one of your hexagons explodes into one of your opponent's hexagons, all of
# the seeds in that hexagon are converted into your seeds. If when an exploding
# hexagon adds a seed to a neighbouring hexagon the neighbouring hexagon becomes
# full (ie it has as many seeds as it has neighbours), that hexagon will also
# explode. In this way, you can start 'chain reactions', which can annihilate
# your opponent at a stroke (if you're lucky).
#
# * How To Play *
#
# To add a seed to a hexagon, click on it. That's all there is to it. If you
# forget whose turn it is, click outside the board. You are advised to choose
# a small board size while you are learning the game. To click in a hexagon,
# move the pointer to the hexagon with the arrow keys and press [EXE].
#
# * Entering the Programs *
#
# Once you have entered the programs, you must define Matrix Y with the
# dimensions of the board you intend to play on (it must be square). If you
# set the dimensions to 6x6 you will not need to change them again, but it
# will use more memory than a smaller board (it uses 10 bytes per hexagon).
#
# This program cannot be used with pre-9700 calcs, as it uses the matrix
# memories and is too large for tweaking to use the SD memories (I think).
# It may be necessary to tweak the graphics for non-widescreen calcs (fx9800),
# I don't know. If it is and you need help, mail me at tom-calcs@mythic-beasts.com.
#
# If you are using a 9x50 calc, you will need to change the names of the progs.
# I have suggested appropriate changes in the comments.
@@ Program "~COLONY"
# Main routine
" \*\*\*\*\* COLONY \*\*\*\*\*"
"1. New game"
"2. Continue game"
?->X
Lbl 0
"Enter size (2(-)6):" ; (-) means unary minus, but you can use - if you want
?->A
Int A->A
A<2=>Goto 0
A>6=>Goto 0
Range 1,127,0,1,63,0
1->P
X=2=>Goto 3
0->L
Prog 2 ; fx-9x50s: 0Mat Y->Mat Y (That's a zero, not a letter O)
Lbl 2
Cls
Prog "CODRAWBOARD" ; fx-9x50s: Prog "CODRAWBD"
Prog "COFILLBOARD" ; fx-9x50s: Prog "COFILLBD"
(-)P->P
Lbl 1
Prog O ; fx-9x50s: Prog "COCHKWIN"
Prog "COPLAY"
Prog "CODRAWBOARD" ; fx-9x50s: Prog "CODRAWBD"
Prog "COFILLBOARD" ; fx-9x50s: Prog "COFILLBD"
Goto 1
Lbl 3
Prog P ; fx-9x50s: Prog "COPLAYER"
1->P
Frac .5L=0=>Goto 2
(-)P->P
Goto 2
@@ Program "COADDSEED"
# fx-9x50s: "CO+SEED"
Isz L
Prog M ; fx-9x50s: Prog "COTRY"
Prog "COCHK4BANG" ; fx-9x50s: Prog "COCHKBNG"
@@ Program "COCHK4BANG"
# fx-9x50s: Prog "COCHKBNG"
Lbl 0
A->R~S
Lbl 1
R->T
S->U
Prog 3 ; fx-9x50s: Prog "COBANG"
Dsz S
Goto 1
A->S
Dsz R
Goto 1
@@ Program "COCHOOSESEED"
# fx-9x50s: "COCHOOSE"
Prog N ; fx-9x50s: Prog "COPUT"
0->I~J
Lbl 0
J>=0=>J<=1=>U-1<1=>Goto 1
J>=1=>J<=2=>T+1>A=>Goto 1
J>=3=>J<=4=>U+1>A=>Goto 1
J>=4=>J<=5=>T-1<1=>Goto 1
Isz I
Lbl 1
Isz J
JGoto 0
Prog "CODRAWSEED" ; fx-9x50s: Prog "CODRAWSD"
@@ Program "CODRAWBOARD"
# fx-9x50s: Prog "CODRAWBD"
A->B~C
Lbl 0
47+10(B+C-A->D
33+5(B-C->E
Plot D+5,E-5
Plot D+10,E-5
Line
Plot D+15,E
Line
Plot D+10,E+5
Line
B<>A=>C<>1=>Goto 1
Plot D+5,E+5
Line
C<>1=>Goto 1
Plot D,E
Line
Lbl 1
B<>1=>Goto 2
Plot D,E
Plot D+5,E-5
Line
Lbl 2
Dsz C
Goto 0
A->C
Dsz B
Goto 0
@@ Program "CODRAWSEED"
# fx-9x50s: "CODRAWSD"
V=0=>Goto Z
Plot 47+10(T+U-A,33+5(T-U
Plot X+5,Y+5
Line
Plot X+5,Y
Line
Plot X+5,Y-5
Line
Plot X-5,Y-5
Line
Plot X-5,Y
Line
Plot X-5,Y+5
Line
Abs V<>V=>Goto 2
1->W
Lbl 1
W=1=>Plot X+7,Y+3
W=2=>Plot X+3,Y
W=3=>Plot X,Y-2
W=4=>Plot X-3,Y
W=5=>Plot X-3,Y+2
W=6=>Plot X,Y+4
Plot X+1,Y
Plot X,Y-1
Plot X-1,Y
Isz W
VGoto Z
Goto 1
Goto Z
Lbl 2
1->W
Lbl 3
Plot 47+10(T+U-A,33+5(T-U
W=1=>Plot X+9,Y+3
W=2=>Plot X+11,Y
W=3=>Plot X+9,Y-2
W=4=>Plot X+6,Y-2
W=5=>Plot X+3,Y
W=6=>Plot X+6,Y+3
Abs (2W-7->H
H<>3=>Plot X,Y-1
H=3=>Plot X+1,Y
Isz W
W<=Abs V=>Goto 3
Lbl Z
Plot 0,0
@@ Program "COFILLBOARD"
# fx-9x50s: "COFILLBD"
A->R~S
Lbl 0
R->T
S->U
Prog "COCHOOSESEED" ; fx-9x50s: Prog "COCHOOSE"
Dsz S
Goto 0
A->S
Dsz R
Goto 0
Prog "COCHK4BANG" ; fx-9x50s: Prog "COCHKBNG"
@@ Program "COPLAY"
# Main loop
(-)P->P
0->K
Lbl 0
Plot 65,33
Plot X,Y_
Intg (.1(Y-28->T
Intg (.2(X-67+10A->Q
4Frac (Q/4->U
U<>0=>Goto 1
X-Y<=33+5Q-10(T+A=>Goto 5
X+Y>=100+5Q+10(T-A=>Goto 6
28+10T->Y
57-10A+5Q->X
Goto 4
Lbl 5
57-10A+5Q->X
38+10T->Y
Goto 4
Lbl 6
67-10A+5Q->X
33+10T->Y
Goto 4
Lbl 1
U<>1=>Goto 2
33+10T->Y
62-10A+5Q->X
Goto 4
Lbl 2
U<>2=>Goto 3
X-Y>=39+5Q-10(T+A=>Goto 7
X+Y>=105+5Q+10(T-A=>Goto 8
33+10T->Y
57-10A+5Q->X
Goto 4
Lbl 7
28+10T->Y
67-10A+5Q->X
Goto 4
Lbl 8
38+10T->Y
67-10A+5Q->X
Lbl 3
U<>3=>Goto 4
Y>=33+10T=>T+1->T
28+10T->Y
62-10A+5Q->X
Lbl 4
.5(.1X-4.7+A->D
.1(Y-33->E
D+E->T
D-E->U
T>=1=>T<=A=>U>=1=>U<=A=>Goto 9
" Current player is "
P<>1=>" (-)"_
P=1=>" ."_
Goto 0
Lbl 9
Prog "COADDSEED" ; fx-9x50s: Prog "CO+SEED"
@@ Program "2"
# fx-9x50s: Omit this prog
0Mat Y->Mat Y ; That's a zero, not a letter O
@@ Program "3"
# fx-9x50s: "COBANG"
Prog N ; fx-9x50s: Prog "COPUT"
6->E
T=1=>E-2->E
T=1=>U=A=>Isz E
T=A=>U=1=>Isz E
T=A=>E-2->E
U=1=>E-2->E
U=A=>E-2->E
Abs VGoto 9
'BANG!
1->K
A->R~S
(V/Abs V)(Abs V-E->Mat Y[T,U]
Cls
U-1->U
0->D
Lbl 0
T<1=>Goto 1
T>A=>Goto 1
U<1=>Goto 1
U>A=>Goto 1
Prog M ; fx-9x50s: Prog "COTRY"
Lbl 1
Isz D
D=1=>T+1->T
D>=2=>D<=3=>U+1->U
D>=3=>D<=4=>T-1->T
D=5=>U-1->U
D<=5=>Goto 0
Lbl 9
@@ Program "M"
# fx-9x50s: "COTRY"
Prog N ; fx-9x50s: Prog "COPUT"
K=0=>V/P<0=>Goto 0
P(Abs V+1->Mat Y[T,U]
Prog "COCHOOSESEED" ; fx-9x50s: Prog "COCHOOSE"
Goto 9
Lbl 0
"THIS HEX HAS ALREADY BEEN COLONISED!"
(-)P->P
Dsz L
Lbl 9
@@ Program "N"
# fx-9x50s: "COPUT"
Mat Y[T,U]->V
@@ Program "O"
# fx-9x50s: "COCHKWIN"
'COCHECK4WIN
L<=2=>Goto 9
A->B~C
0->G
Lbl 0
G=0=>Mat Y[B,C]>0=>1->G
G=0=>Mat Y[B,C]<0=>(-)1->G
GMat Y[B,C]<0=>Goto 9
Dsz B
Goto 0
A->B
Dsz C
Goto 0
" ~~~~ GAME OVER ~~~~ "
0->Q
Lbl 3
Isz Q
\sigma(Mat Y[Q,P,1,6->P
P=0=>Goto 3
Abs P/P->P
P=1=>" . WINS!"
P<>1=>" (-) WINS!"
Prog "CODRAWBOARD" ; fx-9x50s: Prog "CODRAWBD"
Prog "COFILLBOARD" ; fx-9x50s: Prog "COFILLBD"
Lbl 8
Plot 0,0_
Goto 8
Lbl 9
@@ Program "P"
# fx-9x50s: "COPLAYER"
'COPLAYCALC
A->T
0->L
Lbl 0
L+\sigma(Abs Mat Y[T,U,1,A->L
Dsz T
Goto 0
# ========================================================================
# CTF compliant. See http://www.york.ac.uk/~tw104/casio/ for details.
#
# More programs and information at:
# http://www.ex-parrot.com/~tom/calcs/calcs/encyc/
#
# This file last compiled: Friday, 30 April, 1999
# ========================================================================