Title : Calculator Othello Author : James Blackham (james1b@hotmail.com) Date : 01/07/97 Copyright : This program and any associated code and text is the exclusive copyright of the author and owner, James Blackham. You have permission to enter this text into your calculator, run the code on your calculator so long as the author is given full credit in the displayed text. You should email the author if possible to advise that you have used this program, to allow a user base to be built and to give you notice of other programs. You also have permission to distribute the code by any means and to any person, so long as this copyright notice is included and the whole of this file remains in its original form. Release : 1.10 [bug reports/suggestions/questions welcome] Notes : 1st Proper release. You MUST email me if you run this program Notes : This program is very graphical and can be battery heavy. Machine : Casio fx-9700 Memory : Matrix 840 Programs 4000 Total 4840 Requirements : Matrix O => dim as 8x8 Matrix S => dim at 10x2 Program O => Main program, start in matrix mode Program P => Checking program, start in matrix mode Starting : Run program O Symbols : >= is greater than or equal to <= is less than or equal to => is 'then' _ is the small triangle <> is not equal to -> is 'gets written to' r is the small 'r' above the Graph key @ is the theta above the Range key / is divided by Features : Save game, play against calculator, completely graphic mid game scores and stats, pass turn. Instructions : This is the game of Othello (Reversi). If you dont know how to play FIND SOME RULES AND READ THEM NOW! because I'm not going to bother typing them. There is an option to play the calculator (called Shallow Blue) or play with a friend (2 player) 2 Player Mode : Black starts and moves the cursor on the screen to where he would like to place a piece the calculator checks the move is legal and updates the board. White then make a move, and so on. When the board is full, the player with the most counters wins the game At any stage, if a player has no counters, of their colour, they loose. If a player cannot make a move, they have the option to pass that turn Shallow Blue : The calculator is a goodish player. The playing system is based on a series of priority given to squares depending on the position and number of pieces turned. Playing skills can be adjusted by altering these priorities (variable P) - experianced users only! The player can choose which colour starts, though the calculator is always white. Otherwise play is as for two players. Mid Game Menu : Putting the cursor in the box marked M by the side of the board activates the mid game menu. Here you can see the current scores and statistics for the game and find out where the last move went, pause a game for continuing later, end a game or pass your turn. You may only pass where you cannot make a move, so the game checks to see if you can move. If you can, the game will point this out to you. Resuming a game is an option on the main menu when you restart program O after pausing a game. Advanced users information : Saving time and space : Putting some of the routines in separate program areas will speed them up a little and make the program more manageable. Routines for drawing the board and pieces [labels 4 to 9] and the Shallow Blue routine [labels D to *] can both be placed elsewhere and called from the program The whole Shallow Blue routine can be safely removed to save space, but you will not be able to Pass turns or play against the calculator. To enable passing of turns without the SB code, replace the SB code with 9->r and trust your friends not to cheat when they select pass! If you are very desperate for space, remove all the text in the menus and remember them yourself! To move the draw board and pieces routine, change the lines saying Goto 4 to say Prog D. Type in the code from Lbl 4 to Lbl D inclusive from program O into program D. Pausing : When the game is paused, a check code containing the options is stored in matrix O in 8,8. Any disruption to matrix O will destroy the saved game, but otherwise you can use the calculator as normal. If you take longer than 6 minutes to decide a move (!) the thing will turn itself off and you will loose your game. It is then necessary to enter the check code yourself. If it is blacks turn to move then c=100 If it is whites turn then c=200 Add on to c the value currently in matrix O square 8,8 If the computer is playing then multiply c by -1 The code c is then the code you place in matrix O 8x8, then run the program as normal. This is only for if you forget to pause the game properly! Moves back : Code allowing moves to be taken back can be easily added 1. Put the option in the midgame menu 2. Put in some code to copy the matrix after a move (Mat O->Mat P) 3. Put in some code to restore the matrix as required (Mat P->Mat O) ---------END OF INSTRUCTIONAL TEXT----------- Program O : 'OTHELLO Abs (Mat O[8,8])>=100=>1->Z Z=1=>Goto A Lbl 0 0Mat O->Mat O:O->A~Z:2->W:2->Z 1->Mat O[4,4]:1->Mat O[5,5]:2->Mat O[4,5]:2->Mat O[5,4] Lbl A " ":" " " OTHELLO" " " " (C) BLACKHAM '97" " " " "_ " GAMES SETUP MENU" " " "1. PLAY SHALLOW BLUE" "2. PLAY TWO PLAYERS" Z=1=>"3. RESUME OLD GAME" ?->H H=3=>Z=1=>Goto U H=2=>Goto 1 H<>1=>Goto A " " "YOU START (1=YES)"?->T T<>1=>2->T " " Lbl 1 W+Z=4=>Goto 4 W+Z=64=>Goto Y W=0=>Goto Y Z=0=>Goto Y T=1=>Goto 4 T=2=>H<>1=>Goto 4 Lbl B " " 0->r H=1=>T=2=>"SHALLOW BLUE THINKS " H=1=>T=2=>Goto D Lbl C r=9=>Goto X T=1=>"BLACK'S TURN"_ H<>1=>T=2=>"WHITE'S TURN"_ T=1=>Goto 3 H<>1=>T=2=>Goto 3 Lbl 2 T->Mat O[A,B] A->r B->@ 0->K Prog P T+1->T T=3=>1->T Goto 1 Lbl 3 Plot 44,35_ X>=90=>X<=98=>Y>=30=>Y<=40=>Goto T (X-4)/8->A:(Y-5)/6->B Int A=A=>Goto 3:Int B=B=>Goto 3 X>=76=>Goto 3 Y>=59=>Goto 3 X<=12=>Goto 3 Y<=11=>Goto 3 Int A->A:Int B->B Mat O[A,B]<>0=>Goto 3 Goto 2 Lbl 4 0->A~B:0->W~Z Range 1,127,0,1,63,0 Lbl 5 Isz B B=10=>Goto 6 Plot 8B+4,11 Plot 8B+4,59 Line Plot 12,6B+5 Plot 76,6B+5 Line Goto 5 Lbl 6 Plot 9,8:Plot 79,8 Line Plot 79,62:Line Plot 9,62:Line Plot 9,8:Line Plot 12,11:Line Plot 78,9:Plot 77,10 Plot 77,60 Plot 78,61 Plot 11,60 Plot 10,61 Plot 90,30 Plot 90,40:Line Plot 98,40:Line Plot 98,30:Line Plot 90,30:Line Plot 92,32 Plot 92,38:Line Plot 94,36:Line Plot 96,38:Line Plot 96,32:Line Plot 94,35 Lbl 7 0->B Isz A A=9=>Goto B Lbl 8 Isz B B=9=>Goto 7 Mat O[A,B]->C C<>0=>Goto 9 Goto 8 Lbl 9 C=1=>Isz Z C=2=>Isz W Plot 8A+7,6B+9 Plot 8A+9,6B+9:Line Plot 8A+7,6B+7 Plot 8A+9,6B+7:Line Plot 8A+6,6B+8 Plot 8A+10,6B+8 C=1=>Line Goto 8 Lbl D 1->K:0->A:1000->R:0->U Lbl E 0->B A+1->A A=9=>Goto I Lbl F B+1->B B=9=>Goto E Mat O[A,B]<>0=>Goto F Prog P V=0=>Goto F 0->C W+Z<36=>10V->P W+Z>=36=>70-10V->P A=1=>B=1=>1->C A=1=>B=8=>1->C A=8=>B=1=>1->C A=8=>B=8=>1->C C=1=>P-500->P A<3=>B<3=>Mat O[1,1]<>T=>1->C A<3=>B>6=>Mat O[1,8]<>T=>1->C A>6=>B<3=>Mat O[8,1]<>T=>1->C A>6=>B>6=>Mat O[8,8]<>T=>1->C C=1=>Goto H A=2=>P+11->P A=7=>P+11->P B=2=>P+11->P B=7=>P+11->P 0->C B>2=>B<7=>A=1=>Mat O[A,B+1]<>Mat O[A,B-1]=>1->C B>2=>B<7=>A=8=>Mat O[A,B+1]<>Mat O[A,B-1]=>1->C A>2=>A<7=>B=1=>Mat O[A+1,B]<>Mat O[A-1,B]=>1->C A>2=>A<7=>B=8=>Mat O[A+1,B]<>Mat O[A-1,B]=>1->C C=1=>P+21->P Lbl G P>R=>Goto F P=R=>U+1->U U=11=>Goto I P1->U PP->R A->Mat S[U,1] B->Mat S[U,2] Goto F Lbl H P+200->P A=1=>B=2=>Mat O[1,3]<>T=>1->C A=2=>B=2=>Mat O[3,3]<>T=>1->C A=3=>B=1=>Mat O[3,1]<>T=>1->C A=2=>B=8=>Mat O[3,8]<>T=>1->C A=2=>B=7=>Mat O[3,6]<>T=>1->C A=1=>B=7=>Mat O[1,6]<>T=>1->C A=7=>B=8=>Mat O[6,8]<>T=>1->C A=7=>B=7=>Mat O[6,6]<>T=>1->C A=8=>B=7=>Mat O[8,6]<>T=>1->C A=7=>B=1=>Mat O[6,1]<>T=>1->C A=7=>B=2=>Mat O[6,3]<>T=>1->C A=8=>B=2=>Mat O[8,3]<>T=>1->C C=1=>P+200->P Goto G Lbl I U=0=>9->r U<>11=>Int (Ran#xU)+1->U U=11=>Int (Ran#x10)+1->U Mat S[U,1]->A Mat S[U,2]->B I=1=>99->I I=99=>r=9=>Goto X I=99=>Goto W Goto C Lbl T " " " MID GAME MENU" " " "1. SCORES 'N' STARTS" "2. PASS TURN" "3. PAUSE GAME" "4. END GAME" " " ?->Q " " Q=2=>Goto W Q=3=>Goto V Q=4=>Goto Y Q<>1=>Goto 3 " SCORES 'N' STATS" " " "BLACKS:":Z_ "WHITES:":W_ " " T=1=>"BLACK" T=2=>"WHITE" "TO MOVE" " " "TURNS SO FAR" W+Z-4_ " " "LAST MOVE:" r_ "BY" @_ " " "TURNED" V_ " " Goto 3 Lbl U Mat O[8,8]->Q Abs Q<>Q=>1->H Abs Q->Q Int (Q/100)->T Q-100T->Mat O[8,8] Goto 1 Lbl V " " "GAME PAUSED" " " 1->Q:H=1=>-1->Q Q(100T+Mat O[8,8])->Mat O[8,8] Goto Z Lbl W I<>99=>1->I I<>99=>Prog R 0->I "PASS NOT ALLOWED!" " " "DID YOU SPOT" A_ "BY" B_ " " Goto 3 Lbl X " " "TURN PASSED" " " 0->r T+1->T T=3=>1->T Goto 1 Lbl Y " " " GAME OVER" " " "BLACKS:":Z_ "WHITES:":W_ " " " ~~~~~~~~~~~~~~~~~~~" W>Z=>" WHITE WINS" W" BLACK WINS" W=Z=>" DRAW!" H=1=>W>Z=>" SILICON BEATS BRAIN" " ~~~~~~~~~~~~~~~~~~~" " " "REMATCH (1=YES)"?->Q Q=1=>Goto 0 Lbl Z " " -----END OF PROGRAM O----- Program P 'CHECK TURN 0->V:B->P:0->F T+1->L L=3=>1->L Lbl 1 P-1->P P=0=>Goto 3 Mat O[A,P]=T=>F=0=>Goto 3 Mat O[A,P]=0=>Goto 3 Mat O[A,P]=T=>Goto 2 Mat O[A,P]=L=>1->F Goto 1 Lbl 2 P+1->P P=B=>Goto 3 K=0=>T->Mat O[A,P] V+1->V Goto 2 Lbl 3 B->P:0->F Lbl 4 P+1->P P=9=>Goto 6 Mat O[A,P]=T=>F=0=>Goto 6 Mat O[A,P]=0=>Goto 6 Mat O[A,P]=T=>Goto 5 Mat O[A,P]=L=>1->F Goto 4 Lbl 5 P-1->P P=B=>Goto 6 K=0=>T->Mat O[A,P] V+1->V Goto 5 Lbl 6 A->P:0->F Lbl 7 P-1->P P=0=>Goto 9 Mat O[P,B]=T=>F=0=>Goto 9 Mat O[P,B]=0=>Goto 9 Mat O[P,B]=T=>Goto 8 Mat O[P,B]=L=>1->F Goto 7 Lbl 8 P+1->P P=A=>Goto 9 K=0=>T->Mat O[P,B] V+1->V Goto 8 Lbl 9 A->P:0->F Lbl A P+1->P P=9=>Goto C Mat O[P,B]=T=>F=0=>Goto C Mat O[P,B]=0=>Goto C Mat O[P,B]=T=>Goto B Mat O[P,B]=L=>1->F Goto A Lbl B P-1->P P=A=>Goto C K=0=>T->Mat O[P,B] V+1->V Goto B Lbl C 0->F:A->P:B->Q Lbl D P+1->P Q+1->Q P=9=>Goto F Q=9=>Goto F Mat O[P,Q]=T=>F=0=>Goto F Mat O[P,Q]=0=>Goto F Mat O[P,Q]=T=>Goto E Mat O[P,Q]=L=>1->F Goto D Lbl E P-1->P Q-1->Q P=A=>Goto F K=0=>T->Mat O[P,Q] V+1->V Goto E Lbl F 0->F:A->P:B->Q Lbl G P-1->P Q-1->Q P=0=>Goto I Q=0=>Goto I Mat O[P,Q]=T=>F=0=>Goto I Mat O[P,Q]=0=>Goto I Mat O[P,Q]=T=>Goto H Mat O[P,Q]=L=>1->F Goto G Lbl H P+1->P Q+1->Q P=A=>Goto I K=0=>T->Mat O[P,Q] V+1->V Goto H Lbl I 0->F:A->P:B->Q Lbl J P-1->P Q+1->Q P=0=>Goto L Q=9=>Goto L Mat O[P,Q]=T=>F=0=>Goto L Mat O[P,Q]=0=>Goto L Mat O[P,Q]=T=>Goto K Mat O[P,Q]=L=>1->F Goto J Lbl K P+1->P Q-1->Q P=A=>Goto L K=0=>T->Mat O[P,Q] V+1->V Goto K Lbl L 0->F:A->P:B->Q Lbl D P+1->P Q-1->Q P=9=>Goto O Q=0=>Goto O Mat O[P,Q]=T=>F=0=>Goto O Mat O[P,Q]=0=>Goto O Mat O[P,Q]=T=>Goto N Mat O[P,Q]=L=>1->F Goto M Lbl N P-1->P Q+1->Q P=A=>Goto O K=0=>T->Mat O[P,Q] V+1->V Goto N Lbl O --------END OF PROGRAM!!------