------------------------------------------------------------"The Game of REVERSI" from May, 1990------------------------------------------------------------ What an exciting month it has been here in DOWN TO BASICcountry! There are actually two reasons for my excitement.First is this month's program -- a challenging andentertaining strategy game called REVERSI. I hope that youwill find it as much fun as I have. Secondly, I have a newpiece of hardware for my Grandy. I bought one of Tandy'sDeluxe Joysticks when I saw it on sale at Radio Shack lastmonth. Do I hear snickers out there in Grandy land? Were youexpecting something more dramatic and expensive? Well, ifyou are a regular reader of computer magazines, I guess youhave a right to snicker. Every magazine I pick up containsat least one article by an author breathlessly andreverently describing his latest state-of-the-art computerperipheral acquisition. Those authors ramble on for pagesdescribing the features of their new 300 megabyte harddisks, 100 page-per-minute laser printers, and instantaccess CD ROM disk drives. What they tend to gloss over is the price tag. Many ofthose exotic computer accessories cost about as much as asmall yacht. Where do they get the money for that stuff? Isuspect many of you are into Grandy computing strictly as ahobby; I know I am. As a result, I just cannot justifyspending those big bucks on hard disks or laser printers.Instead, I continue to compute happily with a single floppydisk drive and an ancient old dot matrix printer that Ibought back in 1982 for my TRS-80 Model III. Sticks and Shareware -------------------- I actually spend very little money on hardware or softwarefor my Grandy. The basic hardware I purchased about fouryears ago has been more than adequate, and I am so busywriting programs for this column that I have little time foranything else. But in a moment of weakness last week, Ibroke down and bought that joystick. Overall, I have beenvery pleased with it. Many of the public domain andshareware games in our own Grandy Software Library (GSL)support the joystick; use of the joystick makes thoseexcellent programs even more fun. If you have a joystick or are planning to get one, here area few GSL packages that you should be thinking about. Autility program name JOYMOUSE (GSL Entry #20083) fools yourcomputer into thinking that your joystick is actually amouse. Thus, many programs that accept the mouse pointingdevice can be used with your joystick. Of course, joysticksare most commonly used in game programs. STRIKER (GSL Entry#30014) is an excellent arcade style game that allows you topilot a helicopter on a secret spy mission while avoidingenemy gunfire. STRIKER fully supports the use of ajoystick, and since I got mine, I have gotten much higherscores than I ever did with the keyboard. JUMPJOE (GSLEntry #30006) is another fun game, which is reminiscent ofthe arcade classic Donkey Kong. You must use your joystickto guide Joe up the elevators and ladders, picking up keyswhile avoiding the killer robots. However, the subject of this column is not software orhardware reviews; it is BASIC. Of course, BASIC fullysupports the use of joysticks, too, with the STICK and STRIGcommands. In fact, I have modified this month's REVERSIprogram so that you can optionally use the joystick as apointing and play-making device. Don't worry; if you do nothave a joystick, it will still work just fine using thekeyboard. All About REVERSI ----------------- Have you ever heard of REVERSI? It is not a new game; infact, you can trace its origins back to the ancient orientalgames of GO and PENTE. A modern game company hascopyrighted their version of the game under the nameOTHELLO; they chose that name because during play, there areoften dramatic reversals of events -- just as there are inShakespeare's classic play. The game is played on an eight-by-eight checkerboard. Oneplayer controls a set of yellow (or light colored) markers;the other controls a set of red (or dark colored) markers.The game begins with two of each player's markers in thecenter of the board. On his or her turn, each player placesone marker on the board. He must place his marker so thatit is adjacent to at least one other marker on the board,and it is in line with one of his other markers -- eitherhorizontally, vertically, or diagonally. In addition, thatnew marker must be placed so that it "surrounds" one or moreof his opponent's pieces. For example, suppose that we represent one horizontal lineof the board using X and O in place of the red and yellowmarkers. Pretend that line contains a string of XXOOOmarkers, and it is X's turn. If X placed a marker at theend of the line, then the line would look like this: XXOOOX.Because X has "surrounded" that string of three O's, he hascaptured those O's. Once captured, all those O's are turnedinto X's. Thus, the XXOOOX string becomes XXXXXX. As the game progresses, one strategically placed marker cancapture a dozen or more pieces. Often, a piece will set upcaptures in several directions, as well. The appearance ofthe board can change dramatically in the blink of an eye. Play continues until all 64 squares on the board areoccupied, or until neither player can place a marker thatwill capture at least one of his opponent's pieces. Thewinner is the player with the most pieces on the board atthe end of the game. Play the Game ------------- After typing RUN, the screen will clear and the program willask you to enter your name. Type your first name or yourinitials and press ENTER. It will also ask if you are usinga joystick; press "Y" for yes or "N" for no. If you areusing a joystick, be sure to plug it into the left joystickport. In a few moments, the program will display the game board.Before starting the game, it will briefly review the ruleswith an on-screen demonstration. Following that demo, thegame will begin. Sometimes you will get the first move; atother times, the computer will make its move first. On your turn, you will see one of the 64 squares on thescreen highlighted with a fuzzy, gray border. Use any ofthe four arrow keys or your joystick to move the highlightedborder to the square you want to occupy. When you pressENTER or press the joystick button, one of your markers willbe placed in that square. The program will check to see ifyour marker will capture any of your opponent's pieces. Ifit does, then they will be transformed into yours. If yourpiece does not capture any of your opponent's pieces, thenyour move will be disallowed -- but you can keep tryinguntil you find a valid move. If you simply cannot find aplace to play, then you can pass your turn by typing "P". [Note: Those of you with the new enhanced keyboard -- andthat includes all SL and TL owners -- will have troubleusing the up arrow. There is a bug in either Tandy BASIC orthat keyboard which makes it impossible for BASIC to detectthe up arrow. On that keyboard, you may use the PAGE UP keyas an alternative to the up arrow key.] Once you have completed your turn, the computer will takeits turn. You will hear a few beeps and boops as thecomputer evaluates its options; however, you should not haveto wait more than 20 or 30 seconds at the most. Keep youreye on the scoreboard on the lower right hand side of thescreen; you can tell how many markers you have on the boardand how many your computerized opponent owns. Play willcontinue until all 64 squares are occupied, or both of youpass on consecutive turns. After the winner is announced,you will be given the option to play another game or toquit. Program Details --------------- Lines 1050 and 1060 perform some necessary housekeepingchores -- setting the screen mode, establishing the screencolors, and dimensioning some key variables. Lines 1070 and1080 set up two user defined functions. Those two functionsare used to find the locations on the screen associated witheach of the 64 playing squares. Internally, the programrefers to the 64 squares using an arbitrary numberingsystem. The first horizontal row is numbered 1 through 8.The squares in the second row are numbered 11 through 18;the third row uses number 21 through 28; and so on. Thus,the video screen row and column locations for square number43 are calculated using FNR(43) and FNC(43), respectively. Lines 1140 through 1180 present a welcoming message, acceptyour name and store it in N$, then determine whether or notyou are using a joystick. The variable JS is used as a flagby the program. If JS equals zero, then a joystick ispresent; if JS equal one, then there is no joystick. Lines 1220 through 1250 draw the game board on the screen.Lines 1250 through 1320 briefly review the rules of the gameby placing a few pieces on the board, and showing how theycan be captured. Those demonstration pieces are removedlines 1320 and 1330. Lines 1370 through 1470 set up thescoreboard and place four starting pieces on the board.Notice that line 1440 sets every member of array F(A) equalto -1; that array is used by the program to keep track ofthe status of all 64 squares on the board. If F(A) is equalto -1, then square number A is empty. If it is equal tozero, then one of your markers occupies it. If it is equalto one, then the computer owns that square. The honor ofmaking the first move is selected randomly in line 1470. Taking Turns ------------ Line 1510 calls one of two subroutines -- the one beginningat line 1630 if it is your turn, or the one beginning atline 1780 if it is the computer's turn. Line 1520 checks tosee if all 64 squares are occupied. If they are, then lines1540 through 1570 announce the winner. Lines 1580 and 1590offer the chance to play a new game. Lines 1630 through 1680 allow you to place one of yourmarkers on the board. Lines 1690 through 1740 count thenumber of markers owned by each player, then updates thescoreboard. Lines 1780 through 1910 handle the computer'smoves. The numbers contained in the DATA statements oflines 1830 through 1880 are internal representations for the64 squares, arranged from the most desirable to the leastdesirable position. The computer tries to play in each ofthose squares in order until it finds a valid move. Line1820 throws a little variability into the process, byabandoning the strategic move decision process and selectinga square at random. If no valid move is found, the computerpasses in line 1900. Subroutine 1950 clears the message area in the upper righthand portion of the screen. Subroutine 1970 accepts a yesor no answer. Subroutine 2020 allows you to move thehighlighted border and select a square for your move. Noticethe STICK function used in lines 2050 through 2080. Myjoystick returns a value less than 10 in STICK(0) when it ispushed to the left (or to the west) and a value greater than90 when it is pushed to the right (or to the east).Similarly, STICK(1) returns a value less than 10 when it ispushed up (or to the north), and a value greater than 90when it is pulled down (or to the south). If your joystickreturns slightly different values, then you may have tomodify lines 2050 through 2090. How can you find out what values your joystick returns? Hereis a short one-liner you can use to find out. From the "OK"prompt, enter WHILE INKEY$ <> CHR$(13): PRINT STICK(0),STICK(1): WEND then press ENTER. Push your joystick up thenpull it down to see how the first of the two numbers printedon the screen varies. That will tell you the limits onSTICK(0), and let you decide whether the values of 10 and 90are adequate for determining up or down movement. Do thesame thing moving the joystick to the left and right whilewatching the second of the two numbers, to determine thebest limits for STICK(1). One other problem with the keyboard should be mentioned.Some of the new SL and TL models have a problem detecting anup arrow keypress. (See the sidebar accompanying thisarticle for the whole story.) If that happens to you, addthis line to your program: 2035 IF A$ = "U" OR A$ = "u" THENA$ = CHR$(0) + "H" and press ENTER. If and when your uparrow "dies" and is not recognized by BASIC, press theletter "U" as an alternative to the up arrow. Subroutine 2200 highlights one of the playing field'ssquares when Z is equal to 176. That square is restored toa normal border when it is called with Z equal to 219.Subroutine 2270 colors an individual square for eitherplayer. Subroutine 2370 examines the most recent move, andfinds out which of the opponent's pieces are captured. In Conclusion ------------- REVERSI is an interesting game, and the strategy employed bythe computer makes it a challenging opponent. Do not bediscouraged if you lose your first few games; the computeris good but not unbeatable. Remember, there is a little bitof randomness built into the computer's decision makingprocess. As a result, you can never count on the computermaking the same move it made in your last game. If you already own a joystick, you will be able to put yourfeet up on your desk, place the joystick in your lap, andplay REVERSI to your heart's content. If you do not own ajoystick, I doubt that this one program alone will be enoughto make you go out and buy one. Nevertheless, I will betrying to include joystick support in all my programs in thefuture, whenever it is appropriate. And perhaps I will havesome time in the near future to write an article explaininghow to modify previously published DOWN TO BASIC programsfor joystick use. If you have any questions about this article or aboutprograms which have appeared in past issues, please write tome in care of ONE THOUSAND magazine. If you are havingtrouble getting a program to run, include a listing if youhave a printer. If you have an idea for an article or havea special programming request, write to me about that, too.Be sure to include a self addressed stamped envelope insideyour letter. See you next month!