mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-13 00:00:25 -08:00
Added MiniScript versions of 35_Even_Wins.
This commit is contained in:
28
00_Alternate_Languages/35_Even_Wins/MiniScript/README.md
Normal file
28
00_Alternate_Languages/35_Even_Wins/MiniScript/README.md
Normal file
@@ -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
|
||||||
140
00_Alternate_Languages/35_Even_Wins/MiniScript/evenwins.ms
Normal file
140
00_Alternate_Languages/35_Even_Wins/MiniScript/evenwins.ms
Normal file
@@ -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
|
||||||
Reference in New Issue
Block a user