P*,"9,.*_s_,_o^tl,plCo_ ing LAUNCHINGPAD -G" i.sfor Graphics This programletsyou createanalphabetpicturebookfor childr€n.Eachtime llley-t}?ein a lener,theygetbactanappropriare picture appleforA.bear rot tt , tor exunpte. by Maft ZnnQnan 38 T i r e do fT y p i n cg O T 0 ?T . yT - B u g... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . s 4 The authorreviewsRadioShack'sT-BUGcass€tte,which allowsassembly languageprograinmingon rheTt.S,SO.by Wiuian L. Cotshe. DIGGING IN Page38 PlannedPmgrarDming: Th€ThoughtsBehindtheStructure- . . . . , . . . . . . ,2g Careful planningbefor€you startwriting codemakesyour overallprograrnrningeffort muchsimpler.Justfollow rhestepsoutlinedin rhisanicle ro producelogical. snucturedprcErans.bt Rob?i T. Nichohon A GenerG a la m P e Lying P r o g r a n .... . . . . . . . . . . . . . . , . . . . . . . , . . . . . . . . Z 0 Incorpomtingthis look-aheada.lgorithminio your gameslersyou play agarnstthe compurer.The aurhorshowsyou how wirh Fograrnsfor Tic_ Tac-Toeand Kalah. ,y }l erbertL. Derchcm Page43 DoublhgSpacc onShgle.Sided Drsks ......,,,...t6 Thissimple procedu€ yourmemory canrlouble storage, foraninvestrnenr of pennies.b! Rodn y L. Wri9ht. IN THE MONEY Rate.S€ttin8 andBi[ing for Srtal Utilides. ... . . . ...... . . . ...... . . ... .43 Manybusiness€s, includinS smallutilitjes. musrvaryrares according rouse. I nrsprograrh package asisrsinesrabtishing mt€s,marnrains records and preparEs bills. ,) Sr?p/4nP. Sntrrr H o r yt o F a i lM t h a B u s i t r €Ss ys s t e m .. . ... . ... . . .,. .... . . .,..... . . ... .6? Herear€someof rherhingsrharcangowrongwithyourbusiness compuFr ._ and how fo avoid or cofiecr them. by Rodtuy ZaA ON THE LIGHTER SIDE 60 Trappedin a roon wid killerrobors,youmunsurnmon altyourcoumge and skrll tosuryiye. by William lappen DEPARTMENTS FUTURECOMPUTING FEEDBACK............7 'Programs" arc Comint . . . . . . . . . . . . . . . . , . . . - - - . . . . . . . . . . -22 R A N D O M A C C E S S . . , . 1Sponsored 1 Large COMPI,IIER CIIESS . . .77 companiescant ignorerhegrowingpopul&ity of p€rsonatcompuers COMPUTERBRIDGE , .87 andthe potentialadvertisingmediumthey represent.Soonyou rnaytyp€ B O O K S H E L F . . . . . . . . . . 8 9 RUN and s€ea familiar line on your CRT: ..This programis broughtio you WIIAT'S COMINGIJP . by . . ." blwillianR. Parks ADINDEX...........110 publishins @copyright t9?9,Benwill Corp., a Mo€an_cddpian Co. 4 PersonalComputing JUNE ierc UJ E, $ lIJ. o COMPLETE BUSINESS ACCOUNTINC P A C K A GE S ACCOUNTS PAYABLE ACCOUT{TSRECEIVABLE G E N E R A IL E D G E B INVENTORYCONTROL OFDER ENTFY $inc 6qary.Q.o4"'. Box 2ot7 9"y,JVIL,55,* ""i""".i,,J."{,+tf i:"J""" See our other ad in this Magazine ctBclE a5 70 Personal Codputing JUNE 1src A General GamePlaving Program BY HERBERTL. DERSHEM Progranmershaveusedthe look-ahead strategy to develop competitive game playhg programsfor gameslike check_ ers ard chess.A generalform of this look-aheada.lgodthmcan be d€scrib€d in terms of a recursiveprocedurcimplemented in BASIC for sDecific games. If your BASIC proc€ssoraccopts recusive submutinecalls, then you can use this a.lgorirhmro play any suitable game by prograrruningthrEe additional sutrourinesrhardescriberhe game. (For mor€ informationon recursrve progmnrmrng, see ..Recursive Prograruning in BASIC" , ADril pC. ) Considera gamewirh rwo ptayers called compuEr" and "opponenC, At any given point in the game, two descripton describethe situation: the gamesuos (cs), often thestitus of the game boald; and the player to move next (PM), either,,computer" or ''opponent". EachcS, PM pair results eilher in a complel€dgamewith a winner, or in a dmw, or in a set of legal movesfor PM. Eachlegalmovemaps theGS,PMpair.Lel's consider thecase where the players alt€mate moves, making the new PM geneded by a move always different from rhe previousPM. Now we're r€adyto recursivelystate lhe look-alrcadalgorithm which, giv€n a CS,PM pair, €valuat€sall the legd moves available to player PM and detelminesthe optimal one. Algorithm Eyaluate b rtnd the besl nove BM fot playet PM from ea,,u statusGS v'ith evaluaabnof E. Evaluate(GS,PM,E,BM) 2 Grnerare tvIvrMV: MV". rhes€r ol all legalmovesFom (CS,PM),and GSr,CSz....,CS", rhe corresponding sel ot game status€safter the legal movesar€appliedtocS. L If PM = compurer,calt Evaluare (CS, opponent,E, BM,) for i = 1,2,..., n; for q, the laree$ of E,,8.....Ei, setE = q. g^,t = f,t\; retum. 4. If PM : opponent,calt Evajuare (CS,, computer,E,, BM) for i = t, 2,...,n;forq, thesmallest ofE,.B.... Ei, setE = E(, BM : MVr; retum. is always _ Evaluationofa gamesratus irom thecomputer's poinrof view.The larger the evaluation,the betterlhe slatus is for the computer.The.efore,the pnnciple behind rhis algorirlm is that the computeralwayschodes ftom the legal moyes-that move rcsulring in a gamesratuswilh laqest evaluarion.On the other hand, the opponentalways cbooses the move with the smattest evaluation, sincerhat move is rh€ leasr desirablefor the computer. How does the computer determin€ whethera move is dfectly evaluarable? If a garnestatusis lerminal, thereareno further moves.Or som€timesthe computer stops wh€n a certain numberof levelsof moveshavebeenexamined. For example,a 3-tevel look-aheadwilt examineall of the computer'slegal responses.As you cans€e,the numb€rof moves tiat must be exarninedglows rapidly as the level of th€ searcbinfinal level (level 3 in the exarnple aoove), you must implement some heuristic procedureto evaluatethe cS. l. If(GS,PM) is dirccdy evalualable, PM pair.The abiliryof thisprocedure, evaluateit andplacer€sullin E; rerurD_ the static evaluarionfuncrion.to ac 9.A.ine. cumtely evaluate the game's status Sreatly affects how well the computer will compete-There's a trade-off t€, tween the depth of look-aheadand the validiry of rhe staiic evaluationturc tior. If the staticevaluatioofunction is perfect, the computercanus€it to eval, uate all its altemativesdirectly andnol look alEad at all. On the oth€rhand, if the computer can look ahe3dclear to the end of the garne,examiningall of the altematiYes,it has no need for a static evaluationfunction sincetheperfbct evaluationtunction is the garneresult: win, loseor dmw. In practicewe find ourselves somewhere between For the geneml BASIC version for this algorithm,seeListing L Two additions to the algorithmhaveb€ennade to speed up the search. Both halt the PKrcesswhen it's obviousno more searching is needed. Supposethe s€archis at a level generating the computer'sresporis€s.If, at thepreceding level,theopponenfsbest move evaluatesto 4 andso far the com, puter'sb€stmoveat thislevelevaluates to 5, why continue the searchat this level?The opponentwill neverchoose the current move under considemtion b€causeit will evaluateto no smaller than5 which is alreadyI womethanthe b€st move the opponenthasexamined so far. This conditionis testedin line 2100of theprogramin Listingl. [n tr€e searching this process, called alphabeta pruning, usually saves search time, Additional savings can resulr from statement2130 where, as soon as a player hasfound a surewinner for himself, he stopssearching. Now lefs look at two implementations of the algorithm in Listing I . The first, found in Listing 2, is the familiar game of tic-tac-toe. The implementa tion requireslhe addition of thrce submutines to the general garne status evaluator at 2900. These a.re1000, a move genemtor; 3000, a static move evaluationfunction; andz{no, a gameover tester,But the choicesshownhere are exampl€s:try designingyour own improved venions of these subroutines. The padicular impleme ation here uses a maximum searchdepth of l0 levels. For tic-iac-toe, this l€vel implies all searcheswill be lerminatedby the end of the game since the long€st possible game is 9 moves. The static evaluation function i€tums 100 if the positionis awin for thecomputer,-Io0 if it's a win for the opponent,and 0 if Subrouline2000 has beenmodified slightly from that shownin Listing I to acconrnodalethe pres€nceof only one subscripted variable in Radio Shack Level I BASIC, the syscm on which this programwas implemented. The ancientgame of Kalah, our second game, is played on a board wirh six small pits on either side and larye pits at eachend. The gamebeginswilh 3 marken in each of the snail pitr as shownin Figurel. Kalah {Poooo[ Computer's Pits oooooo 0oooooo_. 0 PlayeisPits T Player's I(aIah FiPue 1 Initiat positionof Kalahboard !!, ^r'o I uL!€ lo{rid rhd !! The playen aiternatemovesaccording to thefollowingrulesl I. A playerrnovesby choosinga pit on his $ideof the boardanddistributing the mark€n contained in that pit itrro other pits counterclockwiseamundth€ board b€ginning with the counierclockwise neighborof the emptiedpit. He places one ma.rkerin each pit and Kalah in tum until all marken removed are disrributed. Eraryle: If l\\e owonent beganplay fiom the initial board shown aboveby emptyingthe fifth pit from the left on his side,after his move the boardwould look like Figure2. inc S, oooooo@o voooo@@v 6ry,=N.9). .4o.. Box 2ot'l J"yp. -N9).5s,oz FiAure 2 Exampleofa move c t F c L E8 6 P€rsonalCooputing 7l 2. If the last marke. distributed bv a 3. If rhe last markerdistdbutedon a computer's four marken on the oDno_ player landsin tharptayer'aKalah, ;he player'smovelandsin anemprypir on site (Figure4). side must pit empry another on his Pmy€r rhe ptayers side of rhe board,and if The winner hasthe most markersin side. This move is called a continua_ some.markers are in his oppooenrs pit his.Kalah at tion. The €ontinuadonmighl have anorrecuyopposjlethis pit, rhenlhe tast a prayernasthe endof the$me. Wten no moremekelsin hisDits olher conrinuation,and so on. Erzn_ marker distributed and all the marken and it s his tum to move, the same ple. If the computer's responseto the rn lhe oppositepir are placedin rhe ends.At thatpointrheopponenr aDove_move wasto empiyfie thirdpor Kalahof the player matinafte move. all the mdkes in hrJ pirs Diaces rrom theleft. rl wouldreceiveaconrin_ This move is inio hr calteda caDite. Enn Kalah.andrhewrnn€risd;rerrnrned ualion. This move and ir5 continuation plerlf the opponenr no\rr emDtiesrhe Listing 3 showsthe applicationofrhe areillustntedin Figure3_ lands in the empty pir andcap-tures the game playing algorithm to rhis same. The conlinuationcomplicalesm;tters by requiringtwo locationsto storea move a5 well a5 a specialcoding scnemetor contlnuation moves GuesswhobuiHs thisqreats19 o@@@oo@o "oooo@@v LogicProbe. !lt It/A, r rlJlt. r Yvro u 5Ei'sv-to-oul o Log C ffii""l;:;i::,H;,".:";::,j1 lha'ksrooLrveryoescnprvesteO-bv-steo .narua'-youhavea,u I pe forn ancbooic probe. Wil\ [. rhetogc ,eveli|^a digtralcircJI rransratestnto rghttromtheH orLoLED: putses asnaffowas300nanoseconds are slretcled1tobrtrksofrhepr..rtse _ED, trggereq lror e lr'teread,ngedge.you'I oeabtetoarobe oeeperntologicw ththeLPK-1. oneofthe sma(ertoolsfromCSC. Complete, easy-to-follow instructions helpmakethisa one-night proj€ct. Continuation o@ooo@@o '-oooo@@v FiEureJ Exarnple ofa move and continuation .\@@o@@@,1 Urr".."9 CONTNENIAI SPECIAITIES CORPORATbN I'II I:r.qf.E Figure 4 Exampleofa capturc I-aI 70F!hi ri( N€"r&fn cr06509pm)6 or|tF 0Frcs sinfimDYo(rt4t 3! Calltolljreefordetails 1-800-243-6077 c l R c L E8 7 72 Perso@l Computilg JINE€D Now that you've se€n6ese exarnples, you can implemenrthis algorithm tor other games. You. might wanr lo rmprove the computer's p€rformance on tbesegamesby pmviding bettersrar ic evaluation tunctions or increasina the maximum depth of search. you must proceed with caurion, however. Look,ahead algorithms c:m consume lots of computet time. So be EeparEd to wait fm thecomputer,smoves._ tr Listing 1- Game-Playin€Algorithm ;llliii';:iiir'iii:iii$,;,: jijiiiiii;ifii:ifii"i$*ft ::,r' i:;:i:: :;:It:;t;t:;"";.:{,;:"::;:;'*-"-*,-*",,,*. ,;,:;;; ":i"i,:iii! .:i3il: i;i;;;l " 1:"',i';'.',i':"""';:: :l:p;4ii;irl:"'t;::trs:l;e;li:s i;"x;.-ir'#;r;;::'el";;ii;i: ll:l ::l ; ;i,i;i';i,ii;:;',;;":" ::l; n:' ;il;;,til:;.lllil.;ir-rq;'i1;;iTp;"I"il:Jr3l.l'";id" , iffiilr r:iiii:fii;"{i;iil;:;i':;trc"';r'i.":'^;'.;;;;' 1i,,.;;;i$i";""i,t";il:r"Lt; t;;l ;;l i; li:";t:lt;i;',,";,;;, ;i;3;:; ":l t:r591;:; lt9!.'3;i,,lti."ti: $$,:"u.-d, s:a!sct :i":lii:i'iilliiiJh'iriliii,"' :jii ii! !,ii !ii,iit!!,,ir:,i;1 :,;;i;l eli;.1:",;;';;.1": il";;i il; ;ij;:il;:"'1:''llli3; :;;el;a :i'iI+i"i;;l;;';:Y lliiiii'ihi]i!'iii;il;:iri".";i:ljc"]?ir3,i13i,rr;Ll;":";irrd 1!r".;:jiiil;:iiFtiiirl:;iiiii"i;jT?,,s. riiliil"ii ri3"1 rns-80 soFTwARE cassErTES.. []i :irtglfl*, ife ii#",.' TRS-80 rEvEL l BASTC $42 .. . : :i:;t t:: : ANADEXPRINTER ModelDP.8000gggg VESBATIIlI 5%''DISKETTES $27 boxof 10 8" 0tsKs $40borol 10 i::i TRS-80 FORTRAN $340 PLUS GET 1 FREEI MEMORY ADD"OI,I 16K $65 iTfl+ii{Siifrr I,.illii".l:ii.}tii,1i !';fi' ;3^:;i,t:Ti',i'::;: ;:;[ t,ill:f,,i flj,ffi FREECATAI.OG! TRS-80ELECTRICPENCIL SHUGART SA.IIIO MINIFI.OPPY DRIVE $2eb c t R C L E8 8 PersonalComputins Listing2 - Tic-Tac-Toe , 0 5 0r ( e r e ) - r r r ( a n 0 ) . r : r ( 0 r r r ) = - z r r 0 r ( a r r 1 t = Er: ( 0 + r 0 t =(r0 1 e 1 212 Foi rR! o?rurtri. r r l 0 r s l- r ( 0 . 3 r 3 1 r 0 1 0r r r ( 0 r n > e , o o or . ! r 1 : 0 - r . ( r - r )1 r : r . - , , 0 r 0 r ! ( ! < ' r l . ( 0 ' 0 ) 0 0 1 o? 0 t 0 HowAboutPOSTING 1,000RECORDS to the in 7 MINUTES? G E N E R AL E D G E R I t ' s p o s s i b l ew i i h N 6 w W a r e ' sI N T E R ACTIVE system that has been SERVICE BUnEAU TESTED and CPA APPROVED! IndlvldualPackag$ Are: The packag€s have been designed lor Apple ll single or dual disk systems wilh 32K of user memory w i t h o r w i t h o u t A p p l e s o f t 2F i r m w a r e . SlandrrdNo ChargeFealure!: .HEhs@dJouliabL'dgarfu|E AAuhal.Gsedbdger OrderToday:EachPackage$120,00' 'oGkwih sourc.co& addt10oo lshippedonrywlh packaget chippedody wih packaqst 4525 Psrk Driuc Omah6,N.bre.ka 68127 CIRCLE89 74 Personal Compuiing JUN€ rs7, Listin€ 3 - Kalah 3i3rir ii:'i"iit",:"ti3i:3",i",1ti't,;t,:i liti",t -"-. :::;;,,".,11.''. ::9::: i., ,,0,,, :10,., .o,,, .o,., ,.;i.i',, i;i i;; HAVING TBOUBLE LEARNING BAS[C? -"' ;ii ;;i l,-i"'.,:"'"1{t"" STEPBYSTEPEan inloEctivecomputsr coursen BASTC natseasy€venio'begrnnsrsp,og.amDesiqnh€sd6. vgropeoak{rcar,strLciur€d approach rharreartvworrs.Al lhe endofSTEPBYSr Ep,yoJ'l o€ witingDrcEa;s Ls,nsal rmpo.tant BASTC comhands ;i3iii fi: ,i.i*"i'3""i,s_ff ;tj: --,", d,.;i a 'r -,-E r io.r6i:ri;,'i AVATLABIE FoFTFs_Bo LEversra rr,FEiIioiFprE il SfEP BY STEP: . presonlsmatsrialinsmattsleps . provoesglrdedprogramming pracliceneach esso . resrsyourprogress afioreachtesson . rsaches acluarp@gram wnting,notiosttems . rss!,labl€loraryonolromjunio,hqh up.regardt€ss ol r r a r - r r o . r nr r o ' ! i r r n o i , i , 10lessons withqlizzos,ptusfinattest 3 cassolss liujij,illjrHrri;iiljHll'ri;i"i.Ii;i";::e;:":3.3.ei,i,""' 80pagoWo4(book$39.95ptusg1.ooshipptng rnlr rro{rr'r: R!!o!r 133;i:"1';:l'*" pr $Fro! VISAA MaslerChargsaccopted thclJdsnuFb€r,6rp.dste, MClnclud€ dlgitsabov€nam€) iir lirRD or rDr,- Pmg€mD6sign,Inc,11tdafCour|crc€nwich,Conn. 06800 CIFCLE 8 :i;3l:',t:.i,t?t.:liti*;t,it"t":?et:.,:;.i:'ll3: t.;... , 1 r0 r r t r r D . r ) o 1 , . ( P . r i 6 , r MAFIKET INFCIFTMATIE|N EICIFTWAFIE l;83 l:i,':fl:',:til,lr?i r 6YsrEM ? 9 ! 9' r 0 . ! - ! : r ' 0 . 1 i . ,Lo. , M^FKET . COMPLETE INFORMAT'ON SYSTEM |DBMsl IMS] , r r 0 r r r ( 0 . r 6 r <4 l ' ( z r ! ( - z t r DATA FLES IDATAI ;;3it:i.i;;:' :;3:r:i ,' ' r 0 3 0r - r ( 0 r 1 r t i G ) 0 ) {{ 0 . 6 r ! r r < o ! 0 ? o r ( 0 r r 3 - J r - r t o r ! r - J r 4 ( o r r r^: r o d r - o c l B c L E9 0 P€Mnd .:.mnnrino