Added MiniScript versions of 72_Queen and 74_Rock_Scissors_Paper.

This commit is contained in:
JoeStrout
2023-10-01 15:38:34 -07:00
parent 75b0ce9c46
commit 22e011349c
4 changed files with 230 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
Original source downloaded from [Vintage Basic](http://www.vintage-basic.net/games.html).
Conversion to [MiniScript](https://miniscript.org).
Ways to play:
1. Command-Line MiniScript:
Download for your system from https://miniscript.org/cmdline/, install, and then run the program with a command such as:
```
miniscript queen.ms
```
2. Mini Micro:
Download Mini Micro from https://miniscript.org/MiniMicro/, launch, and then click the top disk slot and chose "Mount Folder..." Select the folder containing the MiniScript program and this README file. Then, at the Mini Micro command prompt, enter:
```
load "queen"
run
```

View File

@@ -0,0 +1,151 @@
print " "*33 + "QUEEN"
print " "*15 + "Creative Computing Morristown New Jersey"
print; print; print
getYesNo = function(prompt)
while true
inp = input(prompt + "? ").lower + " "
if inp[0] == "y" then return "yes"
if inp[0] == "n" then return "no"
print "Please answer 'yes' or 'no'."
end while
end function
printDirections = function
print "We are going to play a game based on one of the chess"
print "moves. Our queen will be able to move only to the left "
print "down or diagonally down and to the left."
print
print "The object of the game is to place the queen in the lower"
print "left hand square by alternating moves between you and the"
print "computer. The first one to place the queen there wins."
print
print "You go first and place the queen in any one of the squares"
print "on the top row or right hand column."
print "That will be your first move."
print "We alternate moves."
print "You may forfeit by typing '0' as your move."
print "Be sure to press the return key after each response."
print
input "(Press Return to continue.)"
print
end function
printCoordinates = function
// Porting note: I cannot imagine what possessed the original author to
// use such a crazy numbering scheme, which is not easy for the human
// player OR the code. But assumptions about it are scattered throughout
// the whole program, so we're stuck with it.
print
print " 81 71 61 51 41 31 21 11"
print " 92 82 72 62 52 42 32 22"
print " 103 93 83 73 63 53 43 33"
print " 114 104 94 84 74 64 54 44"
print " 125 115 105 95 85 75 65 55"
print " 136 126 116 106 96 86 76 66"
print " 147 137 127 117 107 97 87 77"
print " 158 148 138 128 118 108 98 88"
print
end function
getStartPos = function
while true
m1 = input("Where would you like to start? ").val
tens = floor(m1/10)
ones = m1 % 10
if ones == 1 or tens == ones or m1 == 0 then return m1
print "Please read the directions again."
print "You have begun illegally."
print
end while
end function
isGoodMove = function(ones, tens)
pos = 10 * tens + ones
return [158, 127, 126, 75, 73].indexOf(pos) != null
end function
getRandomMove = function(queenPos)
tens = floor(queenPos/10)
ones = queenPos % 10
z = rnd
if z > 0.6 then
return 10 * (tens+1) + ones
else if z > 0.3 then
return 10 * (tens+2) + (ones+1)
else
return 10 * (tens+1) + ones
end if
end function
getComputerMove = function(queenPos)
tens = floor(queenPos/10)
ones = queenPos % 10
if [41, 44, 73, 75, 126, 127].indexOf(queenPos) != null then return getRandomMove(queenPos)
for k in range(7, 1)
if isGoodMove(ones, tens+k) then return 10 * (tens+k) + ones // left
if isGoodMove(ones+k, tens+k) then return 10 * (tens+k) + (ones+k) // down
if isGoodMove(ones+k, tens+k*2) then return 10 * (tens+k*2) + (ones+k) // down-left
end for
return getRandomMove(queenPos)
end function
getHumanMove = function(queenPos)
tens = floor(queenPos/10)
ones = queenPos % 10
while true
pos = input("What is your move? ").val
if pos == 0 then return 0
dTens = floor(pos/10) - tens
dOnes = pos % 10 - ones
ok = false
if dOnes == 0 and dTens > 0 then ok = true // moving left
if dOnes == dTens and dOnes > 0 then ok = true // moving down
if dTens == dOnes*2 and dOnes > 0 then ok = true // moving down-left
if ok then return pos
print
print "Y O U C H E A T . . . Try again";
end while
end function
playGame = function
queenPos = getStartPos
while true
if queenPos == 0 then
print "It looks like I have won by forfeit."
return
end if
// computer move
queenPos = getComputerMove(queenPos)
print "Computer moves to square " + queenPos
if queenPos == 158 then
print
print "Nice try, but it looks like I have won."
return
end if
// human move
queenPos = getHumanMove(queenPos)
if queenPos == 158 then
print
print "C O N G R A T U L A T I O N S . . ."
print
print "You have won--very well played."
print "It looks like I have met my match."
print "Thanks for playing---I can't win all the time."
return
end if
end while
end function
// Main program
if getYesNo("Do you want instructions") == "yes" then printDirections
while true
printCoordinates
playGame
print
if getYesNo("Anyone else care to try") == "no" then break
end while
print
print "OK --- Thanks again."

View File

@@ -0,0 +1,21 @@
Original source downloaded from [Vintage Basic](http://www.vintage-basic.net/games.html).
Conversion to [MiniScript](https://miniscript.org).
Ways to play:
0. Try-It! Page:
Go to https://miniscript.org/tryit/, clear the sample code from the code editor, and paste in the contents of rockscissors.ms. Then click the "Run Script" button. Program output (and input) will appear in the green-on-black terminal display to the right of or below the code editor.
1. Command-Line MiniScript:
Download for your system from https://miniscript.org/cmdline/, install, and then run the program with a command such as:
```
miniscript rockscissors.ms
```
2. Mini Micro:
Download Mini Micro from https://miniscript.org/MiniMicro/, launch, and then click the top disk slot and chose "Mount Folder..." Select the folder containing the MiniScript program and this README file. Then, at the Mini Micro command prompt, enter:
```
load "rockscissors"
run
```

View File

@@ -0,0 +1,40 @@
print " "*21 + "Game of Rock, Scissors, Paper"
print " "*15 + "Creative Computing Morristown New Jersey"
print; print; print
while true
numGames = input("How many games? ").val
if 0 < numGames < 11 then break
print "Sorry, but we aren't allowed to play that many."
end while
computerWins = 0
playerWins = 0
for game in range(1, numGames)
print; print "Game number " + game
myChoice = floor(rnd*3 + 1)
while true
print "3=Rock...2=Scissors...1=Paper"
playerChoice = input("1...2...3...What's your choice? ").val
if [1,2,3].indexOf(playerChoice) != null then break
print "Invalid."
end while
print "This is my choice..."
print ["...Paper", "...Scissors", "...Rock"][myChoice-1]
diff = myChoice - playerChoice
if diff == 0 then
print "Tie game. No winner."
else if diff == 1 or diff == -2 then
print "Wow! I win!!!"
computerWins += 1
else
print "You win!!!"
playerWins += 1
end if
end for
print; print "Here is the final game score:"
print "I have won " + computerWins + " game(s)."
print "You have won " + playerWins + " game(s)."
print "And " + (numGames - computerWins - playerWins) + " game(s) ended in a tie."
print; print "Thanks for playing!!"