Return to main

Get a 60-day FREE trial!

See examples

How was this done?

How was this done?

Tech support

icon

Here's how this was done:

; This is the Stones  game.
; stones.web and stones.gif should be in webcgi

  
; Skip over subroutines
goto doittoit                         


;---------------------------------------------------------------------

; output top of page
:dotop                                
WebOut('<H2>WebBatch® Stones</H2>',1)
WebOut('<p>In the game stones, you start with a pile of stones.  
        You may remove one, two, or three stones from the pile.  
        The person left with the last stone loses.<hr>',1)
return


;---------------------------------------------------------------------

; output the form
:daform                                
WebOut("How many stones do you wish to take?<br>",1)
WebOut('<FORM ACTION="/webcgi/webbatch.exe?stones/stones.web+%stones%" 
         METHOD=POST>',1)
WebOut('<SELECT NAME=taken><OPTION>1
        <OPTION>2<OPTION>3</SELECT>',1)
WebOut('<INPUT TYPE="SUBMIT" VALUE="Take Stones">',1)
WebOut('</FORM>',1)
return


;---------------------------------------------------------------------

; Display rows of five stones
:drawstones                            
x=XStones/5
for y=1 to x
   WebOut('<IMG SRC="/webcgi/webbatch.exe?dumpgif+stones/stone.gif" 
            HEIGHT=20 WIDTH=20>
           <IMG SRC="/webcgi/webbatch.exe?dumpgif+stones/stone.gif" 
            HEIGHT=20 WIDTH=20>',0)
   WebOut('<IMG SRC="/webcgi/webbatch.exe?dumpgif+stones/stone.gif" 
            HEIGHT=20 WIDTH=20>
           <IMG SRC="/webcgi/webbatch.exe?dumpgif+stones/stone.gif" 
            HEIGHT=20 WIDTH=20>
           <IMG SRC="/webcgi/webbatch.exe?dumpgif+stones/stone.gif" 
            HEIGHT=20 WIDTH=20><br>',1)
next
x=XStones mod 5
for y=1 to x
    WebOut('<IMG SRC="/webcgi/webbatch.exe?dumpgif+stones/stone.gif" 
             HEIGHT=20 WIDTH=20>',0)
next
WebOut("<hr>",1)
return


;---------------------------------------------------------------------

; Code really starts here
:doittoit  
                             
; Output content type
WebOut('Content-type: text/html', 2) 

; Usual HTML Stuff  
WebOut('<HTML><HEAD><TITLE>Stones</TITLE>
        </HEAD><BODY>',1)
         
; Do the main body
gosub  dobody       

; Usual HTML stuff                    
WebOut('</BODY></HTML>',1)
exit                                    




;---------------------------------------------------------------------

; the guts of the code
:dobody                
                 
; Pick number of stones off of the command line
Stones=strtrim(WebCmdData())            

; How many can we take per turn
MaxTakePerTurn =  3                     

; Compute magic number (rocket science stuff here...)
TheMagicNumber = MaxTakePerTurn + 1     

; If stones is blank, new game, get a new number of stones,
; Show Introduction, and setup a game.
if Stones==""                           
        ; make a random number betwixt 15 ans 30                              
        stones=Int(Random(15))+15
        
        ; output top of page       
        gosub dotop                     
        xstones=stones
        WebOut("Game starting with %stones% stones.<br>",1)
        
        ; Draw the remaining stones
        gosub drawstones
        
        ; Output the form                
        gosub daform                    

; otherwise, we're continuing a game
else                                 
        ; Output top of form
        gosub dotop     
                        
        ; Process current guess
        ; Get number of stones taken in previous move
        taken=WebParamData("taken")   
          
        ; Compute number of stones left
        StonesLeft=max(0,Stones-taken)
        
        ; Do some variable initialization to make
        ; English sentences below grammatically correct...
        if stonesleft==1                
           vvv="is"                     
           sss=""
        else
           vvv="are"
           sss="s"
        endif
        
        ; Report on the move
        WebOut("There were %stones% stones.  You took %taken%.  
                There %vvv% now %stonesleft% stone%sss% left.<br>",1)
                
        Stones=StonesLeft
        xstones=stones
        
        ; Draw remaining stones
        gosub drawstones   
                     
        ;Check the score!
        if Stones==1      ; Computer lost.  Whine a lot.               
           WebOut("What??!!??  How did that happen?  
                   Must have been some kind of TCP/IP network error 
                   with the analog pulse-reversing ossillosophilator.  
                   Please contact your Internet provider and 
                   get it repaired.",1)
           WebOut('<br><A HREF=/webcgi/webbatch.exe?stones/stones.web>
                   Play Again?</a>',1)
                   
        else
        
           if Stones==0   ; User lost.  Ha Ha Ha Ha Ha Ha Ha
              WebOut("You took the last stone.  You lost.  Tough cookies.",1)
              WebOut('<br><A HREF=/webcgi/webbatch.exe?stones/stones.web>
                      Play Again?</a>',1)
                      
           else
           
              ;Computer figures out its move here
              MyMove =Stones - 1
              MyMove = MyMove mod TheMagicNumber
              
              ; If mymove is zero, computer is in a bad position
              ; Pick a random number and hope user makes a mistrake.
              if MyMove == 0 then MyMove = Int(max(1,Random(MaxTakePerTurn)))
              
              ; Compute stones left
              StonesLeft =Stones-MyMove 
              
              ; more stuff for correct English grammer
              if MyMove==1 then x=""    
              else x="s"
              
              ; Report on what computer did
              MyBoxText=strcat("I take %MyMove% stone%x%, 
                                leaving %StonesLeft%.<br>")
              Stones = StonesLeft
              xstones=Stones
              WebOut(MyBoxText,1)
              
              ; Draw the move
              gosub drawstones
              
              ; check to see if user lost                       
              if Stones==1   ; Ha Ha Ha Ha Ha Ha           
                 WebOut('You are stuck with the last stone. You lose.',1)
                 WebOut('<br><A HREF=/webcgi/webbatch.exe?stones/stones.web>
                         Play Again?</a>',1)
                         
              else
              
                 ; Draw the form  
                 gosub daform            
              endif
           endif
        endif   
endif        

return
Note: Some lines in this source code have been broken for improved readability.
Copyright ©1996-2023 by Island Lake Consulting LLC WebBatch is a trademark of Island Lake Consulting LLC. All other trademarks are the property of their respective owners.