Removed spaces from top-level directory names.

Spaces tend to cause annoyances in a Unix-style shell environment.
This change fixes that.
This commit is contained in:
Chris Reuter
2021-11-21 18:30:21 -05:00
parent df2e7426eb
commit d26dbf036a
1725 changed files with 0 additions and 0 deletions

7
80_Slots/README.md Normal file
View File

@@ -0,0 +1,7 @@
### Slots
As published in Basic Computer Games (1978)
https://www.atariarchives.org/basicgames/showpage.php?page=149
Downloaded from Vintage Basic at
http://www.vintage-basic.net/games.html

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Microsoft C#](https://docs.microsoft.com/en-us/dotnet/csharp/)

3
80_Slots/java/README.md Normal file
View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Oracle Java](https://openjdk.java.net/)

View File

@@ -0,0 +1,297 @@
import java.util.Arrays;
import java.util.Scanner;
/**
* Game of Slots
* <p>
* Based on the Basic game of Slots here
* https://github.com/coding-horror/basic-computer-games/blob/main/80%20Slots/slots.bas
* <p>
* Note: The idea was to create a version of the 1970's Basic game in Java, without introducing
* new features - no additional text, error checking, etc has been added.
*/
public class Slots {
public static final String[] SLOT_SYMBOLS = {"BAR", "BELL", "ORANGE", "LEMON", "PLUM", "CHERRY"};
public static final int NUMBER_SYMBOLS = SLOT_SYMBOLS.length;
// Jackpot symbol (BAR)
public static final int BAR_SYMBOL = 0;
// Indicator that the current spin won nothing
public static final int NO_WINNER = -1;
// Used for keyboard input
private final Scanner kbScanner;
private enum GAME_STATE {
START_GAME,
ONE_SPIN,
RESULTS,
GAME_OVER
}
// Current game state
private GAME_STATE gameState;
// Different types of spin results
private enum WINNINGS {
JACKPOT(100),
TOP_DOLLAR(10),
DOUBLE_BAR(5),
REGULAR(2),
NO_WIN(0);
private final int multiplier;
WINNINGS(int mult) {
multiplier = mult;
}
// No win returns the negative amount of net
// otherwise calculate winnings based on
// multiplier
public int calculateWinnings(int bet) {
if (multiplier == 0) {
return -bet;
} else {
// Return original bet plus a multipler
// of the win type
return (multiplier * bet) + bet;
}
}
}
private int playerBalance;
public Slots() {
kbScanner = new Scanner(System.in);
gameState = GAME_STATE.START_GAME;
}
/**
* Main game loop
*/
public void play() {
int[] slotReel = new int[3];
do {
// Results of a single spin
WINNINGS winnings;
switch (gameState) {
case START_GAME:
intro();
playerBalance = 0;
gameState = GAME_STATE.ONE_SPIN;
break;
case ONE_SPIN:
int playerBet = displayTextAndGetNumber("YOUR BET? ");
slotReel[0] = randomSymbol();
slotReel[1] = randomSymbol();
slotReel[2] = randomSymbol();
// Store which symbol (if any) matches at least one other reel
int whichSymbolWon = winningSymbol(slotReel[0], slotReel[1], slotReel[2]);
// Display the three randomly drawn symbols
StringBuilder output = new StringBuilder();
for (int i = 0; i < 3; i++) {
if (i > 0) {
output.append(" ");
}
output.append(SLOT_SYMBOLS[slotReel[i]]);
}
System.out.println(output);
// Calculate results
if (whichSymbolWon == NO_WINNER) {
// No symbols match = nothing won
winnings = WINNINGS.NO_WIN;
} else if (slotReel[0] == slotReel[1] && slotReel[0] == slotReel[2]) {
// Top dollar, 3 matching symbols
winnings = WINNINGS.TOP_DOLLAR;
if (slotReel[0] == BAR_SYMBOL) {
// All 3 symbols are BAR. Jackpot!
winnings = WINNINGS.JACKPOT;
}
} else {
// At this point the remaining options are a regular win
// or a double, since the rest (including not winning) have already
// been checked above.
// Assume a regular win
winnings = WINNINGS.REGULAR;
// But if it was the BAR symbol that matched, its a double bar
if (slotReel[0] == BAR_SYMBOL) {
winnings = WINNINGS.DOUBLE_BAR;
}
}
// Update the players balance with the amount won or lost on this spin
playerBalance += winnings.calculateWinnings(playerBet);
System.out.println();
// Output what happened on this spin
switch (winnings) {
case NO_WIN:
System.out.println("YOU LOST.");
break;
case REGULAR:
System.out.println("DOUBLE!!");
System.out.println("YOU WON!");
break;
case DOUBLE_BAR:
System.out.println("*DOUBLE BAR*");
System.out.println("YOU WON!");
break;
case TOP_DOLLAR:
System.out.println();
System.out.println("**TOP DOLLAR**");
System.out.println("YOU WON!");
break;
case JACKPOT:
System.out.println();
System.out.println("***JACKPOT***");
System.out.println("YOU WON!");
break;
}
System.out.println("YOUR STANDINGS ARE $" + playerBalance);
// If player does not elect to play again, show results of session
if (!yesEntered(displayTextAndGetInput("AGAIN? "))) {
gameState = GAME_STATE.RESULTS;
}
break;
case RESULTS:
if (playerBalance == 0) {
System.out.println("HEY, YOU BROKE EVEN.");
} else if (playerBalance > 0) {
System.out.println("COLLECT YOUR WINNINGS FROM THE H&M CASHIER.");
} else {
// Lost
System.out.println("PAY UP! PLEASE LEAVE YOUR MONEY ON THE TERMINAL.");
}
gameState = GAME_STATE.GAME_OVER;
break;
}
} while (gameState != GAME_STATE.GAME_OVER);
}
private void intro() {
System.out.println(simulateTabs(30) + "SLOTS");
System.out.println(simulateTabs(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println();
System.out.println("YOU ARE IN THE H&M CASINO,IN FRONT OF ONE OF OUR");
System.out.println("ONE-ARM BANDITS. BET FROM $1 TO $100.");
System.out.println("TO PULL THE ARM, PUNCH THE RETURN KEY AFTER MAKING YOUR BET.");
}
/*
* Print a message on the screen, then accept input from Keyboard.
* Converts input to an Integer
*
* @param text message to be displayed on screen.
* @return what was typed by the player.
*/
private int displayTextAndGetNumber(String text) {
return Integer.parseInt(displayTextAndGetInput(text));
}
/*
* Print a message on the screen, then accept input from Keyboard.
*
* @param text message to be displayed on screen.
* @return what was typed by the player.
*/
private String displayTextAndGetInput(String text) {
System.out.print(text);
return kbScanner.next();
}
/**
* Checks whether player entered Y or YES to a question.
*
* @param text player string from kb
* @return true of Y or YES was entered, otherwise false
*/
private boolean yesEntered(String text) {
return stringIsAnyValue(text, "Y", "YES");
}
/**
* Check whether a string equals one of a variable number of values
* Useful to check for Y or YES for example
* Comparison is case insensitive.
*
* @param text source string
* @param values a range of values to compare against the source string
* @return true if a comparison was found in one of the variable number of strings passed
*/
private boolean stringIsAnyValue(String text, String... values) {
return Arrays.stream(values).anyMatch(str -> str.equalsIgnoreCase(text));
}
/**
* Simulate the old basic tab(xx) command which indented text by xx spaces.
*
* @param spaces number of spaces required
* @return String with number of spaces
*/
private String simulateTabs(int spaces) {
char[] spacesTemp = new char[spaces];
Arrays.fill(spacesTemp, ' ');
return new String(spacesTemp);
}
/**
* Find the symbol that won this round i.e. the first reel that matched another reel
*
* @param reel1 reel1 spin result
* @param reel2 reel2 spin result
* @param reel3 reel3 spin result
* @return NO_WINNER if no reels match otherwise an int 0-2 to indicate the reel that matches another
*/
private int winningSymbol(int reel1, int reel2, int reel3) {
if (reel1 == reel2) {
return 0;
} else if (reel1 == reel3) {
return 0;
} else if (reel2 == reel3) {
return 1;
} else {
return NO_WINNER;
}
}
/**
* Random symbol for a slot wheel
*
* @return number between 0-5
*/
private int randomSymbol() {
return (int) (Math.random() * NUMBER_SYMBOLS);
}
}

View File

@@ -0,0 +1,6 @@
public class SlotsGame {
public static void main(String[] args) {
Slots slots = new Slots();
slots.play();
}
}

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [JavaScript](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Shells)

View File

@@ -0,0 +1,9 @@
<html>
<head>
<title>SLOTS</title>
</head>
<body>
<pre id="output" style="font-size: 12pt;"></pre>
<script src="slots.js"></script>
</body>
</html>

View File

@@ -0,0 +1,135 @@
// SLOTS
//
// Converted from BASIC to Javascript by Oscar Toledo G. (nanochess)
//
function print(str)
{
document.getElementById("output").appendChild(document.createTextNode(str));
}
function input()
{
var input_element;
var input_str;
return new Promise(function (resolve) {
input_element = document.createElement("INPUT");
print("? ");
input_element.setAttribute("type", "text");
input_element.setAttribute("length", "50");
document.getElementById("output").appendChild(input_element);
input_element.focus();
input_str = undefined;
input_element.addEventListener("keydown", function (event) {
if (event.keyCode == 13) {
input_str = input_element.value;
document.getElementById("output").removeChild(input_element);
print(input_str);
print("\n");
resolve(input_str);
}
});
});
}
function tab(space)
{
var str = "";
while (space-- > 0)
str += " ";
return str;
}
var figures = [, "BAR", "BELL", "ORANGE", "LEMON", "PLUM", "CHERRY"];
// Main program
async function main()
{
print(tab(30) + "SLOTS\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
print("\n");
print("\n");
print("\n");
// Produced by Fred Mirabelle and Bob Harper on Jan 29, 1973
// It simulates the slot machine.
print("YOU ARE IN THE H&M CASINO,IN FRONT ON ONE OF OUR\n");
print("ONE-ARM BANDITS. BET FROM $1 TO $100.\n");
print("TO PULL THE ARM, PUNCH THE RETURN KEY AFTER MAKING YOUR BET.\n");
p = 0;
while (1) {
while (1) {
print("\n");
print("YOUR BET");
m = parseInt(await input());
if (m > 100) {
print("HOUSE LIMITS ARE $100\n");
} else if (m < 1) {
print("MINIMUM BET IS $1\n");
} else {
break;
}
}
// Not implemented: GOSUB 1270 ten chimes
print("\n");
x = Math.floor(6 * Math.random() + 1);
y = Math.floor(6 * Math.random() + 1);
z = Math.floor(6 * Math.random() + 1);
print("\n");
// Not implemented: GOSUB 1310 seven chimes after figure x and y
print(figures[x] + " " + figures[y] + " " + figures[z] + "\n");
lost = false;
if (x == y && y == z) { // Three figure
print("\n");
if (z != 1) {
print("**TOP DOLLAR**\n");
p += ((10 * m) + m);
} else {
print("***JACKPOT***\n");
p += ((100 * m) + m);
}
print("YOU WON!\n");
} else if (x == y || y == z || x == z) {
if (x == y)
c = x;
else
c = z;
if (c == 1) {
print("\n");
print("*DOUBLE BAR*\n");
print("YOU WON\n");
p += ((5 * m) + m);
} else if (x != z) {
print("\n");
print("DOUBLE!!\n");
print("YOU WON!\n");
p += ((2 * m) + m);
} else {
lost = true;
}
} else {
lost = true;
}
if (lost) {
print("\n");
print("YOU LOST.\n");
p -= m;
}
print("YOUR STANDINGS ARE $" + p + "\n");
print("AGAIN");
str = await input();
if (str.substr(0, 1) != "Y")
break;
}
print("\n");
if (p < 0) {
print("PAY UP! PLEASE LEAVE YOUR MONEY ON THE TERMINAL.\n");
} else if (p == 0) {
print("HEY, YOU BROKE EVEN.\n");
} else {
print("COLLECT YOUR WINNINGS FROM THE H&M CASHIER.\n");
}
}
main();

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Pascal](https://en.wikipedia.org/wiki/Pascal_(programming_language))

3
80_Slots/perl/README.md Normal file
View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Perl](https://www.perl.org/)

View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Python](https://www.python.org/about/)

159
80_Slots/python/slots.py Normal file
View File

@@ -0,0 +1,159 @@
########################################################
#
# Slots
#
# From Basic Computer Games (1978)
#
# "The slot machine or one-arm bandit is a mechanical
# device that will absorb coins just about as fast as
# you can feed it. After inserting a coin, you pull a
# handle that sets three indepent reels spining. If the
# reels stop with certain symbols appearing in the pay
# line, you get a certain payoff. The original slot
# machine, called the Liberty bell, was invented in 1895
# by Charles Fey in San Francisco. Fey refused to sell
# or lease the manufacturing rights, so H.S. Mills in
# Chicago built a similar, but much improved, machine
# called the Operators Bell. This has survived nearly
# unchanged to today.
# On the operators Bell and other standard slot
# machines, there are 20 symbols on each wheel but they
# are not distributed evenly among the objects(cherries,
# bar, apples, etc). Of the 8000 possible combinations,
# the expected payoff(to the player) is 7049 or $89.11
# for every $100.00 put in, one of the lowest expected
# payoffs of all casino games.
# In the program here, the payoff is considerably more
# liberal; indeed it appears to favor the player by 11%
# -- i.e., an expected payoff of $111 for each $100 bet."
# The program was originally written by Fred Mirabelle
# and Bob Harper
#
########################################################
from random import choices
from collections import Counter
import sys
def initial_message():
print(" "*30 + "Slots")
print(" "*15 + "Creative Computing Morrison, New Jersey")
print("\n"*3)
print("You are in the H&M Casino, in front of one of our")
print("one-arm Bandits. Bet from $1 to $100.")
print("To pull the arm, punch the return key after making your bet.")
def input_betting():
print("\n")
b = -1
while b < 1 or b > 100:
try:
b = int(input("Your bet:"))
except ValueError:
b = -1
if b > 100:
print("House limits are $100")
elif b < 1:
print("Minium bet is $1")
beeping()
return int(b)
def beeping():
# Function to produce a beep sound.
# In the original program is the subroutine at line 1270
for _ in range(5):
sys.stdout.write('\a')
sys.stdout.flush()
def spin_wheels():
possible_fruits = ["Bar", "Bell", "Orange", "Lemon", "Plum", "Cherry"]
wheel = choices(possible_fruits, k=3)
print(*wheel)
beeping()
return wheel
def adjust_profits(wheel, m, profits):
# we remove the duplicates
s = set(wheel)
if len(s) == 1:
# the three fruits are the same
fruit = s.pop()
if fruit == "Bar":
print("\n***Jackpot***")
profits = (((100*m)+m)+profits)
else:
print("\n**Top Dollar**")
profits = (((10*m)+m)+profits)
print("You Won!")
elif len(s) == 2:
# two fruits are equal
c = Counter(wheel)
# we get the fruit that appears two times
fruit = sorted(c.items(), key=lambda x: x[1], reverse=True)[0][0]
if fruit == "Bar":
print("\n*Double Bar*")
profits = (((5*m)+m)+profits)
else:
print("\nDouble!!")
profits = (((2*m)+m)+profits)
print("You Won!")
else:
# three different fruits
print("\nYou Lost.")
profits = profits - m
return profits
def final_message(profits):
if profits < 0:
print("Pay up! Please leave your money on the terminal")
elif profits == 0:
print("Hey, You broke even.")
else:
print("Collect your winings from the H&M cashier.")
profits = 0
keep_betting = True
initial_message()
while keep_betting:
m = input_betting()
w = spin_wheels()
profits = adjust_profits(w, m, profits)
print("Your standings are ${}".format(profits))
answer = input("Again?")
try:
if not answer[0].lower() == "y":
keep_betting = False
except IndexError:
keep_betting = False
final_message(profits)
######################################################################
#
# Porting notes
#
# The selections of the fruits(Bar, apples, lemon, etc.) are made
# with equal probability, accordingly to random.choices documentation.
# It could be added a weights list to the function and therefore
# adjust the expected payoff
#
######################################################################

3
80_Slots/ruby/README.md Normal file
View File

@@ -0,0 +1,3 @@
Original source downloaded [from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Ruby](https://www.ruby-lang.org/en/)

134
80_Slots/slots.bas Normal file
View File

@@ -0,0 +1,134 @@
10 PRINT TAB(30);"SLOTS"
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT: PRINT: PRINT
100 REM PRODUCED BY FRED MIRABELLE AND BOB HARPER ON JAN 29, 1973
110 REM IT SIMULATES THE SLOT MACHINE.
120 PRINT "YOU ARE IN THE H&M CASINO,IN FRONT OF ONE OF OUR"
130 PRINT "ONE-ARM BANDITS. BET FROM $1 TO $100."
140 PRINT "TO PULL THE ARM, PUNCH THE RETURN KEY AFTER MAKING YOUR BET."
150 LET P=0
160 PRINT: PRINT"YOUR BET";
170 INPUT M
180 IF M>100 THEN 860
190 IF M<1 THEN 880
200 M=INT(M)
210 GOSUB 1270
220 PRINT
230 LET X=INT(6*RND(1)+1)
240 LET Y=INT(6*RND(1)+1)
250 LET Z=INT(6*RND(1)+1)
260 PRINT
270 IF X=1 THEN 910
280 IF X=2 THEN 930
290 IF X=3 THEN 950
300 IF X=4 THEN 970
310 IF X=5 THEN 990
320 IF X=6 THEN 1010
330 IF Y=1 THEN 1030
340 IF Y=2 THEN 1050
350 IF Y=3 THEN 1070
360 IF Y=4 THEN 1090
370 IF Y=5 THEN 1110
380 IF Y=6 THEN 1130
390 IF Z=1 THEN 1150
400 IF Z=2 THEN 1170
410 IF Z=3 THEN 1190
420 IF Z=4 THEN 1210
430 IF Z=5 THEN 1230
440 IF Z=6 THEN 1250
450 IF X=Y THEN 600
460 IF X=Z THEN 630
470 IF Y=Z THEN 650
480 PRINT
490 PRINT "YOU LOST."
500 LET P=P-M
510 PRINT "YOUR STANDINGS ARE $"P
520 PRINT "AGAIN";
530 INPUT A$
540 IF A$="Y" THEN 160
550 PRINT
560 IF P<0 THEN 670
570 IF P=0 THEN 690
580 IF P>0 THEN 710
590 GOTO 1350
600 IF Y=Z THEN 730
610 IF Y=1 THEN 820
620 GOTO 1341
630 IF Z=1 THEN 820
640 GOTO 470
650 IF Z=1 THEN 820
660 GOTO 1341
670 PRINT "PAY UP! PLEASE LEAVE YOUR MONEY ON THE TERMINAL."
680 GOTO 1350
690 PRINT"HEY, YOU BROKE EVEN."
700 GOTO 1350
710 PRINT "COLLECT YOUR WINNINGS FROM THE H&M CASHIER."
720 GOTO 1350
730 IF Z=1 THEN 780
740 PRINT: PRINT"**TOP DOLLAR**"
750 PRINT "YOU WON!"
760 P=(((10*M)+M)+P)
770 GOTO 510
780 PRINT:PRINT"***JACKPOT***"
790 PRINT "YOU WON!"
800 P=(((100*M)+M)+P)
810 GOTO 510
820 PRINT:PRINT"*DOUBLE BAR*"
830 PRINT"YOU WON!"
840 P=(((5*M)+M)+P)
850 GOTO 510
860 PRINT"HOUSE LIMITS ARE $100"
870 GOTO 160
880 PRINT"MINIMUM BET IS $1"
890 GOTO 160
900 GOTO 220
910 PRINT"BAR";:GOSUB 1310
920 GOTO 330
930 PRINT"BELL";:GOSUB 1310
940 GOTO 330
950 PRINT"ORANGE";:GOSUB 1310
960 GOTO 330
970 PRINT"LEMON";:GOSUB 1310
980 GOTO 330
990 PRINT"PLUM";:GOSUB 1310
1000 GOTO 330
1010 PRINT"CHERRY";:GOSUB 1310
1020 GOTO 330
1030 PRINT" BAR";:GOSUB 1310
1040 GOTO 390
1050 PRINT" BELL";:GOSUB 1310
1060 GOTO 390
1070 PRINT" ORANGE";:GOSUB 1310
1080 GOTO 390
1090 PRINT" LEMON";:GOSUB 1310
1100 GOTO 390
1110 PRINT" PLUM";:GOSUB 1310
1120 GOTO 390
1130 PRINT" CHERRY";:GOSUB 1310
1140 GOTO 390
1150 PRINT" BAR"
1160 GOTO 450
1170 PRINT" BELL"
1180 GOTO 450
1190 PRINT" ORANGE"
1200 GOTO 450
1210 PRINT" LEMON"
1220 GOTO 450
1230 PRINT" PLUM"
1240 GOTO 450
1250 PRINT" CHERRY"
1260 GOTO 450
1270 FOR Q4=1 TO 10
1280 PRINT CHR$(7);
1290 NEXT Q4
1300 RETURN
1310 FOR T8=1 TO 5
1320 PRINT CHR$(7);
1330 NEXT T8
1340 RETURN
1341 PRINT: PRINT "DOUBLE!!"
1342 PRINT"YOU WON!"
1343 P=(((2*M)+M)+P)
1344 GOTO 510
1350 STOP
9999 END

3
80_Slots/vbnet/README.md Normal file
View File

@@ -0,0 +1,3 @@
Original BASIC source [downloaded from Vintage Basic](http://www.vintage-basic.net/games.html)
Conversion to [Visual Basic .NET](https://en.wikipedia.org/wiki/Visual_Basic_.NET)