Merge pull request #874 from JoeStrout/miniscript-batch-4

Miniscript batch 4
This commit is contained in:
Jeff Atwood
2023-08-02 16:20:29 -07:00
committed by GitHub
29 changed files with 1834 additions and 4 deletions
@@ -0,0 +1,19 @@
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 change.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 change.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "change"
run
@@ -0,0 +1,57 @@
print " "*33 + "Change"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print; print
print "I, your friendly microcomputer, will determine"
print "the correct change for items costing up to $100."
print; print
while true
itemCost = input("Cost of item? ").val
if itemCost == 0 then break
payment = input("Amount of payment? ").val
change = payment - itemCost
if change < 0 then
print "Sorry, you have short-changed me $" + (itemCost - payment)
continue
else if change == 0 then
print "Correct amount, thank you."
continue
end if
print "Your change, $" + change
dollars = floor(change/10)
if dollars then print dollars + " ten dollar bill(s)"
change -= dollars * 10
fivers = floor(change/5)
if fivers then print fivers + " five dollar bill(s)"
change -= fivers * 5
ones = floor(change)
if ones then print ones + " one dollar bill(s)"
change -= ones
change *= 100 // (now working in cents)
halfs = floor(change / 50)
if halfs then print halfs + " one half dollar(s)"
change -= halfs * 50
quarters = floor(change / 25)
if quarters then print quarters + " quarter(s)"
change -= quarters * 25
dimes = floor(change / 10)
if dimes then print dimes + " dime(s)"
change -= dimes * 10
nickels = floor(change / 5)
if nickels then print nickels + " nickel(s)"
change -= nickels * 5
pennies = round(change)
if pennies then print pennies + " penny(s)"
print "Thank you, come again."
print; print
end while
@@ -0,0 +1,16 @@
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 checkers.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "checkers"
run
@@ -0,0 +1,243 @@
print " "*32 + "Checkers"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print; print
print "This is the game of Checkers. The computer is X,"
print "and you are O. The computer will move first."
print "Squares are referred to by a coordinate system."
print "(0,0) is the lower left corner"
print "(0,7) is the upper left corner"
print "(7,0) is the lower right corner"
print "(7,7) is the upper right corner"
print "The computer will type '+TO' when you have another"
print "jump. Type two negative numbers if you cannot jump."
print; print; print
input "(Press Return.)"; print // (give player a chance to read)
// The board. Pieces are represented by numeric values:
// - 0 = empty square
// - -1,-2 = computer (X) (-1 for regular piece, -2 for king)
// - 1,2 = human (O) (1 for regular piece, 2 for king)
// Board is indexed by [x][y], so we have to initialize it sideways:
board = [
[ 1, 0, 1, 0, 0, 0, -1, 0],
[ 0, 1, 0, 0, 0, -1, 0, -1],
[ 1, 0, 1, 0, 0, 0, -1, 0],
[ 0, 1, 0, 0, 0, -1, 0, -1],
[ 1, 0, 1, 0, 0, 0, -1, 0],
[ 0, 1, 0, 0, 0, -1, 0, -1],
[ 1, 0, 1, 0, 0, 0, -1, 0],
[ 0, 1, 0, 0, 0, -1, 0, -1]]
// Function to print the board
printBoard = function
for y in range(7, 0)
for x in range(0, 7)
// We print by indexing with the board entry (-2 to 2) into a list
// of possible representations. Remember that in MiniScript, a
// negative index counts from the end.
print [". ", "O ", "O*", "X*", "X "][board[x][y]], " "
end for
print; print
end for
end function
// Function to get x,y coordinates from the player.
// This is written to allow the two numbers to be
// separated by any combination of ',' and ' '.
// Returns input as [x,y].
inputPosition = function(prompt, requiredPieceSign, allowCancel=false)
while true
ans = input(prompt + "? ").replace(",", " ").split
if ans.len < 2 then
print "Enter two coordinates, for example: 4 0"
continue
end if
x = val(ans[0])
y = val(ans[-1])
if x < 0 and y < 0 and allowCancel then
return [x, y]
else if x < 0 or x > 7 or y < 0 or y > 7 then
print "Coordinates must be in the range 0-7"
else if x%2 != y%2 then
print "Invalid coordinates (both must be odd, or both even)"
else if sign(board[x][y]) != requiredPieceSign then
print "Invalid coordinates"
else
return [x, y]
end if
end while
end function
// Evaluate a potential (computer) move.
evalMove = function(fromX, fromY, toX, toY)
score = 0
// +2 if it promotes this piece
if toY == 0 and board[fromX][fromY] == -1 then score += 2
// +5 if it jumps an opponent's piece
if abs(fromY-toY) == 2 then score += 5
// -2 if the piece is moving away from the top boundary
if fromY == 7 then score -= 2
// +1 for putting the piece against a vertical boundary
if toX == 0 or toX == 7 then score += 1
// check neighboring pieces of the target position
for c in [-1, 1]
if toX+c < 0 or toX+c > 7 or toY-1 < 0 then continue
// +1 for each adjacent friendly piece
if board[toX+c][toY-1] < 0 then score += 1
// -1 for each opponent piece that could now jump this one
if toX-c >= 0 and toX-c <= 7 and toY+1 <= 7 and board[toX+c][toY-1] > 0 and (
board[toX-c][toY+1] == 0 or (toX-c == fromX and toY+1 == fromY)) then score -= 2
end for
return score
end function
// Consider a possible (computer) move, including whether it's even valid.
// Return it or the previous best, whichever is better.
consider = function(fromX, fromY, toX, toY, previousBest)
// make sure it's within the bounds of the board
if toX < 0 or toX > 7 or toY < 0 or toY > 7 then return previousBest
// if it's an opponent's piece, consider jumping it instead
dx = toX - fromX
if board[toX][toY] > 0 and abs(dx) == 1 then
dy = toY - fromY
return consider(fromX, fromY, fromX + dx*2, fromY + dy*2, previousBest)
end if
// if it's a jump, make sure it's over an opponent piece
if abs(dx) == 2 then
midX = (fromX + toX)/2; midY = (fromY + toY)/2
if board[midX][midY] < 1 then return previousBest
end if
// make sure the destination is empty
if board[toX][toY] then return previousBest
// all checks passed; score it, and return whichever is better
rating = evalMove(fromX, fromY, toX, toY)
if not previousBest or rating > previousBest.rating then
newBest = {}
newBest.fromX = fromX; newBest.fromY = fromY
newBest.toX = toX; newBest.toY = toY
newBest.rating = rating
return newBest
else
return previousBest
end if
end function
// Do the computer's turn
doComputerTurn = function
// For each square on the board containing one of my pieces, consider
// possible moves and keep the best one so far. Start with a step
// size of 1 (ordinary move), but if we jump, then keep jumping.
stepSize = 1
while true
bestMove = null
for x in range(0, 7)
for y in range(0, 7)
if board[x][y] >= 0 then continue // not my piece
move = {}
move.fromPos = [x,y]
// Consider forward moves; if it's a king, also consider backward moves
for dx in [-stepSize, stepSize]
move.toPos = [dx, -stepSize]
bestMove = consider(x, y, x+dx, y-stepSize, bestMove)
if board[x][y] == -2 then bestMove = consider(x, y, x+dx, y+stepSize, bestMove)
end for
end for
end for
if not bestMove then
// No valid move -- if step size is still 1, this means we
// couldn't find ANY move on our turn, and we have lost.
// Otherwise, we're done.
if stepSize == 1 then
globals.gameOver = true
globals.winner = 1
end if
break
end if
// Do the move, and stop if we did not jump.
if stepSize == 1 then
print "From " + bestMove.fromX + " " + bestMove.fromY, ""
end if
print " to " + bestMove.toX + " " + bestMove.toY, ""
movePiece bestMove.fromX, bestMove.fromY, bestMove.toX, bestMove.toY
if abs(bestMove.toX - bestMove.fromX) == 1 then break
stepSize = 2
end while
print
end function
// Move one piece (including captures and crowning
movePiece = function(fromX, fromY, toX, toY)
piece = board[fromX][fromY]
board[toX][toY] = piece
board[fromX][fromY] = 0
// capture piece jumped over
if abs(toX - fromX) == 2 then
board[(fromX+toX)/2][(fromY+toY)/2] = 0
end if
// crown (make into a king) a piece that reaches the back row
if (toY == 7 and piece > 0) or (toY == 0 and piece < 0) then
board[toX][toY] = 2 * sign(piece)
end if
end function
// Handle the player's move.
doPlayerTurn = function
fromPos = inputPosition("From", 1, true)
fromX = fromPos[0]; fromY = fromPos[1]
if fromX < 0 then
// Player concedes the game.
globals.gameOver = true
globals.winner = -1
return
end if
while true
toPos = inputPosition("To", 0)
toX = toPos[0]; toY = toPos[1]
dist = abs(toX - fromX)
if dist <= 2 and abs(toY - fromY) == dist then break
end while
while true
// Make the move, and continue as long as we have a jump
movePiece fromX, fromY, toX, toY
if dist != 2 then break
// Prompt for another move, allowing a cancel (negative input).
fromX = toX; fromY = toX
toPos = inputPosition("+To", 0, true)
if toPos[0] < 0 or toPos[1] < 0 then break
toX = toPos[0]; toY = toPos[1]
end while
// If piece has reached the end of the board, crown this piece
if toY == 7 then board[toX][toY] = 2
end function
// Main loop.
gameOver = false
while not gameOver
doComputerTurn
if gameOver then break
printBoard
doPlayerTurn
if gameOver then break
printBoard
end while
print
if winner > 0 then print "You win." else print "I win."
@@ -0,0 +1,19 @@
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 chemist.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 chemist.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "chemist"
run
@@ -0,0 +1,30 @@
print " "*33 + "Chemist"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print; print
print "The fictitious chemical kryptocyanic acid can only be"
print "diluted by the ratio of 7 parts water to 3 parts acid."
print "If any other ratio is attempted, the acid becomes unstable"
print "and soon explodes. Given the amount of acid, you must"
print "decide how much water to add for dilution. If you miss"
print "you face the consequences."
deaths = 0
while deaths < 9
acid = floor(rnd * 50)
water = 7 * acid/3
response = input(acid +" liters of kryptocyanic acid. How much water? ").val
diff = abs(water - response)
if diff > water/20 then
print " SIZZLE! You have just been desalinated into a blob"
print " of quivering protoplasm!"
deaths += 1
if deaths < 9 then
print " However, you may try again with another life."
end if
else
print " Good job! You may breathe now, but don't inhale the fumes!"
print
end if
end while
print " Your 9 lives are used, but you will be long remembered for"
print " your contributions to the field of comic book chemistry."
@@ -0,0 +1,21 @@
Original source downloaded from [Vintage Basic](http://www.vintage-basic.net/games.html).
Conversion to [MiniScript](https://miniscript.org).
NOTE: I have added `wait` statements before and while printing the lightning bolt, without which it appears too quickly to be properly dramatic.
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 chief.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 chief.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "chief"
run
@@ -0,0 +1,50 @@
print " "*30 + "Chief"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print; print
print "I am chief Numbers Freek, the great Indian math god."
yn = input("Are you ready to take the test you called me out for? ").lower
if not yn or yn[0] != "y" then
print "Shut up, pale face with wise tongue."
end if
print " Take a number and add 3. Divide this number by 5 and"
print "multiply by 8. Divide by 5 and add the same. Subtract 1."
b = input(" What do you have? ").val
c = (b+1-5)*5/8*5-3
yn = input("I bet your number was " + c + ". Am I right? ").lower
if yn and yn[0] == "y" then
print "Bye!!!"
else
k = input("What was your original number? ").val
f=k+3
g=f/5
h=g*8
i=h/5+5
j=i-1
print "So you think you're so smart, eh?"
print "Now watch."
print k + " plus 3 equals " + f +". This divided by 5 equals " + g + ";"
print "this times 8 equals " + h + ". If we divide by 5 and add 5,"
print "we get " + i + ", which, minus 1, equals " + j + "."
yn = input("Now do you believe me? ").lower
if yn and yn[0] == "y" then
print "Bye!!!"
else
print "You have made me mad!!!"
print "There must be a great lightning bolt!"
print; print; wait 2
for x in range(30, 22)
print " "*x + "x x"; wait 0.1
end for
print " "*21 + "x xxx"; wait 0.1
print " "*20 + "x x"; wait 0.1
print " "*19 + "xx x"; wait 0.1
for y in range(20, 13)
print " "*y + "x x"; wait 0.1
end for
print " "*12 + "xx"; wait 0.1
print " "*11 + "x"; wait 0.1
print " "*10 + "*"; wait 0.1
print; print"#########################"; print
print "I hope you believe me now, for your sake!!"
end if
end if
@@ -0,0 +1,16 @@
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 chomp.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "chomp"
run
@@ -0,0 +1,102 @@
print " "*33 + "Chomp"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print; print
// *** THE GAME OF CHOMP *** COPYRIGHT PCC 1973 ***
initBoard = function(rows, columns)
globals.rows = rows
globals.columns = columns
globals.board = [[null]] // indexed as [row][column], 1-based
for i in range(1, rows)
board.push ["."] + ["*"] * columns
end for
board[1][1] = "P"
end function
printBoard = function
print
print " "*7 + "1 2 3 4 5 6 7 8 9"
for i in range(1, rows)
print i + " "*6 + board[i][1:].join
end for
print
end function
introduction = function
print
print "This is the game of chomp (Scientific American, Jan 1973)"
r = input("Do you want the rules (1=yes, 0=no!)? ").val
if r == 0 then return
print "Chomp is for 1 or more players (humans only)."
print
print "Here's how a board looks (this one is 5 by 7):"
initBoard 5, 7
printBoard
print
print "The board is a big cookie - R rows high and C columns"
print "wide. You input R and C at the start. In the upper left"
print "corner of the cookie is a poison square (P). The one who"
print "chomps the poison square loses. To take a chomp, type the"
print "row and column of one of the squares on the cookie."
print "All of the squares below and to the right of that square"
print "(including that square, too) disappear -- chomp!!"
print "No fair chomping squares that have already been chomped,"
print "or that are outside the original dimensions of the cookie."
print
end function
setup = function
print
globals.numPlayers = input("How many players? ").val
rows = input("How many rows? ").val
while rows > 9
rows = input("Too many rows (9 is maximum). Now, how many rows? ").val
end while
columns = input("How many columns? ").val
while rows > 9
columns = input("Too many columns (9 is maximum). Now, how many columns? ").val
end while
print
initBoard rows, columns
end function
doOneTurn = function(player)
printBoard
print "Player " + player
while true
inp = input("Coordinates of chomp (row,column)? ")
inp = inp.replace(",", " ").split
if inp.len < 2 then continue
r = inp[0].val
c = inp[-1].val
if 1 <= r <= rows and 1 <= c <= columns and board[r][c] != " " then break
print "No fair. You're trying to chomp on empty space!"
end while
if board[r][c] == "P" then
print "You lose, player " + player
globals.gameOver = true
else
end if
for row in range(r, rows)
for col in range(c, columns)
board[row][col] = " "
end for
end for
end function
// Main program
introduction
while true
setup
gameOver = false
player = 0
while not gameOver
player += 1
if player > numPlayers then player = 1
doOneTurn player
end while
print
r = input("Again (1=yes, 0=no!)? ").val
if r != 1 then break
end while
@@ -0,0 +1,16 @@
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 civilwar.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "civilwar"
run
@@ -0,0 +1,437 @@
print " "*26 + "Civil War"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print; print
// ORIGINAL GAME DESIGN: CRAM, GOODIE, HIBBARD LEXINGTON H.S.
// MODIFICATIONS: G. PAUL, R. HESS (TIES), 1973
// Conversion to MiniScript: J. Strout, 2023
sides = ["Confederate", "Union"]
getYesNo = function(prompt)
while true
yn = input(prompt + "? ").lower
if yn and yn[0] == "y" then return "YES"
if yn and yn[0] == "n" then return "NO"
print "Yes or no -- "
end while
end function
instructions = function
print; print; print; print
print "This is a civil war simulation."
print "To play type a response when the computer asks."
print "Remember that all factors are interrelated and that your"
print "responses could change history. Facts and figures used are"
print "based on the actual occurrence. Most battles tend to result"
print "as they did in the civil war, but it all depends on you!!"
print
print "The object of the game is to win as many battles as ";
print "possible."
print
print "Your choices for defensive strategy are:"
print " (1) artillery attack"
print " (2) fortification against frontal attack"
print " (3) fortification against flanking maneuvers"
print " (4) falling back"
print " Your choices for offensive strategy are:"
print " (1) artillery attack"
print " (2) frontal attack"
print " (3) flanking maneuvers"
print " (4) encirclement"
print "You may surrender by typing a '5' for your strategy."
end function
historicalBattles = []
addBattle = function(name, men0, men1, cas0, cas1, offDef, desc)
battle = {}
battle.name = name
battle.men = [men0, men1]
battle.casualties = [cas0, cas1]
battle.offDef = offDef // 1=Confederate Defense, 2=both Offense, 3=Confederate Offense
battle.description = desc
historicalBattles.push battle
end function
loadData = function
// Historical data
addBattle "Bull Run",18000,18500,1967,2708,1, [
"July 21, 1861. Gen. Beauregard, commanding the South, met",
"Union forces with Gen. Mcdowell in a premature battle at",
"Bull Run. Gen. Jackson helped push back the Union attack."]
addBattle "Shiloh",40000.,44894.,10699,13047,3, [
"April 6-7, 1862. The Confederate surprise attack at",
"Shiloh failed due to poor organization."]
addBattle "Seven Days",95000.,115000.,20614,15849,3, [
"June 25-july 1, 1862. General Lee (CSA) upheld the",
"offensive throughout the battle and forced Gen. McClellan",
"and the Union forces away from Richmond."]
addBattle "Second Bull Run",54000.,63000.,10000,14000,2, [
"Aug 29-30, 1862. The combined Confederate forces under Lee",
"and Jackson drove the Union forces back into washington."]
addBattle "Antietam",40000.,50000.,10000,12000,3, [
"Sept 17, 1862. The South failed to incorporate Maryland",
"into the Confederacy."]
addBattle "Fredericksburg",75000.,120000.,5377,12653,1, [
"Dec 13, 1862. The Confederacy under Lee successfully",
"repulsed an attack by the Union under Gen. Burnside."]
addBattle "Murfreesboro",38000.,45000.,11000,12000,1, [
"Dec 31, 1862. The South under Gen. Bragg won a close battle."]
addBattle "Chancellorsville",32000,90000.,13000,17197,2, [
"May 1-6, 1863. The South had a costly victory and lost",
"one of their outstanding generals, 'Stonewall' Jackson."]
addBattle "Vicksburg",50000.,70000.,12000,19000,1, [
"July 4, 1863. Vicksburg was a costly defeat for the South",
"because it gave the Union access to the Mississippi."]
addBattle "Gettysburg",72500.,85000.,20000,23000,3, [
"July 1-3, 1863. A Southern mistake by Gen. Lee at Gettysburg",
"cost them one of the most crucial battles of the war."]
addBattle "Chickamauga",66000.,60000.,18000,16000,2, [
"Sept. 15, 1863. Confusion in a forest near Chickamauga led",
"to a costly Southern victory."]
addBattle "Chattanooga",37000.,60000.,36700.,5800,2, [
"Nov. 25, 1863. After the South had sieged Gen. Rosencrans'",
"army for three months, Gen. Grant broke the siege."]
addBattle "Spotsylvania",62000.,110000.,17723,18000,2, [
"May 5, 1864. Grant's plan to keep Lee isolated began to",
"fail here, and continued at Cold Harbor and Petersburg."]
addBattle "Atlanta",65000.,100000.,8500,3700,1, [
"August, 1864. Sherman and three veteran armies converged",
"on Atlanta and dealt the death blow to the Confederacy."]
end function
setup = function
print; print; print
if getYesNo("Are there two generals present") == "YES" then
globals.numPlayers = 2
else
globals.numPlayers = 1
print; print "You are the Confederacy. Good luck!"
print
end if
print "Select a battle by typing a number from 1 to 14 on"
print "request. Type any other number to end the simulation."
print "But '0' brings back exact previous battle situation"
print "allowing you to replay it."
print
print "Note: a negative food$ entry causes the program to "
print "use the entries from the previous battle."
print
yn = getYesNo("After requesting a battle, do you wish battle descriptions")
globals.battleDesc = (yn == "YES")
end function
// Game variables -- the 2-element arrays below represent the stats for
// player 0 (Confederacy) and 1 (Union)
D = [0,0] // money
F = [0,0] // food budget
H = [0,0] // salary budget
B = [0,0] // ammo budget
men = [0,0] // men at start of battle? (M1, M2)
menAdded = [0,0] // men added (M3, M4)
menAvail = [0,0] // men available (M5, M6)
P = [0,0] // casualties?
T = [0,0] // total losses?
resources = [0,0] // total resources (money) available to each side (R1, R2)
spending = [0,0] // total expenditures for each side (Q1, Q2)
morale = [0,0] // troop morale (O)
strategy = [0,0] // strategy choice (Y1, Y2)
inflation = [0,0] // inflation (I1, I2)
R = 0 // previous battle
losses = 0 // Confederate losses
wins = 0 // Confederate wins
unresolved = 0 // battles where neither side clearly won
printInColumns = function(a, b, c)
print (a + " "*20)[:20] + (b + " "*16)[:16] + c
end function
pickBattle = function
print; print; print
globals.replay = false
while true
num = input("Which battle do you wish to simulate? ").val
if num == 0 and R > 0 then
num = R
globals.replay = true
end if
if 0 < num <= historicalBattles.len then break
end while
globals.bat = historicalBattles[num - 1]
if not replay then
men[0] = bat.men[0]
men[1] = bat.men[1]
// inflation calc
inflation[0] = 10 + (losses - wins) * 2
inflation[1] = 10 + (wins - losses) * 2
// money available
D[0] = 100 * floor((men[0]*(100-inflation[0])/2000) * (1+(resources[0]-spending[0])/(resources[0]+1))+0.5)
D[1] = 100 * floor(men[1]*(100-inflation[1])/2000 + 0.5)
if numPlayers == 2 then
D[1] = 100 * floor((men[1]*(100-inflation[1])/2000) * (1+(resources[1]-spending[1])/(resources[1]+1))+0.5)
end if
// men available
menAvail[0] = floor(men[0]*(1 + (P[0]-T[0])/(menAdded[0]+1)))
menAvail[1] = floor(men[1]*(1 + (P[1]-T[1])/(menAdded[1]+1)))
globals.F1 = 5/6 * men[0] // ?!?
print; print; print; print; print
print "P:" + P + "; T:" + T + "; menAdded:" + menAdded
print "men[0]:" + men[0] + " ...F1:" + F1
print "This is the battle of " + bat.name
if battleDesc then
for line in bat.description
print line
end for
end if
else
print bat.name + " Instant Replay"
end if
print
printInColumns " ", "CONFEDERACY", " UNION"
printInColumns "MEN", " "+menAvail[0], " "+menAvail[1]
printInColumns "MONEY", "$ "+D[0], "$ "+D[1]
printInColumns "INFLATION", " "+(inflation[0]+15)+" %", " " +inflation[1]+" %"
// (Note: printout lies and shows confederate inflation 15% higher than actual)
print
end function
getBudget = function(player)
print sides[player] + " General---How much do you wish to spend for"
getNum = function(prompt, allowNegative)
while true
n = input(prompt)
if not n then continue
if n[-1] == "k" then n = n[:-1] + "000" // (allow entries like "60k")
if n.val >= 0 or allowNegative then return n.val
print "Negative values are not allowed."
end while
end function
while true
f = getNum(" - Food......? ", true)
if f < 0 then
if resources[player] == 0 then
print "No previous entries."
print "How much do you wish to spend for"
continue
end if
break // keep all previous entries
end if
F[player] = f
H[player] = getNum(" - Salaries..? ", false)
B[player] = getNum(" - Ammunition? ", false)
if F[player] + H[player] + B[player] <= D[player] then break
print "Think again! You have only $" + D[player]
end while
end function
calcMorale = function(player)
m = ((2*F[player]^2 + H[player]^2) / F1^2 + 1)
print (" "*11 + sides[player])[-11:], " "
if m >= 10 then
print "morale is high"
else if m >= 5 then
print "morale is fair"
else
print "morale is poor"
end if
morale[player] = m
end function
getStrategy = function(player)
if numPlayers == 1 then prompt = "Your strategy" else prompt = sides[player] + " strategy"
while true
strat = input(prompt + "? ").val
if 0 < strat < 6 then break
print "Strategy " + strat + " not allowed."
end while
strategy[player] = strat
if strat == 5 then
print "The " + ["Confederacy", "Union"][player] + " has surrendered."
globals.gameOver = true
end if
end function
calcComputerStrategy = function
// Union strategy is computer chosen
print "Union strategy is ", ""
s0 = 0
r = 100 * rnd
for i in range(0, 3)
s0 += unionStrats[i]
if r < s0 then
strategy[1] = i+1
break
end if
end for
print strategy[1]
end function
learnStrategy = function
// Learn present strategy, start forgetting old ones.
// - Present strategy of south gains 3*s, others lose s
// probability points, unless a strategy falls below 5%.
s = 3; s0 = 0
for i in range(0,3)
if unionStrats[i] < 5 then continue
unionStrats[i] -= s
s0 += s
end for
unionStrats[strategy[1]-1] += s0
end function
doBattle = function
U = 0; U2 = 0
// simulated losses -- North
C6 = (2 * bat.casualties[1]/5) * (1+1/(2*(abs(strategy[1]-strategy[0])+1)))
C6 = C6 * (1.28 + (5*men[1]/6) / (B[1]+1))
C6 = floor(C6 * (1+1/morale[1]) + .5)
// - IF LOSS > MEN PRESENT, RESCALE LOSSES
E2 = 100/morale[1] // desertions (Union)
if floor(C6 + E2) >= menAvail[1] then
C6 = floor(13*menAvail[1]/20)
E2 = 7 * C6/13
U2=1 // Union loss
end if
// simulated losses -- South
C5 = (2 * bat.casualties[0]/5) * (1+1/(2*(abs(strategy[1]-strategy[0])+1)))
print "step A:" + C5
C5 = floor(C5 * (1+1/morale[0])*(1.28+F1/(B[0]+1))+.5)
print "step B:" + C5
print "based on morale[0]:"+morale[0]+", F1:"+F1+", B[0]:"+B[0]
E=100/morale[0]
if C5+100/morale[0] >= men[0]*(1+(P1-T1)/(menAdded[0]+1)) then
C5 = floor(13*men[0]/20 * (1+(P1-T1)/(menAdded[0]+1)))
print "step C:" + C5
print "men: " + men; print "menAdded: " + menAdded; print "P1,T1:" + P1 + "," + T1
E=7*C5/13 // desertions (Confed)
U=1 // Confederate loss
end if
print
print; print; printInColumns "", "CONFEDERACY", "UNION"
if numPlayers == 1 then
C6 = floor(17 * bat.casualties[1] * bat.casualties[0] / (C5*20))
E2 = 5 * morale[0]
end if
printInColumns "CASUALTIES", C5, C6
printInColumns "DESERTIONS", floor(E), floor(E2)
print
if numPlayers == 2 then
print "Compared to the actual casualties at " + bat.name
print "Confederate: " + round(100*C5/bat.casualties[0]) + "% of the original"
print "Union: " + round(100*C6/bat.casualties[1]) + "% of the original"
print
// Who won?
print "U:"+U+ " U2:"+U2
if (U == 1 and U2 != 1) or (U == U2 and C5+E > C6+E2) then
print "The Union wins " + bat.name
globals.losses += 1
else if (U2 == 1 and U != 1) or (U == U2 and C5+E < C6+E2) then
print "The confederacy wins " + bat.name
globals.wins += 1
else
print "Battle outcome unresolved"
globals.unresolved += 1
end if
else
print "Your casualties were " + round(100*C5/bat.casualties[0]) + "% of"
print "the actual casualties at " + bat.name
print
if U == 1 or C5+E >= 17*bat.casualties[1]*bat.casualties[0]/(C5*20)+5*morale[0] then
print "You lose " + bat.name
if not replay then globals.losses += 1
else
print "You win " + bat.name
if not replay then globals.wins += 1
end if
end if
if not replay then
// Cumulative battle factors which alter historical
// resources availeble. (If a replay, don't update.)
T[0] += C5 + E
T[1] += C6 + E2
P[0] += bat.casualties[0]
P[1] += bat.casualties[1]
spending[0] += F[0] + H[0] + B[0]
spending[1] += F[1] + H[1] + B[1]
resources[0] += men[0]*(100-inflation[0])/20
resources[1] += men[1]*(100-inflation[1])/20
menAdded[0] += men[0]
menAdded[1] += men[1]
learnStrategy
end if
print "---------------"
end function
// Main Program
loadData
unionStrats = [25, 25, 25, 25]
P1=0; P2=0; T1=0; T2=0 // cumulative stat thingies
print
if getYesNo("Do you want instructions") == "YES" then instructions
setup
gameOver = false
while not gameOver
pickBattle
if gameOver then break
for i in range(0, numPlayers-1)
getBudget i
end for
for i in range(0, numPlayers-1)
calcMorale i
end for
print "Confederate General---", ""
if bat.offDef == 3 then
print "you are on the offensive"
else if bat.offDef == 1 then
print "you are on the defensive"
else
print "both sides are on the offensive "
end if
print
getStrategy 0
if numPlayers == 2 then getStrategy 1 else calcComputerStrategy
if gameOver then break
doBattle
end while
// Finish off
print; print; print; print; print; print
print "The Confederacy has won " + wins + " battles and lost " + losses
if strategy[0] == 5 or (strategy[1] != 5 and losses > wins) then
print "The Union has won the war"
else
print "The Confederacy has won the war"
end if
print "For the " + (wins + losses + unresolved) + " battles fought (excluding reruns)"
print
printInColumns "", "Confederacy", "Union"
printInColumns "Historical Losses", round(P[0]), round(P[1])
printInColumns "Simulated Losses", round(T[0]), round(T[1])
print
printInColumns " % of Original", round(100*T[0]/P[0]), round(100*T[1]/P[1])
if numPlayers == 1 then
print
print "Union intelligence suggsets that the South used "
print "strategies 1, 2, 3, 4 in the following percentages"
print unionStrats.join
end if
@@ -0,0 +1,16 @@
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 combat.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "combat"
run
@@ -0,0 +1,165 @@
print " "*33 + "Combat"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print; print
printInColumns2 = function(a, b, lineBreak=true)
print (a+" "*16)[:16] + (b+" "*16)[:16], ""
if lineBreak then print
end function
printInColumns3 = function(a, b, c, lineBreak=true)
print (a+" "*16)[:16] + (b+" "*16)[:16] + (c+" "*16)[:16], ""
if lineBreak then print
end function
// computer forces:
d = 30000 // army
e = 20000 // navy
f = 22000 // air force
print "I am at war with you."; print "We have 72000 soldiers apiece."
while true
print; print "Distribute your forces."
printInColumns3 "", "ME", "YOU"
printInColumns2 "army", d, false
a = input("?").val
printInColumns2 "navy", e, false
b = input("?").val
printInColumns2 "a. f.", f, false
c = input("?").val
if a+b+c <= 72000 then break
end while
print "You attack first. Type (1) for army; (2) for navy;"
print "and (3) for air force."
y = input.val
while true
x = input("How many men? ").val
if x < 0 then continue
if y <= 1 or y > 3 then
// Army attack
if x > a then continue
if x < a/3 then
print "You lost "+x+" men from your army."
a=floor(a-x)
else if x < 2*a/3 then
print "You lost " + floor(x/3) + " men, but I lost " + floor(2*d/3)
a=floor(a-x/3)
d=0 // (message above lied!)
else
print "You sunk one of my patrol boats, but I wiped out two"
print "of your air force bases and 3 army bases."
a=floor(a/3)
c=floor(c/3)
e=floor(2*e/3)
end if
else if y == 2 then
// Naval attack
if x > b then continue
if x < e/3 then
print "Your attack was stopped!"
b = floor(b-x)
else if x < 2*e/3 then
print "You destroyed " + floor(2*e/3) + "of my army."
e=floor(e/3)
else
print "You sunk one of my patrol boats, but I wiped out two"
print "of your air force bases and 3 army bases."
a=floor(a/3)
c=floor(c/3)
e=floor(2*e/3)
end if
else
// Air force attack
if x > c then continue
if x < c/3 then
print "Your attack was wiped out."
c = floor(c-x)
else if x < 2*c/3 then
print "We had a dogfight. You won - and finished your mission."
d=floor(2*d/3)
e=floor(e/3)
f=floor(f/3)
else
print "You wiped out one of my army patrols, but I destroyed"
print "two navy bases and bombed three army bases."
a=floor(a/4)
b=floor(b/3)
d=floor(2*d/3)
end if
end if
break
end while
result = null // 1 you win, -1 you lose, 0 tie (treaty)
print
printInColumns3 "", "YOU", "ME"
printInColumns3 "army", a, d
printInColumns3 "navy", b, e
printInColumns3 "a. f.", c, f
print "What is your next move?"
print "army=1 navy=2 air force=3"
g = input.val
while true
t = input("How many men? ").val
if t < 0 then continue
if g <= 1 or g > 3 then
// Army attack
if t > a then continue
if t < d/2 then
print "I wiped out your attack!"
a = a-t
else
print "You destroyed my army!"
d=0
end if
else if g == 2 then
// Naval attack
if t > b then continue
if t < e/2 then
print "I sunk two of your battleships, and my air force"
print "wiped out your ungaurded capitol." // (sic)
a = a/4
b = b/2
else
print "Your navy shot down three of my xiii planes,"
print "and sunk three battleships."
f = 2*f/3
e = (e/2)
end if
else
// Air Force attack
if t > c then continue
if t > f/2 then
print "My navy and air force in a combined attack left"
print "your country in shambles."
a = a/3
b = b/3
c = c/3
else
print "One of your planes crashed into my house. I am dead."
print "My country fell apart."
result = 1
end if
end if
break
end while
if result == null then
print
print "From the results of both of your attacks,"
result = 0
if a+b+c > 3/2*(d+e+f) then result = 1
if a+b+c < 2/3*(d+e+f) then result = -1
end if
if result == 0 then
print "the treaty of paris concluded that we take our"
print "respective countries and live in peace."
else if result == 1 then
print "You won, oh! shucks!!!!"
else
print "You lost-I conquered your country. It serves you"
print "right for playing this stupid game!!!"
end if
@@ -0,0 +1,16 @@
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 cube.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "cube"
run
@@ -0,0 +1,100 @@
print " "*34 + "Bullseye"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print; print
if input("Do you want to see the instructions? (yes--1,no--0) ").val then
print "This is a game in which you will be playing against the"
print "random decision of the computer. The field of play is a"
print "cube of size 3. Any of the locations can be designated"
print "by inputing three numbers such as 2,3,1. At the start,"
print "you are automatically at location 1,1,1. The object of"
print "the game is to get to location 3,3,3. One minor detail:"
print "the computer will pick, at random, locations at which"
print "it will plant land mines. If you hit one of these locations"
print "you lose. One other detail: you may move only one space "
print "in one direction each move. For example: from 1,1,2 you"
print "may move to 2,1,2 or 1,1,3. You may not change"
print "two of the numbers on the same move. If you make an illegal"
print "move, you lose and the computer takes the money you may"
print "have bet on that round."
print
print
print "All yes or no questions will be answered by a 1 for yes"
print "or a 0 (zero) for no."
print
print "When stating the amount of a wager, print only the number"
print "of dollars (example: 250). You are automatically started with"
print "500 dollars in your account."
print
print "Good luck!"
end if
money = 500
while money >= 0
mineLocs = []
// Note: unlike the original BASIC program, which doesn't actually pick random
// numbers unless you manually set X to a positive value before running the
// program, we do pick five random mine locations here.
// But like that program, we make no attempt to avoid 1,1,1 or 3,3,3, or to
// ensure that we have picked five DIFFERENT locations.
for i in range(1,5)
mineLocs.push [floor(3 * rnd + 1), floor(3 * rnd + 1), floor(3 * rnd + 1)]
end for
wager = 0
if input("Want to make a wager? ").val then
wager = input("How much? ").val
while money < wager
wager = input("Tried to fool me; bet again? ").val
end while
end if
position = [1,1,1]
print
inp = input("It's your move: ")
won = 0
while true
inp = inp.replace(",", " ").replace(" ", " ").split
newPos = []
if inp.len == 3 then newPos = [inp[0].val, inp[1].val, inp[2].val]
legal = newPos.len == 3
totalChange = 0
for i in newPos.indexes
// The original game allowed you to walk outside the 1-3 range,
// thus safely avoiding all the mines. To disallow this exploit,
// uncomment the following line.
//if newPos[i] < 1 or newPos[i] > 3 then legal = false
totalChange += abs(newPos[i] - position[i])
end for
if totalChange > 1 then legal = false
if not legal then
print; print "Illegal move. You lose."
won = -wager
break
end if
if newPos == [3,3,3] then
print "Congratulations!"
won = wager
break
else if mineLocs.indexOf(newPos) != null then
print "******BANG******"
print "You lose!"
print
print
won = -wager
break
end if
position = newPos
inp = input("Next move: ")
end while
if won != 0 then
globals.money += won
if money <= 0 then print "You bust."
end if
if wager then
print " You now have " + money + " dollars."
end if
if not input("Do you want to try again? ").val then break
end while
print "Tough luck!"
print
print "Goodbye."
@@ -0,0 +1,16 @@
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 digits.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "digits"
run
@@ -0,0 +1,99 @@
import "listUtil"
print " "*33 + "Digits"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print; print
printInColumns = function(a, b, c, d)
print (a+" "*16)[:16] + (b+" "*16)[:16] + (c+" "*16)[:16] + (d+" "*16)[:16]
end function
print "This is a game of guessing."
print "For instructions, type '1', else type '0'"
if input != "0" then
print
print "Please take a piece of paper and write down"
print "the digits '0', '1', or '2' thirty times at random."
print "Arrange them in three lines of ten digits each."
print "I will ask for then ten at a time."
print "I will always guess them first and then look at your"
print "next number to see if i was right. By pure luck,"
print "I ought to be right ten times. But i hope to do better"
print "than that *****"
print; print
end if
a = 0; b = 1; c = 3
while true
m = list.init2d(27, 3, 1)
k = list.init2d(3, 3, 9)
l = list.init2d(9, 3, 3)
l[0][0] = 2; l[4][1] = 2; l[8][2] = 2
z=26; z1=8; z2=2
qtyRight = 0
guess = 0
for t in range(1,3)
while true
print
print "Ten numbers, please";
n = input.replace(",", " ").replace(" ", "").split
if n.len != 10 then continue
valid = true
for i in n.indexes
n[i] = n[i].val
if n[i] < 0 or n[i] > 2 then
print "Only use the digits '0', '1', or '2'."
print "Let's try again."
valid = false
break
end if
end for
if valid then break
end while
print; printInColumns "My guess","Your no.","Result","No. right"; print
for u in range(0, 9)
yourNum = n[u]; s=0
for j in range(0,2)
s1 = a*k[z2][j] + b*l[z1][j] + c*m[z][j]
if s > s1 then continue
if s < s1 or rnd >= 0.5 then
s = s1; guess = j
end if
end for
if guess == yourNum then
outcome = " right"
qtyRight += 1
else
outcome = " wrong"
end if
printInColumns " "+guess, " " + yourNum, outcome, qtyRight
m[z][yourNum] += 1
l[z1][yourNum] += 1
k[z2][yourNum] += 1
z -= floor(z/9)*9
z = 3*z + yourNum
z1 = z - floor(z/9)*9
z2 = yourNum
end for
end for
print
if qtyRight > 10 then
print "I guessed more than 1/3 of your numbers."
print "I win."
print char(7) * 10
else if qtyRight < 10 then
print "I guessed less than 1/3 of your numbers."
print "You beat me. Congratulations *****"
else
print "I guessed exactly 1/3 of your numbers."
print "It's a tie game."
end if
print "Do you want to try again (1 for yes, 0 for no)";
if input != "1" then break
end while
print; print "Thanks for the game."
@@ -0,0 +1,28 @@
Original source downloaded from [Vintage Basic](http://www.vintage-basic.net/games.html).
Conversion to [MiniScript](https://miniscript.org).
Note that this folder (like the original BASIC programs) contains TWO different programs based on the same idea. evenwins.ms plays deterministically; gameofevenwins.ms learns from its failures over multiple games.
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 evenwins.ms
or
miniscript gameofevenwins.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "evenwins"
run
or
load "gameofevenwins"
run
@@ -0,0 +1,140 @@
print " "*31 + "Digits"
print " "*15 + "Creative Computing Morristown, New Jersey"
print; print
y1 = 0
m1 = 0
print " This is a two person game called 'Even Wins.'"
print "To play the game, the players need 27 marbles or"
print "other objects on a table."
print
print
print " The 2 players alternate turns, with each player"
print "removing from 1 to 4 marbles on each move. The game"
print "ends when there are no marbles left, and the winner"
print "is the one with an even number of marbles."
print
print
print " The only rules are that (1) you must alternate turns,"
print "(2) you must take between 1 and 4 marbles each turn,"
print "and (3) you cannot skip a turn."
print
print
print
while true
print " Type a '1' if you want to go first, and type"
print "a '0' if you want me to go first."
c = input.val
print
if c != 0 then
t = 27
print
print
print
print "Total=" + t
print
print
print "What is your first move?"
m = 0
else
t = 27
m = 2
print
print "Total= " + t
print
m1 += m
t -= m
end if
while true
if m then
print "I pick up " + m + " marbles."
if t == 0 then break
print
print "Total=" + t
print
print " And what is your next move, my total is " + m1
end if
while true
y = input.val
print
if y < 1 or y > 4 then
print
print "The number of marbles you must take be a positive"
print "integer between 1 and 4."
print
print " What is your next move?"
print
else if y > t then
print " You have tried to take more marbles than there are"
print "left. Try again."
else
break
end if
end while
y1 += y
t -= y
if t == 0 then break
print "Total=" + t
print
print "Your total is " + y1
if t < 0.5 then break
r = t % 6
if y1 % 2 != 0 then
if t >= 4.2 then
if r <= 3.4 then
m = r + 1
m1 += m
t -= m
else if r < 4.7 or r > 3.5 then
m = 4
m1 += m
t -= m
else
m = 1
m1 += m
t -= m
end if
else
m = t
t -= m
print "I pick up " + m + " marbles."
print
print "Total = 0"
m1 += m
break
end if
else
if r < 1.5 or r > 5.3 then
m = 1
m1 += m
t -= m
else
m = r - 1
m1 += m
t -= m
if t < 0.2 then
print "I pick up " + m + " marbles."
print
break
end if
end if
end if
end while
print "That is all of the marbles."
print
print " My total is " + m1 + ", your total is " + y1
print
if m1 % 2 then
print " You won. Do you want to play"
else
print " I won. Do you want to play"
end if
print "again? Type 1 for yes and 0 for no."
a1 = input.val
if a1 == 0 then break
m1 = 0
y1 = 0
end while
print
print "OK. See you later"
@@ -0,0 +1,90 @@
print " "*28 + "Game Of Even Wins"
print " "*15 + "Creative Computing Morristown, New Jersey"
print
print
yesNo = input("Do you want instructions (yes or no)? ").lower
if not yesNo or yesNo[0] != "n" then
print "The game is played as follows:"
print
print "At the beginning of the game, a random number of chips are"
print "placed on the board. The number of chips always starts"
print "as an odd number. On each turn, a player must take one,"
print "two, three, or four chips. The winner is the player who"
print "finishes with a total number of chips that is even."
print "The computer starts out knowing only the rules of the"
print "game. It gradually learns to play well. It should be"
print "difficult to beat the computer after twenty games in a row."
print "Try it!!!!"
print
print "To quit at any time, type a '0' as your move."
print
end if
l = 0
b = 0
r = [[4]*6, [4]*6]
while true
a = 0
b = 0
e = 0
l = 0
p = floor((13 * rnd + 9) / 2) * 2 + 1;
while true
if p == 1 then
print "There is 1 chip on the board."
else
print "There are " + p + " chips on the board."
end if
e1 = e
l1 = l
e = a % 2
l = p % 6
if r[e][l] < p then
m = r[e][l]
if m <= 0 then
m = 1
b = 1
break
end if
p -= m
if m == 1 then
prompt = "Computer takes 1 chip leaving " + p + "... Your move? "
else
prompt = "Computer takes " + m + " chips leaving " + p + "... Your move? "
end if
b += m
while true
m = input(prompt).val
if m == 0 then break
if 1 <= m <= p and m <= 4 then break
prompt = m + " is an illegal move ... Your move? "
end while
if m == 0 then break
if m == p then break // <-- Really? Before we've done the math?
p -= m
a += m
else
if p == 1 then
print "Computer takes 1 chip."
else
print "Computer takes " + p + " chips."
end if
r[e][l] = p
b += p
break
end if
end while
if m == 0 then break
if b % 2 != 0 then
print "Game over ... you win!!!"
if r[e][l] != 1 then
r[e][l] -= 1
else if (r[e1][l1] != 1) then
r[e1][l1] -= 1
end if
else
print "Game over ... I win!!!"
end if
print
end while
@@ -0,0 +1,16 @@
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 flipflop.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 BASIC program. Then, at the Mini Micro command prompt, enter:
load "flipflop"
run
@@ -0,0 +1,97 @@
print " "*32 + "FlipFlop"
print " "*15 + "Creative Computing Morristown, New Jersey"
print
// Created by Michael Cass (1978)
// Ported to MiniScript by Joe Strout (2023)
print "The object of this puzzle is to change this:"
print
print "X X X X X X X X X X"
print
print "to this:"
print
print "O O O O O O O O O O"
print
print "By typing the number corresponding to the position of the"
print "letter on some numbers, one position will change, on"
print "others, two will change. To reset line to all X's, type 0"
print "(zero) and to start over in the middle of a game, type "
print "11 (eleven)."
print
startNewGame = function
globals.q = rnd
globals.guesses = 0
print "Here is the starting line of X's."
print
print "1 2 3 4 5 6 7 8 9 10"
print "X X X X X X X X X X"
print
end function
getInput = function
while true
n = input("Input the number: ").val
if n == floor(n) and 0 <= n <= 11 then break
print "Illegal entry--try again."
end while
return n
end function
startNewGame
while true
A = [""] + ["X"] * 10 // (include empty 0th element so we can index 1-based
m = 0 // (previous input)
while true
n = getInput
if n == 11 then
startNewGame
continue
else if n == 0 then
A = ["X"] * 10
continue
end if
if n != m then
// when user enters a different number from previous time
m = n
if A[n] == "O" then A[n] = "X" else A[n] = "O"
while m == n
r = tan(q + n/q - n) - sin(q/n) + 336*sin(8*n)
n = floor(10 * (r - floor(r)))
if A[n] != "O" then
A[n] = "O"
break
end if
A[n] = "X"
end while
else
// when n == m, i.e., user entered the same number twice in a row
while m == n
if A[n] == "O" then A[n] = "X" else A[n] = "O"
r = 0.592 * (1 / tan(q/n + q)) / sin(n*2 + q) - cos(n)
n = floor(10 * (r - floor(r)))
if A[n] != "O" then
A[n] = "O"
break
end if
A[n] = "X"
end while
end if
print "1 2 3 4 5 6 7 8 9 10"
print A[1:].join
guesses += 1
if A[1:] == ["O"]*10 then break
end while
if guesses <= 12 then
print "Very good. You guessed it in only " + guesses + " guesses."
else
print "Try harder next time. It took you " + guesses + " guesses."
end if
yesNo = input("Do you want to try another puzzle? ").lower
if not yesNo or yesNo[0] == "n" then break
print
end while
+2 -1
View File
@@ -24,5 +24,6 @@ should be more readable.
- If the computer moves a checker to the bottom row, it promotes, but
leaves the original checker in place. (See line 1240)
- Human players may move non-kings as if they were kings. (See lines 1590 to 1810)
- Human players are not required to jump if it is possible.
- Human players are not required to jump if it is possible, and may make a number
other illegal moves (jumping their own pieces, jumping empty squares, etc.).
- Curious writing to "I" variable without ever reading it. (See lines 1700 and 1806)
+4 -2
View File
@@ -13,11 +13,13 @@ As published in Basic Computer Games (1978):
Downloaded from Vintage Basic at
http://www.vintage-basic.net/games.html
#### Known Bugs
- There is a typo in the original Basic, "...DECIDE **WHO** MUCH WATER..." should be "DECIDE **HOW** MUCH WATER"
#### Porting Notes
(please note any difficulties or challenges in porting here)
There is a type in the original Basic, "...DECIDE **WHO** MUCH WATER..." should be "DECIDE **HOW** MUCH WATER"
#### External Links
- C: https://github.com/ericfischer/basic-computer-games/blob/main/24%20Chemist/c/chemist.c
+4
View File
@@ -17,6 +17,10 @@ As published in Basic Computer Games (1978):
Downloaded from Vintage Basic at
http://www.vintage-basic.net/games.html
#### Known Bugs
- At the end of a single-player game, the program reports strategies used by "THE SOUTH", but these are in fact strategies used by the North (the computer player) -- the South is always a human player.
#### Porting Notes
(please note any difficulties or challenges in porting here)
+5
View File
@@ -15,6 +15,11 @@ As published in Basic Computer Games (1978):
Downloaded from Vintage Basic at
http://www.vintage-basic.net/games.html
#### Known Bugs
- The original game misspells "unguarded" on line 1751.
- In an initial army attack, the program claims that the computer loses 2/3 of its army, but it actually loses its entire army (lines 150-155).
#### Porting Notes
(please note any difficulties or challenges in porting here)
+8
View File
@@ -17,6 +17,14 @@ http://www.vintage-basic.net/games.html
(please note any difficulties or challenges in porting here)
##### Known Bugs
This program does very little validation of its input, enabling the user to cheat in two ways:
- One can enter a large negative wager, purposely lose, and gain that much money.
- One can move outside the cube (using coordinates 0 or 4), then safely walk "around" the standard play volume to the destination square.
It's remotely possible that these are clever solutions the user is intended to find, solving an otherwise purely random game.
##### Randomization Logic
The BASIC code uses an interesting technique for choosing the random coordinates for the mines. The first coordinate is
+2 -1
View File
@@ -18,4 +18,5 @@ http://www.vintage-basic.net/games.html
#### Porting Notes
(please note any difficulties or challenges in porting here)
- The program contains a lot of mysterious and seemingly arbitrary constants. It's not clear there is any logic or rationality behind it.
- The key equation involved in the guess (line 700) involves a factor of `A`, but `A` is always 0, making that term meaningless. As a result, all the work to build and update array K and value Z2 appear to be meaningless, too.