rem The Vorticon algorithm for the Royal Game of UR rem Throw dice rem 1. Can a piece move off the board (needs exact dice number)? If YES, then make move and take piece out of play. Go to 10 rem 2. Can a piece on the board land on an enemy piece not on a rosette square? if YES, then make move and take out enemy piece. Go to 9 rem 3. Are there >2 pieces on the board that can move? If YES, then move the furthest one. Go to 9 rem 4. Are there any unplayed pieces left? If YES then go to 8 rem 5. Is there a piece on the board that can move? If NO then go to 9 rem 6. Introduce a new piece into the game. rem 7. END computer turn. rem 8. Are all the computer pieces off the board? if YES, then computer wins. STOP rem 9. Go to 9 rem 10.Can a piece on the board or a new piece land on a rosette square free of enemy pieces? If YES, then make move with preference to the piece that can go to the center rosette square. Go to 1 rem t variable t=total of dice rolls rem i variable i=index value to scan arrays rem rf flag for the center rosette rem rp flag for other rosettes rem cb variable initialized to 0 represents number of computer pieces on the board rem cp array cp computer's piece positions rem cn variable initialized to 7 (number of computer pieces not home) rem cw variable set to 1 when cn becomes 0 so cw is a flag saying computer wins rem pb variable initialized to 0 represents number of player pieces on the board rem pp array pp player's piece positions rem pn variable initialized to 7 (number of player pieces new / not in play) rem pw variable set to 1 when pn becomes 0 so pw is a flag saying player wins rem in variable in takes player input : also holds from move location rem out variable holds to move location rem flg rem d variable d looks like temporarily holds value of each individual die roll 30 print "The Royal Game of UR" 40 dim cp(14) 45 dim pp(14) 50 cn=7:pn=7:cb=0:pb=0 :rem initialize key variables 60 gosub 5000 :rem roll dice for first time to decide who plays first 70 if t<3 then goto 100 80 if t>3 then goto 150 90 goto 60 : rem if t=3 then roll again rem ////////////// start of main loop /////////////////// 100 print "my turn" 105 gosub 5100 110 if cw>0 then print "I Win! ":end 115 if rp=-1 and rf=-1 then goto 150 120 goto 100 150 print "your turn" 155 gosub 5700 160 if pw>0 then print "You Win!":end 165 if rf=-1 then goto 100 170 goto 150 rem ////////////// end of main loop /////////////////// 5000 rem roll dice subroutine 5010 t=0 5020 for i=1 to 4 5030 d=INT(RND(0)*4) 5040 if d>2 then d=0:goto 5050 5045 d=1 5050 t=t+d 5060 next i 5070 if t=0 then t=5 : rem rule some use where all dice show zero = 5 5080 return 5100 rem Computer Play 5105 rem check piece exit 5110 gosub 5000:rem roll dice 5115 print "I rolled ";t 5116 rp=-1:rf=-1 5120 if cp(15-t)=0 then goto 5180 5130 cp(15-t)=cp(15-t)-1:cb=cb-1:cn=cn-1 5140 if cn=0 then cw=1 5150 in=15-t:out=15 5160 gosub 6000 : rem print move 5170 return rem check for capture 5180 if cb=0 then 5280 5190 for i=1 to 11 5200 if cp(i)=0 then goto 5270 5210 if i+t<5 then goto 5270 5215 if i+t<15 and pt(i+t)=0 then goto 5270 5220 if i+t=8 then goto 5270 5230 print "Capture ";i;" to ";i+t 5240 pb=pb-pp(i+t):pp(i+t)=0 5250 cp(i)=cp(i)-1:cp(i+t)=1 5260 i=12:flg=1:goto 5270 5270 next i 5275 if flg=1 then flg=0: return 5280 if t<5 then goto 5320 5290 if pp(5)=0 then goto 5320 5300 t=0:print "Capture ";i;" to ";i+t 5301 pb=pb-pp(5):pp(5)=0:cp(5)=cp(5)+1:cb=cb+1:return 5320 for i=1 to 13 5330 if cp(i)=0 then goto 5360 5340 if i+t=8 and pp(8)=0 then rf=i 5350 if i+t=4 or i+t=15 then rp=i 5360 next i 5370 if rf>0 then in=rf:out=in+t:i=rf:goto 5390 5375 if cb<>cn and t=4 then in=0:out=t:rp=1:cb=cb+1:i=0:goto 5390:rem check for rosette 5380 if rp>0 then in=rp:out=in+t:i=rp:goto 5390 5386 goto 5420 5390 gosub 6000 5400 cp(i)=cp(i)-1:cp(i+t)=cp(i+t)+1 5410 return rem Step 4. move furthest piece if > 2 on board 5420 if cb<3 then goto 5550 5440 for i=13 to 1 step -1 5450 if i+t>15 or cp(i)=0 then goto 5520 5455 if i+t=8 and pp(8)>0 then goto 5520 5460 if cp(i)>0 and i=8 then rf=1:goto 5520 5480 in=i:out=i+t:rf=-1 5490 cp(i+t)=cp(i+t)+1:cp(i)=cp(i)-1 5500 gosub 6000:rem print move 5510 flg=1:i=0 5520 next i 5525 if flg=1 then flg=0:return 5530 if rf=-1 then goto 5550 5540 rf=-1:in=8:out=8+t 5541 cp(8+t)=cp(8+t)+1:cp(8)=cp(8)-1 5542 gosub 6000:return rem step 7 introduce new piece to the board 5550 if cn=cb then 5590 5560 cp(t)=cp(t)+1:cb=cb+1 5570 in=0:out=t:gosub 6000:rem print move 5580 return rem move piece if no other move available 5590 for i=13 to 1 step -1 5600 if cp(i)=0 or i+t>15 then goto 5630 5605 if i=8 and pp(8)>0 then goto 5630 5610 in=5:out=i+t:gosub 6000:rem print move 5620 cp(i)=cp(i)-1:cp(i+t)=cp(i+t)+1 5625 flg=1:i=0 5630 next i 5635 if flg=1 then flg=0:return 5640 print " No move for me! ":return 5700 rem player move 5710 gosub 5000 5720 rf=-1 5730 print " You roll ";t 5740 for i=1 to 14 5745 if pp(i)>0 and i+t=8 and cp(8)>0 then goto 5760 5750 if pp(i)>0 and i+t<16 then flg=1:i=15 5760 next i 5765 if flg=1 then flg=0:goto 5800 5770 if pn<>pb then goto 5800 5780 print " You can't move! " 5790 return rem in next line, "beep 3" is used to beep the speaker in the sharp computer 5800 input "from ";in:if in<0 or in>14 then goto 5800 5805 if in=0 and pn=pb then goto 5800 5806 if in+t>15 then goto 5800:rem this traps to make sure exact roll to move off board 5807 if in>0 and pp(in)=0 then goto 5800 5810 if in+t=8 and cp(8)>0 then goto 5800 5815 if in+t=15 then goto 5920 5820 if cp(in+t)=0 then goto 5880 5825 if cp(in+t)>0 and (in+t<5 or in+t>12) then goto 5880 5830 print "You capture ";cp(in+t);"!" 5840 cb=cb-cp(in+t):cp(in+t)=0 5850 if in=0 then pp(t)=pp(t)+1:pb=pb+1:return 5860 pp(in)=pp(in)-1:pp(in+t)=pp(in+t)+1 5870 return 5880 pp(in)=pp(in)-1:pp(in+t)=pp(in+t)+1 5890 if in+t=4 or in+t=8 or in+t=14 then rf=1 5900 if in=0 then pb=pb+1 5910 return 5920 pp(in)=pp(in)-1:pn=pn-1:pb=pb-1 5930 if pn=0 then pw=1 5940 return 6000 rem print move 6010 print "From ";in;" to ";out 6020 return