Command Prompt for Windows




Batch File STONES

The following batch file is an implementation of the old kids game called Stones. The instructions are included in the game :-

@ECHO off
IF NOT "%winone%"=="" GOTO okay
ECHO This Batch file requires the WinOne(R) Command Prompt to run!
EXIT /b
:okay

SETLOCAL
 
GETSTR Instuctions (Y/N) ?
UPPER %getstr%
IF ("%upper%" == "Y") {
    ECHO.
    ECHO In this game, the players, you and the
    ECHO computer, start with a common pile of
    ECHO many stones, usually between 15 and 35.
    ECHO.
    ECHO While alternating turns, you take away
    ECHO one or more stones from the pile.
    ECHO You may not take more than some agreed
    ECHO upon number of stones, usually between
    ECHO three and six.
    ECHO.
    ECHO Whoever is forced to take the last
    ECHO stone loses.
    ECHO.
    ECHO You get to go first.
    ECHO.
}
 
ECHO.
LET remaining=(%random_number% %% 21) + 15
LET max=(%random_number% %% 3) + 3
LET magic=%max% + 1
 
ECHO Starting with %remaining% Stones.
 
:next
ECHO.
GETNUM %remaining% Stones left. Take 1 to %max% stones ?
IF ("%getnum%" == "") {
    ECHO You fool! You must enter the number of stones to take.
    GOTO next
}
 
IF (int(%getnum%) != %getnum%) {
    ECHO You fool! There are no broken stones in the pile.
    GOTO next
}
 
IF (%getnum% < 1 || %getnum% > %max%) {
    ECHO You cheat! You may only take 1 to %max% stones.
    GOTO next
}
 
ECHO Human takes %getnum% stones
IF (%getnum% < %remaining%) {
    LET remaining=%remaining% - %getnum%
    IF (%remaining% == 1) {
        SAY Hmmm I lost. You must be 
		ECHO running the program on a defective computer.
        ENDLOCAL
        END
    }
 
    LET mymove=(%remaining% - 1) %% %magic%
    IF (%mymove% == 0) LET mymove=(%random_number% %% %max%) + 1
 
    LET left=%remaining% - %mymove%
    SAY Hmm %remaining% stones left. 
	ECHO  I take %mymove% stones, leaving %left%.
 
    LET remaining=%left%
    IF (%remaining% != 1) GOTO next
}
 
ECHO Human stuck with final stone.
ECHO Nyah Nyah Nyah.  You Lose.
 
ENDLOCAL

Running this batch file produces the following output :-

Instuctions (Y/N) ?y
 
In this game, the players, you and the
computer, start with a common pile of
many stones, usually between 15 and 35.
 
While alternating turns, you take away
one or more stones from the pile.
You may not take more than some agreed
upon number of stones, usually between
three and six.
 
Whoever is forced to take the last
stone loses.
 
You get to go first.
 
 
Starting with 32 Stones.
 
32 Stones left. Take 1 to 3 stones ?3
Human takes 3 stones
Hmm 29 stones left. I take 3 stones, leaving 26.
 
26 Stones left. Take 1 to 3 stones ?2
Human takes 2 stones
Hmm 24 stones left. I take 3 stones, leaving 21.
 
21 Stones left. Take 1 to 3 stones ?3
Human takes 3 stones
Hmm 18 stones left. I take 1 stones, leaving 17.
 
17 Stones left. Take 1 to 3 stones ?1
Human takes 1 stones
Hmm 16 stones left. I take 3 stones, leaving 13.
 
13 Stones left. Take 1 to 3 stones ?3
Human takes 3 stones
Hmm 10 stones left. I take 1 stones, leaving 9.
 
9 Stones left. Take 1 to 3 stones ?2
Human takes 2 stones
Hmm 7 stones left. I take 2 stones, leaving 5.
 
5 Stones left. Take 1 to 3 stones ?1
Human takes 1 stones
Hmm 4 stones left. I take 3 stones, leaving 1.
Human stuck with final stone.
Nyah Nyah Nyah.  You Lose.