4 in a row! =========== By: B. Rasmus Anthin Homepage: http://www.algonet.se/~anthin E-mail: anthin@algonet.se S-mail: N.Fiskeb"cksv. 54, 426 58 V.F. GBG Sweden Tel: 031-296779 What: The classic 4-IN-A-ROW game there you drop X:s and O:s in columns. He who first gets four in a row diagonally, vertically or horisontally has won. (The included subprogram checks this for you). If you use the subroutine the both programs must be in MATRIX-mode and you must have the dimensions 8*8 on matrix A. You can easily disconnect the subroutine to make the game faster. Other: Bug is fixed. Size: 1102 + 1480 bytes. "4 IN A ROW" " " Lbl C Mcl 1->X~Y Lbl A 0->Mat A[Y,X] X=8=>Isz Y X=8=>0->X Y=9=>Goto B Isz X Goto A Lbl B Range 1,127,0,1,63,0 Plot 5,5 Plot 5,45 Line Plot 15,5 Plot 15,45 Line Plot 25,5 Plot 25,45 Line Plot 35,5 Plot 35,45 Line Plot 45,5 Plot 45,45 Line Plot 55,5 Plot 55,45 Line Plot 65,5 Plot 65,45 Line Plot 75,5 Plot 75,45 Line Plot 85,5 Plot 85,45 Line Plot 5,5 Plot 85,5 Line Plot 5,3 Plot 85,3 Line Plot 10,48 Plot 10,52 Line Plot 21,48 Plot 19,48 Line Plot 19,50 Line Plot 21,50 Line Plot 21,52 Line Plot 19,52 Line Plot 29,48 Plot 31,48 Line Plot 31,50 Line Plot 29,50 Line Plot 31,50 Line Plot 31,52 Line Plot 29,52 Line Plot 41,48 Plot 41,52 Line Plot 41,49 Plot 39,49 Line Plot 39,52 Line Plot 49,48 Plot 51,48 Line Plot 51,50 Line Plot 49,50 Line Plot 49,52 Line Plot 51,52 Line Plot 59,50 Plot 61,50 Line Plot 61,48 Line Plot 59,48 Line Plot 59,52 Line Plot 61,52 Line Plot 71,48 Plot 71,52 Line Plot 69,52 Line Plot 69,51 Line Plot 79,48 Plot 81,48 Line Plot 81,52 Line Plot 79,52 Line Plot 79,48 Line Plot 80,50 Plot 0,0_ Lbl 0 U=4=>Goto C V=4=>Goto C "PLAYER X" "ENTER COLUMN (1-8)"?->A C[A+1]+5->C[A+1] A=1=>5->D A=2=>15->D A=3=>25->D A=4=>35->D A=5=>45->D A=6=>55->D A=7=>65->D A=8=>75->D C[A+1]/5->B 9-B->B 1->Mat A[B,A] Prog W ; 'Prog W : will speed it up, but you must then check by your self who has won. Plot D+2,C[A+1]+1 Plot D+8,C[A+1]+5 Line Plot D+8,C[A+1]+1 Plot D+2,C[A+1]+5 Line_ Lbl 1 U=4=>Goto C V=4=>Goto C "PLAYER O" "ENTER COLUMN (1-8)"?->A C[A+1]+5->C[A+1] A=1=>5->D A=2=>15->D A=3=>25->D A=4=>35->D A=5=>45->D A=6=>55->D A=7=>65->D A=8=>75->D C[A+1]/5->B 9-B->B 2->Mat A[B,A] Prog W ; The same thing here as before if you want to speed up the game. Plot D+2,C[A+1]+1 Plot D+8,C[A+1]+1 Line Plot D+8,C[A+1]+4 Line Plot D+2,C[A+1]+4 Line Plot D+2,C[A+1]+1 Line_ A>=1=>A<=8=>Goto 0 Lbl 2 Program W --------- 'SUB;---CHECK XO 1->r 1->@ ; @ means theta (alpha Range) Lbl 0 r=1=>@=1=>"PLEASE" Mat A[r,@]=1=>Isz U Mat A[r,@]=2=>Isz V Mat A[r,@]<>1=>0->U ; <> means: not equal (PRGM F2 F2) Mat A[r,@]<>2=>0->V Mat A[r,@+1]=1=>Isz U Mat A[r,@+1]=2=>Isz V Mat A[r,@+1]<>1=>0->U Mat A[r,@+1]<>2=>0->V Mat A[r,@+2]=1=>Isz U Mat A[r,@+2]=2=>Isz V Mat A[r,@+2]<>1=>0->U Mat A[r,@+2]<>2=>0->V Mat A[r,@+3]=1=>Isz U Mat A[r,@+3]=2=>Isz V Mat A[r,@+3]<>1=>0->U Mat A[r,@+3]<>2=>0->V U=4=>Goto W V=4=>Goto W 0->U~V @=5=>Goto 1 Isz @ Goto 0 Lbl 1 Isz r r=9=>Goto 2 1->@ Goto 0 Lbl 2 1->r 1->@ Lbl 4 r=1=>@=1=>"WAIT" Mat A[r,@]=1=>Isz U Mat A[r,@]=2=>Isz V Mat A[r,@]<>1=>0->U Mat A[r,@]<>2=>0->V Mat A[r+1,@]=1=>Isz U Mat A[r+1,@]=2=>Isz V Mat A[r+1,@]<>1=>0->U Mat A[r+1,@]<>2=>0->V Mat A[r+2,@]=1=>Isz U Mat A[r+2,@]=2=>Isz V Mat A[r+2,@]<>1=>0->U Mat A[r+2,@]<>2=>0->V Mat A[r+3,@]=1=>Isz U Mat A[r+3,@]=2=>Isz V Mat A[r+3,@]<>1=>0->U Mat A[r+3,@]<>2=>0->V U=4=>Goto W V=4=>Goto W 0->U~V r=5=>Goto 5 Isz r Goto 4 Lbl 5 Isz @ @=9=>Goto 6 1->r Goto 4 Lbl 6 1->r 1->@ Lbl 7 r=1=>@=1=>"A" Mat A[r,@+3]=1=>Isz U Mat A[r,@+3]=2=>Isz V Mat A[r,@+3]<>1=>0->U Mat A[r,@+3]<>2=>0->V Mat A[r+1,@+2]=1=>Isz U Mat A[r+1,@+2]=2=>Isz V Mat A[r+1,@+2]<>1=>0->U Mat A[r+1,@+2]<>2=>0->V Mat A[r+2,@+1]=1=>Isz U Mat A[r+2,@+1]=2=>Isz V Mat A[r+2,@+1]<>1=>0->U Mat A[r+2,@+1]<>2=>0->V Mat A[r+3,@]=1=>Isz U Mat A[r+3,@]=2=>Isz V Mat A[r+3,@]<>1=>0->U Mat A[r+3,@]<>2=>0->V U=4=>Goto W V=4=>Goto W 0->U~V @=5=>Goto 8 Isz @ Goto 7 Lbl 8 Isr r r=5=>Goto 9 ; Bug is fixed here. 1->@ Goto 7 Lbl 9 1->r 1->@ Lbl A r=1=>@=1=>"MOMENT !!!" r=1=>@=1=>" " Mat A[r,@]=1=>Isz U Mat A[r,@]=2=>Isz V Mat A[r,@]<>1=>0->U Mat A[r,@]<>2=>0->V Mat A[r+1,@+1]=1=>Isz U Mat A[r+1,@+1]=2=>Isz V Mat A[r+1,@+1]<>1=>0->U Mat A[r+1,@+1]<>2=>0->V Mat A[r+2,@+2]=1=>Isz U Mat A[r+2,@+2]=2=>Isz V Mat A[r+2,@+2]<>1=>0->U Mat A[r+2,@+2]<>2=>0->V Mat A[r+3,@+3]=1=>Isz U Mat A[r+3,@+3]=2=>Isz V Mat A[r+3,@+3]<>1=>0->U Mat A[r+3,@+3]<>2=>0->V U=4=>Goto W V=4=>Goto W 0->U~V @=5=>Goto B Isz @ Goto A Lbl B Isz r r=5=>Goto 3 ; And here is a bug fixed too. 1->@ Goto A Lbl W U=4=>"X WINS!!!" V=4=>"O WINS!!!" "---------"_ Lbl 3 ------------------------------------- Puh.. That's all folks. Hope you'll be satisfied with the result. WARNING --- Subroutine W is very slow, so you must be patient! --- VARNING