remove copy/pasted ports from alternate languages

This commit is contained in:
Jeff Atwood
2022-03-15 21:40:04 -07:00
parent a1af4fd89f
commit f4613dab05
1341 changed files with 0 additions and 71352 deletions

View File

@@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Diamond", "Diamond.csproj", "{44B406C8-70F0-4183-B19A-5B045A1AEBA4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{44B406C8-70F0-4183-B19A-5B045A1AEBA4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{44B406C8-70F0-4183-B19A-5B045A1AEBA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{44B406C8-70F0-4183-B19A-5B045A1AEBA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{44B406C8-70F0-4183-B19A-5B045A1AEBA4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,3 +0,0 @@
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/)

View File

@@ -1,163 +0,0 @@
import java.util.Scanner;
/**
* Game of Diamond
* <p>
* Based on the BASIC game of Diamond here
* https://github.com/coding-horror/basic-computer-games/blob/main/32%20Diamond/diamond.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.
*
* Converted from BASIC to Java by Darren Cardenas.
*/
public class Diamond {
private static final int LINE_WIDTH = 60;
private static final String PREFIX = "CC";
private static final char SYMBOL = '!';
private final Scanner scan; // For user input
public Diamond() {
scan = new Scanner(System.in);
} // End of constructor Diamond
public void play() {
showIntro();
startGame();
} // End of method play
private void showIntro() {
System.out.println(" ".repeat(32) + "DIAMOND");
System.out.println(" ".repeat(14) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println("\n\n");
} // End of method showIntro
private void startGame() {
int body = 0;
int column = 0;
int end = 0;
int fill = 0;
int increment = 2;
int numPerSide = 0;
int prefixIndex = 0;
int row = 0;
int start = 1;
int userNum = 0;
String lineContent = "";
// Get user input
System.out.println("FOR A PRETTY DIAMOND PATTERN,");
System.out.print("TYPE IN AN ODD NUMBER BETWEEN 5 AND 21? ");
userNum = scan.nextInt();
System.out.println("");
// Calcuate number of diamonds to be drawn on each side of screen
numPerSide = (int) (LINE_WIDTH / userNum);
end = userNum;
// Begin loop through each row of diamonds
for (row = 1; row <= numPerSide; row++) {
// Begin loop through top and bottom halves of each diamond
for (body = start; increment < 0 ? body >= end : body <= end; body += increment) {
lineContent = "";
// Add whitespace
while (lineContent.length() < ((userNum - body) / 2)) {
lineContent += " ";
}
// Begin loop through each column of diamonds
for (column = 1; column <= numPerSide; column++) {
prefixIndex = 1;
// Begin loop that fills each diamond with characters
for (fill = 1; fill <= body; fill++) {
// Right side of diamond
if (prefixIndex > PREFIX.length()) {
lineContent += SYMBOL;
}
// Left side of diamond
else {
lineContent += PREFIX.charAt(prefixIndex - 1);
prefixIndex++;
}
} // End loop that fills each diamond with characters
// Column finished
if (column == numPerSide) {
break;
}
// Column not finishd
else {
// Add whitespace
while (lineContent.length() < (userNum * column + (userNum - body) / 2)) {
lineContent += " ";
}
}
} // End loop through each column of diamonds
System.out.println(lineContent);
} // End loop through top and bottom half of each diamond
if (start != 1) {
start = 1;
end = userNum;
increment = 2;
}
else {
start = userNum - 2;
end = 1;
increment = -2;
row--;
}
} // End loop through each row of diamonds
} // End of method startGame
public static void main(String[] args) {
Diamond diamond = new Diamond();
diamond.play();
} // End of method main
} // End of class Diamond

View File

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

View File

@@ -1,3 +0,0 @@
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

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

View File

@@ -1,94 +0,0 @@
// DIAMOND
//
// 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;
}
// Main program
async function main()
{
print(tab(33) + "DIAMOND\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
print("\n");
print("\n");
print("\n");
print("FOR A PRETTY DIAMOND PATTERN,\n");
print("TYPE IN AN ODD NUMBER BETWEEN 5 AND 21");
r = parseInt(await input());
q = Math.floor(60 / r);
as = "CC"
x = 1;
y = r;
z = 2;
for (l = 1; l <= q; l++) {
for (n = x; z < 0 ? n >= y : n <= y; n += z) {
str = "";
while (str.length < (r - n) / 2)
str += " ";
for (m = 1; m <= q; m++) {
c = 1;
for (a = 1; a <= n; a++) {
if (c > as.length)
str += "!";
else
str += as[c++ - 1];
}
if (m == q)
break;
while (str.length < r * m + (r - n) / 2)
str += " ";
}
print(str + "\n");
}
if (x != 1) {
x = 1;
y = r;
z = 2;
} else {
x = r - 2;
y = 1;
z = -2;
l--;
}
}
}
main();

View File

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

View File

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

View File

@@ -1,35 +0,0 @@
#!/usr/bin/perl
use strict;
################
# PORTING NOTES:
# * In basic "Tab" function are not spaces, but absolute col position on screen.
# * It was too dificult to port this one, couldn't figure out the original algorithm.
# * So the algorithm was remake.
#
print ' 'x 33 . "DIAMOND\n";
print ' 'x 15 . "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n";
print "\n"; print "\n"; print "\n";
print "FOR A PRETTY DIAMOND PATTERN,\n";
print "TYPE IN AN ODD NUMBER BETWEEN 5 AND 21? "; chomp(my $R = <STDIN>); print "\n";
my $Wid= int(60/$R)+1;
my $Dia="CC". "!" x ($R-2);
for (my $J=1; $J<$Wid; $J++) {
for (my $K=1; $K<($R+2)*2-4; $K+=2) {
my $Size= $K;
if ($K>$R) { $Size=$R+($R-$K); }
my $Chunk= substr($Dia, 0, $Size);
for (my $L=1; $L<$Wid; $L++) {
my $Space= " " x (($R-$Size)/2);
if ($L>1) { $Space.=$Space; }
print $Space.$Chunk;
}
print "\n";
}
}
exit;

View File

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

View File

@@ -1,64 +0,0 @@
"""
DIAMOND
Prints pretty diamond patterns to the screen.
Ported by Dave LeCompte
"""
def print_with_tab(space_count, msg):
if space_count > 0:
spaces = " " * space_count
else:
spaces = ""
print(spaces + msg)
def print_diamond(begin_width, end_width, step, width, count):
edgeString = "CC"
fill = "!"
n = begin_width
while True:
line_buffer = " " * ((width - n) // 2)
for across in range(count):
for a in range(n):
if a >= len(edgeString):
line_buffer += fill
else:
line_buffer += edgeString[a]
line_buffer += " " * (
(width * (across + 1) + (width - n) // 2) - len(line_buffer)
)
print(line_buffer)
if n == end_width:
return
n += step
def main():
print_with_tab(33, "DIAMOND")
print_with_tab(15, "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
print()
print()
print()
print("FOR A PRETTY DIAMOND PATTERN,")
print("TYPE IN AN ODD NUMBER BETWEEN 5 AND 21")
width = int(input())
print()
PAGE_WIDTH = 60
count = int(PAGE_WIDTH / width)
for down in range(count):
print_diamond(1, width, 2, width, count)
print_diamond(width - 2, 1, -2, width, count)
print()
print()
if __name__ == "__main__":
main()

View File

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

View File

@@ -1,45 +0,0 @@
def intro
print " DIAMOND
CREATIVE COMPUTING MORRISTOWN, NEW JERSEY
FOR A PRETTY DIAMOND PATTERN,
TYPE IN AN ODD NUMBER BETWEEN 5 AND 21? "
end
def get_facets
while true
number = gets.chomp
return number.to_i if /^\d+$/.match(number)
puts "!NUMBER EXPECTED - RETRY INPUT LINE"
print "? "
end
end
def get_diamond_lines(facets)
spacers = (facets - 1) / 2
lines = [' ' * spacers + 'C' + ' ' * spacers]
lines += (1...facets).step(2).to_a.map { |v|
spacers -= 1
' ' * spacers + 'CC' + '!' * v + ' ' * spacers
}
lines + lines[0..-2].reverse
end
def draw_diamonds(lines)
repeat = 60 / lines[0].length
(0...repeat).each { lines.map { |l| l * repeat }.each { |l| puts l } }
end
def main
intro
facets = get_facets
puts
lines = get_diamond_lines(facets)
draw_diamonds(lines)
end
trap "SIGINT" do puts; exit 130 end
main

View File

@@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Diamond", "Diamond.vbproj", "{87084ED3-F01C-4D7E-8BE7-10C2F3FA148F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{87084ED3-F01C-4D7E-8BE7-10C2F3FA148F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87084ED3-F01C-4D7E-8BE7-10C2F3FA148F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87084ED3-F01C-4D7E-8BE7-10C2F3FA148F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87084ED3-F01C-4D7E-8BE7-10C2F3FA148F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,8 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Diamond</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>16.9</LangVersion>
</PropertyGroup>
</Project>

View File

@@ -1,3 +0,0 @@
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)

View File

@@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Remove="TextUtil.cs" />
</ItemGroup>
</Project>

View File

@@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dice", "Dice.csproj", "{D136AC51-DDC0-471A-8EAC-D3C772FA7D51}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D136AC51-DDC0-471A-8EAC-D3C772FA7D51}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D136AC51-DDC0-471A-8EAC-D3C772FA7D51}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D136AC51-DDC0-471A-8EAC-D3C772FA7D51}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D136AC51-DDC0-471A-8EAC-D3C772FA7D51}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,112 +0,0 @@
using System;
using System.Linq;
namespace BasicComputerGames.Dice
{
public class Game
{
private readonly RollGenerator _roller = new RollGenerator();
public void GameLoop()
{
DisplayIntroText();
// RollGenerator.ReseedRNG(1234); // hard-code seed for repeatabilty during testing
do
{
int numRolls = GetInput();
var counter = CountRolls(numRolls);
DisplayCounts(counter);
} while (TryAgain());
}
private void DisplayIntroText()
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Dice");
Console.WriteLine("Creating Computing, Morristown, New Jersey."); Console.WriteLine();
Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.WriteLine("Original code by Danny Freidus.");
Console.WriteLine("Originally published in 1978 in the book 'Basic Computer Games' by David Ahl.");
Console.WriteLine("Modernized and converted to C# in 2021 by James Curran (noveltheory.com).");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine("This program simulates the rolling of a pair of dice.");
Console.WriteLine("You enter the number of times you want the computer to");
Console.WriteLine("'roll' the dice. Watch out, very large numbers take");
Console.WriteLine("a long time. In particular, numbers over 10 million.");
Console.WriteLine();
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine("Press any key start the game.");
Console.ReadKey(true);
}
private int GetInput()
{
int num = -1;
Console.WriteLine();
do
{
Console.WriteLine();
Console.Write("How many rolls? ");
} while (!Int32.TryParse(Console.ReadLine(), out num));
return num;
}
private void DisplayCounts(int[] counter)
{
Console.WriteLine();
Console.WriteLine($"\tTotal\tTotal Number");
Console.WriteLine($"\tSpots\tof Times");
Console.WriteLine($"\t===\t=========");
for (var n = 1; n < counter.Length; ++n)
{
Console.WriteLine($"\t{n + 1,2}\t{counter[n],9:#,0}");
}
Console.WriteLine();
}
private int[] CountRolls(int x)
{
var counter = _roller.Rolls().Take(x).Aggregate(new int[12], (cntr, r) =>
{
cntr[r.die1 + r.die2 - 1]++;
return cntr;
});
return counter;
}
/// <summary>
/// Prompt the player to try again, and wait for them to press Y or N.
/// </summary>
/// <returns>Returns true if the player wants to try again, false if they have finished playing.</returns>
private bool TryAgain()
{
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine("Would you like to try again? (Press 'Y' for yes or 'N' for no)");
Console.ForegroundColor = ConsoleColor.Yellow;
Console.Write("> ");
char pressedKey;
// Keep looping until we get a recognised input
do
{
// Read a key, don't display it on screen
ConsoleKeyInfo key = Console.ReadKey(true);
// Convert to upper-case so we don't need to care about capitalisation
pressedKey = Char.ToUpper(key.KeyChar);
// Is this a key we recognise? If not, keep looping
} while (pressedKey != 'Y' && pressedKey != 'N');
// Display the result on the screen
Console.WriteLine(pressedKey);
// Return true if the player pressed 'Y', false for anything else.
return (pressedKey == 'Y');
}
}
}

View File

@@ -1,14 +0,0 @@
namespace BasicComputerGames.Dice
{
public class Program
{
public static void Main(string[] args)
{
// Create an instance of our main Game class
Game game = new Game();
// Call its GameLoop function. This will play the game endlessly in a loop until the player chooses to quit.
game.GameLoop();
}
}
}

View File

@@ -1,3 +0,0 @@
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/) by James Curran (http://www.noveltheory.com)

View File

@@ -1,20 +0,0 @@
using System;
using System.Collections.Generic;
namespace BasicComputerGames.Dice
{
public class RollGenerator
{
static Random _rnd = new Random();
public static void ReseedRNG(int seed) => _rnd = new Random(seed);
public IEnumerable<(int die1, int die2)> Rolls()
{
while (true)
{
yield return (_rnd.Next(1, 7), _rnd.Next(1, 7));
}
}
}
}

View File

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

View File

@@ -1,146 +0,0 @@
import java.util.Arrays;
import java.util.Scanner;
/**
* Game of Dice
* <p>
* Based on the Basic game of Dice here
* https://github.com/coding-horror/basic-computer-games/blob/main/33%20Dice/dice.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 Dice {
// Used for keyboard input
private final Scanner kbScanner;
private enum GAME_STATE {
START_GAME,
INPUT_AND_CALCULATE,
RESULTS,
GAME_OVER
}
// Current game state
private GAME_STATE gameState;
private int[] spots;
public Dice() {
kbScanner = new Scanner(System.in);
gameState = GAME_STATE.START_GAME;
}
/**
* Main game loop
*/
public void play() {
do {
switch (gameState) {
case START_GAME:
intro();
spots = new int[12];
gameState = GAME_STATE.INPUT_AND_CALCULATE;
break;
case INPUT_AND_CALCULATE:
int howManyRolls = displayTextAndGetNumber("HOW MANY ROLLS? ");
for (int i = 0; i < howManyRolls; i++) {
int diceRoll = (int) (Math.random() * 6 + 1) + (int) (Math.random() * 6 + 1);
// save dice roll in zero based array
spots[diceRoll - 1]++;
}
gameState = GAME_STATE.RESULTS;
break;
case RESULTS:
System.out.println("TOTAL SPOTS" + simulateTabs(8) + "NUMBER OF TIMES");
for (int i = 1; i < 12; i++) {
// show output using zero based array
System.out.println(simulateTabs(5) + (i + 1) + simulateTabs(20) + spots[i]);
}
System.out.println();
if (yesEntered(displayTextAndGetInput("TRY AGAIN? "))) {
gameState = GAME_STATE.START_GAME;
} else {
gameState = GAME_STATE.GAME_OVER;
}
break;
}
} while (gameState != GAME_STATE.GAME_OVER);
}
private void intro() {
System.out.println(simulateTabs(34) + "DICE");
System.out.println(simulateTabs(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println();
System.out.println("THIS PROGRAM SIMULATES THE ROLLING OF A");
System.out.println("PAIR OF DICE.");
System.out.println("YOU ENTER THE NUMBER OF TIMES YOU WANT THE COMPUTER TO");
System.out.println("'ROLL' THE DICE. WATCH OUT, VERY LARGE NUMBERS TAKE");
System.out.println("A LONG TIME. IN PARTICULAR, NUMBERS OVER 5000.");
}
/*
* 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);
}
}

View File

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

View File

@@ -1,3 +0,0 @@
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

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

View File

@@ -1,84 +0,0 @@
// DICE
//
// 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;
}
// Main program
async function main()
{
print(tab(34) + "DICE\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
print("\n");
print("\n");
print("\n");
f = [];
// Danny Freidus
print("THIS PROGRAM SIMULATES THE ROLLING OF A\n");
print("PAIR OF DICE.\n");
print("YOU ENTER THE NUMBER OF TIMES YOU WANT THE COMPUTER TO\n");
print("'ROLL' THE DICE. WATCH OUT, VERY LARGE NUMBERS TAKE\n");
print("A LONG TIME. IN PARTICULAR, NUMBERS OVER 5000.\n");
do {
for (q = 1; q <= 12; q++)
f[q] = 0;
print("\n");
print("HOW MANY ROLLS");
x = parseInt(await input());
for (s = 1; s <= x; s++) {
a = Math.floor(Math.random() * 6 + 1);
b = Math.floor(Math.random() * 6 + 1);
r = a + b;
f[r]++;
}
print("\n");
print("TOTAL SPOTS\tNUMBER OF TIMES\n");
for (v = 2; v <= 12; v++) {
print("\t" + v + "\t" + f[v] + "\n");
}
print("\n");
print("\n");
print("TRY AGAIN");
str = await input();
} while (str.substr(0, 1) == "Y") ;
}
main();

View File

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

View File

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

View File

@@ -1,40 +0,0 @@
#!/usr/bin/perl
use strict;
print ' 'x 34 . "DICE\n";
print ' 'x 15 . "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n";
print "\n\n\n";
my @F;
#REM DANNY FREIDUS;
print "THIS PROGRAM SIMULATES THE ROLLING OF A\n";
print "PAIR OF DICE.\n";
print "YOU ENTER THE NUMBER OF TIMES YOU WANT THE COMPUTER TO\n";
print "'ROLL' THE DICE. WATCH OUT, VERY LARGE NUMBERS TAKE\n";
print "A LONG TIME. IN PARTICULAR, NUMBERS OVER 5000.\n";
my $X;
my $Z;
do {
for (my $Q=1; $Q<=12; $Q++) {
$F[$Q]=0;
}
print "\n"; print "HOW MANY ROLLS";
print "? "; chomp($X = <STDIN>);
for (my $S=1; $S<=$X; $S++) {
my $A=int(6*rand(1)+1);
my $B=int(6*rand(1)+1);
my $R=$A+$B;
$F[$R]=$F[$R]+1;
}
print "\n";
print "TOTAL SPOTS\tNUMBER OF TIMES\n";
for (my $V=2; $V<=12; $V++) {
print "$V\t\t$F[$V]\n";
}
print "\n";
print "\n"; print "TRY AGAIN";
print "? "; chomp($Z = <STDIN>);
} until (uc($Z) ne "YES");
exit;

View File

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

View File

@@ -1,113 +0,0 @@
########################################################
#
# Dice
#
# From: BASIC Computer Games (1978)
# Edited by David H. Ahl
#
# "Not exactly a game, this program simulates rolling
# a pair of dice a large number of times and prints out
# the frequency distribution. You simply input the
# number of rolls. It is interesting to see how many
# rolls are necessary to approach the theoretical
# distribution:
#
# 2 1/36 2.7777...%
# 3 2/36 5.5555...%
# 4 3/36 8.3333...%
# etc.
#
# "Daniel Freidus wrote this program while in the
# seventh grade at Harrison Jr-Sr High School,
# Harrison, New York."
#
# Python port by Jeff Jetton, 2019
#
########################################################
import random
# We'll track counts of roll outcomes in a 13-element list.
# The first two indices (0 & 1) are ignored, leaving just
# the indices that match the roll values (2 through 12).
freq = [0] * 13
# Display intro text
print("\n Dice")
print("Creative Computing Morristown, New Jersey")
print("\n\n")
# "Danny Freidus"
print("This program simulates the rolling of a")
print("pair of dice.")
print("You enter the number of times you want the computer to")
print("'roll' the dice. Watch out, very large numbers take")
print("a long time. In particular, numbers over 5000.")
still_playing = True
while still_playing:
print("")
n = int(input("How many rolls? "))
# Roll the dice n times
for i in range(n):
die1 = random.randint(1, 6)
die2 = random.randint(1, 6)
roll_total = die1 + die2
freq[roll_total] += 1
# Display final results
print("\nTotal Spots Number of Times")
for i in range(2, 13):
print(" %-14d%d" % (i, freq[i]))
# Keep playing?
print("")
response = input("Try again? ")
if len(response) > 0 and response.upper()[0] == "Y":
# Clear out the frequency list
freq = [0] * 13
else:
# Exit the game loop
still_playing = False
########################################################
#
# Porting Notes
#
# A fairly straightforward port. The only change is
# in the handling of the user's "try again" response.
# The original program only continued if the user
# entered "YES", whereas this version will continue
# if any word starting with "Y" or "y" is given.
#
# The instruction text--which, like all these ports,
# was taken verbatim from the original listing--is
# charmingly quaint in its dire warning against
# setting the number of rolls too high. At the time
# of this writing, on a fairly slow computer, a
# 5000-roll run typically clocks in at well under
# 1/10 of a second!
#
#
# Ideas for Modifications
#
# Have the results include a third column showing
# the percent of rolls each count represents. Or
# (better yet) print a low-fi bar graph using
# rows of asterisks to represent relative values,
# with each asterisk representing one percent,
# for example.
#
# Add a column showing the theoretically expected
# percentage, for comparison.
#
# Keep track of how much time the series of rolls
# takes and add that info to the final report.
#
# What if three (or four, or five...) dice were
# rolled each time?
#
########################################################

View File

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

View File

@@ -1,51 +0,0 @@
def intro
puts " DICE
CREATIVE COMPUTING MORRISTOWN, NEW JERSEY
THIS PROGRAM SIMULATES THE ROLLING OF A
PAIR OF DICE.
YOU ENTER THE NUMBER OF TIMES YOU WANT THE COMPUTER TO
'ROLL' THE DICE. WATCH OUT, VERY LARGE NUMBERS TAKE
A LONG TIME. IN PARTICULAR, NUMBERS OVER 5000.
"
end
def get_rolls
while true
number = gets.chomp
return number.to_i if /^\d+$/.match(number)
puts "!NUMBER EXPECTED - RETRY INPUT LINE"
print "? "
end
end
def dice_roll = rand(6) + 1 # ruby 3, woot!
def print_rolls(rolls)
values = Array.new(11, 0)
(1..rolls).each { values[dice_roll + dice_roll - 2] += 1 }
puts "\nTOTAL SPOTS NUMBER OF TIMES"
(0..10).each { |k| puts " %-2d %-2d" % [k + 2, values[k]] }
end
def main
intro
loop do
print "HOW MANY ROLLS? "
rolls = get_rolls
print_rolls(rolls)
print "\n\nTRY AGAIN? "
option = (gets || '').chomp.upcase
break unless option == 'YES'
puts
end
end
trap "SIGINT" do puts; exit 130 end
main

View File

@@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Dice", "Dice.vbproj", "{6410CCD0-0D78-49C9-9B15-70F901A1EB19}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{6410CCD0-0D78-49C9-9B15-70F901A1EB19}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6410CCD0-0D78-49C9-9B15-70F901A1EB19}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6410CCD0-0D78-49C9-9B15-70F901A1EB19}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6410CCD0-0D78-49C9-9B15-70F901A1EB19}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,8 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Dice</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>16.9</LangVersion>
</PropertyGroup>
</Project>

View File

@@ -1,3 +0,0 @@
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)

View File

@@ -1,38 +0,0 @@
Imports System
Module Program
Sub Main(args As String())
Const header As String =
" DICE
CREATIVE COMPUTING MORRISTOWN, NEW JERSEY
THIS PROGRAM SIMULATES THE ROLLING OF A
PAIR OF DICE.
YOU ENTER THE NUMBER OF TIMES YOU WANT THE COMPUTER TO
/ROLL/ THE DICE. WATCH OUT, VERY LARGE NUMBERS TAKE
A LONG TIME. IN PARTICULAR, NUMBERS OVER 5000."
Console.WriteLine(header)
Dim D6 As New Random()
Dim continuePrompt As String = "YES"
While continuePrompt = "YES"
Console.Write($"{vbCrLf}HOW MANY ROLLS? ")
Dim x As Integer = Convert.ToInt32(Console.ReadLine())
Dim F = Enumerable.Repeat(0, 11).ToList()
For s As Integer = 0 To x - 1
F(D6.Next(6) + D6.Next(6)) += 1
Next
Console.WriteLine($"{vbCrLf}TOTAL SPOTS NUMBER OF TIMES")
For V As Integer = 0 To 10
Console.WriteLine($" {V + 2}{vbTab,-8}{F(V)}")
Next
Console.Write($"{vbCrLf}TRY AGAIN ")
continuePrompt = Console.ReadLine().ToUpper()
End While
End Sub
End Module

View File

@@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Digits", "Digits.csproj", "{BB89211D-85FB-4FC0-AF62-715459227D7E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{BB89211D-85FB-4FC0-AF62-715459227D7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB89211D-85FB-4FC0-AF62-715459227D7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB89211D-85FB-4FC0-AF62-715459227D7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB89211D-85FB-4FC0-AF62-715459227D7E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,3 +0,0 @@
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/)

View File

@@ -1,185 +0,0 @@
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
* DIGITS
* <p>
* Converted from BASIC to Java by Aldrin Misquitta (@aldrinm)
*/
public class Digits {
public static void main(String[] args) {
printIntro();
Scanner scan = new Scanner(System.in);
boolean showInstructions = readInstructionChoice(scan);
if (showInstructions) {
printInstructions();
}
int a = 0, b = 1, c = 3;
int[][] m = new int[27][3];
int[][] k = new int[3][3];
int[][] l = new int[9][3];
boolean continueGame = true;
while (continueGame) {
for (int[] ints : m) {
Arrays.fill(ints, 1);
}
for (int[] ints : k) {
Arrays.fill(ints, 9);
}
for (int[] ints : l) {
Arrays.fill(ints, 3);
}
l[0][0] = 2;
l[4][1] = 2;
l[8][2] = 2;
int z = 26, z1 = 8, z2 = 2, runningCorrect = 0;
for (int t = 1; t <= 3; t++) {
boolean validNumbers = false;
int[] numbers = new int[0];
while (!validNumbers) {
System.out.println();
numbers = read10Numbers(scan);
validNumbers = true;
for (int number : numbers) {
if (number < 0 || number > 2) {
System.out.println("ONLY USE THE DIGITS '0', '1', OR '2'.");
System.out.println("LET'S TRY AGAIN.");
validNumbers = false;
break;
}
}
}
System.out.printf("\n%-14s%-14s%-14s%-14s", "MY GUESS", "YOUR NO.", "RESULT", "NO. RIGHT");
for (int number : numbers) {
int s = 0;
int myGuess = 0;
for (int j = 0; j <= 2; j++) {
//What did the original author have in mind ? The first expression always results in 0 because a is always 0
int s1 = a * k[z2][j] + b * l[z1][j] + c * m[z][j];
if (s < s1) {
s = s1;
myGuess = j;
} else if (s1 == s) {
if (Math.random() >= 0.5) {
myGuess = j;
}
}
}
String result;
if (myGuess != number) {
result = "WRONG";
} else {
runningCorrect++;
result = "RIGHT";
m[z][number] = m[z][number] + 1;
l[z1][number] = l[z1][number] + 1;
k[z2][number] = k[z2][number] + 1;
z = z - (z / 9) * 9;
z = 3 * z + number;
}
System.out.printf("\n%-14d%-14d%-14s%-14d", myGuess, number, result, runningCorrect);
z1 = z - (z / 9) * 9;
z2 = number;
}
}
//print summary report
System.out.println();
if (runningCorrect > 10) {
System.out.println();
System.out.println("I GUESSED MORE THAN 1/3 OF YOUR NUMBERS.");
System.out.println("I WIN.\u0007");
} else if (runningCorrect < 10) {
System.out.println("I GUESSED LESS THAN 1/3 OF YOUR NUMBERS.");
System.out.println("YOU BEAT ME. CONGRATULATIONS *****");
} else {
System.out.println("I GUESSED EXACTLY 1/3 OF YOUR NUMBERS.");
System.out.println("IT'S A TIE GAME.");
}
continueGame = readContinueChoice(scan);
}
System.out.println("\nTHANKS FOR THE GAME.");
}
private static boolean readContinueChoice(Scanner scan) {
System.out.print("\nDO YOU WANT TO TRY AGAIN (1 FOR YES, 0 FOR NO) ? ");
int choice;
try {
choice = scan.nextInt();
return choice == 1;
} catch (InputMismatchException ex) {
return false;
} finally {
scan.nextLine();
}
}
private static int[] read10Numbers(Scanner scan) {
System.out.print("TEN NUMBERS, PLEASE ? ");
int[] numbers = new int[10];
for (int i = 0; i < numbers.length; i++) {
boolean validInput = false;
while (!validInput) {
try {
int n = scan.nextInt();
validInput = true;
numbers[i] = n;
} catch (InputMismatchException ex) {
System.out.println("!NUMBER EXPECTED - RETRY INPUT LINE");
} finally {
scan.nextLine();
}
}
}
return numbers;
}
private static void printInstructions() {
System.out.println("\n");
System.out.println("PLEASE TAKE A PIECE OF PAPER AND WRITE DOWN");
System.out.println("THE DIGITS '0', '1', OR '2' THIRTY TIMES AT RANDOM.");
System.out.println("ARRANGE THEM IN THREE LINES OF TEN DIGITS EACH.");
System.out.println("I WILL ASK FOR THEN TEN AT A TIME.");
System.out.println("I WILL ALWAYS GUESS THEM FIRST AND THEN LOOK AT YOUR");
System.out.println("NEXT NUMBER TO SEE IF I WAS RIGHT. BY PURE LUCK,");
System.out.println("I OUGHT TO BE RIGHT TEN TIMES. BUT I HOPE TO DO BETTER");
System.out.println("THAN THAT *****");
System.out.println();
}
private static boolean readInstructionChoice(Scanner scan) {
System.out.print("FOR INSTRUCTIONS, TYPE '1', ELSE TYPE '0' ? ");
int choice;
try {
choice = scan.nextInt();
return choice == 1;
} catch (InputMismatchException ex) {
return false;
} finally {
scan.nextLine();
}
}
private static void printIntro() {
System.out.println(" DIGITS");
System.out.println(" CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println("\n\n");
System.out.println("THIS IS A GAME OF GUESSING.");
}
}

View File

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

View File

@@ -1,3 +0,0 @@
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

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

View File

@@ -1,175 +0,0 @@
// DIGITS
//
// 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;
}
// Main program
async function main()
{
print(tab(33) + "DIGITS\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
print("\n");
print("\n");
print("\n");
print("THIS IS A GAME OF GUESSING.\n");
print("FOR INSTRUCTIONS, TYPE '1', ELSE TYPE '0'");
e = parseInt(await input());
if (e != 0) {
print("\n");
print("PLEASE TAKE A PIECE OF PAPER AND WRITE DOWN\n");
print("THE DIGITS '0', '1', OR '2' THIRTY TIMES AT RANDOM.\n");
print("ARRANGE THEM IN THREE LINES OF TEN DIGITS EACH.\n");
print("I WILL ASK FOR THEN TEN AT A TIME.\n");
print("I WILL ALWAYS GUESS THEM FIRST AND THEN LOOK AT YOUR\n");
print("NEXT NUMBER TO SEE IF I WAS RIGHT. BY PURE LUCK,\n");
print("I OUGHT TO BE RIGHT TEN TIMES. BUT I HOPE TO DO BETTER\n");
print("THAN THAT *****\n");
print("\n");
print("\n");
}
a = 0;
b = 1;
c = 3;
m = [];
k = [];
l = [];
n = [];
while (1) {
for (i = 0; i <= 26; i++) {
m[i] = [];
for (j = 0; j <= 2; j++) {
m[i][j] = 1;
}
}
for (i = 0; i <= 2; i++) {
k[i] = [];
for (j = 0; j <= 2; j++) {
k[i][j] = 9;
}
}
for (i = 0; i <= 8; i++) {
l[i] = [];
for (j = 0; j <= 2; j++) {
l[i][j] = 3;
}
}
l[0][0] = 2;
l[4][1] = 2;
l[8][2] = 2;
z = 26;
z1 = 8;
z2 = 2;
x = 0;
for (t = 1; t <= 3; t++) {
while (1) {
print("\n");
print("TEN NUMBERS, PLEASE");
str = await input();
for (i = 1; i <= 10; i++) {
n[i] = parseInt(str);
j = str.indexOf(",");
if (j >= 0) {
str = str.substr(j + 1);
}
if (n[i] < 0 || n[i] > 2)
break;
}
if (i <= 10) {
print("ONLY USE THE DIGITS '0', '1', OR '2'.\n");
print("LET'S TRY AGAIN.\n");
} else {
break;
}
}
print("\n");
print("MY GUESS\tYOUR NO.\tRESULT\tNO. RIGHT\n");
print("\n");
for (u = 1; u <= 10; u++) {
n2 = n[u];
s = 0;
for (j = 0; j <= 2; j++) {
s1 = a * k[z2][j] + b * l[z1][j] + c * m[z][j];
if (s > s1)
continue;
if (s < s1 || Math.random() >= 0.5) {
s = s1;
g = j;
}
}
print(" " + g + "\t\t " + n[u] + "\t\t");
if (g == n[u]) {
x++;
print(" RIGHT\t " + x + "\n");
m[z][n2]++;
l[z1][n2]++;
k[z2][n2]++;
z = z % 9;
z = 3 * z + n[u];
} else {
print(" WRONG\t " + x + "\n");
}
z1 = z % 9;
z2 = n[u];
}
}
print("\n");
if (x > 10) {
print("I GUESSED MORE THAN 1/3 OF YOUR NUMBERS.\n");
print("I WIN.\n");
} else if (x == 10) {
print("I GUESSED EXACTLY 1/3 OF YOUR NUMBERS.\n");
print("IT'S A TIE GAME.\n");
} else {
print("I GUESSED LESS THAN 1/3 OF YOUR NUMBERS.\n");
print("YOU BEAT ME. CONGRATULATIONS *****\n");
}
print("\n");
print("DO YOU WANT TO TRY AGAIN (1 FOR YES, 0 FOR NO)");
x = parseInt(await input());
if (x != 1)
break;
}
print("\n");
print("THANKS FOR THE GAME.\n");
}
main();

View File

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

View File

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

View File

@@ -1,156 +0,0 @@
import random
def print_intro():
print(" DIGITS")
print(" CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
print("\n\n")
print("THIS IS A GAME OF GUESSING.")
def read_instruction_choice():
print("FOR INSTRUCTIONS, TYPE '1', ELSE TYPE '0' ? ")
try:
choice = int(input())
return choice == 1
except (ValueError, TypeError):
return False
def print_instructions():
print("\n")
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()
def read_10_numbers():
print("TEN NUMBERS, PLEASE ? ")
numbers = []
for _ in range(10):
valid_input = False
while not valid_input:
try:
n = int(input())
valid_input = True
numbers.append(n)
except (TypeError, ValueError):
print("!NUMBER EXPECTED - RETRY INPUT LINE")
return numbers
def read_continue_choice():
print("\nDO YOU WANT TO TRY AGAIN (1 FOR YES, 0 FOR NO) ? ")
try:
choice = int(input())
return choice == 1
except (ValueError, TypeError):
return False
def print_summary_report(running_correct: int):
print()
if running_correct > 10:
print()
print("I GUESSED MORE THAN 1/3 OF YOUR NUMBERS.")
print("I WIN.\u0007")
elif running_correct < 10:
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.")
def main():
print_intro()
if read_instruction_choice():
print_instructions()
a = 0
b = 1
c = 3
m = [[1] * 3 for _ in range(27)]
k = [[9] * 3 for _ in range(3)]
l = [[3] * 3 for _ in range(9)] # noqa: E741
continue_game = True
while continue_game:
l[0][0] = 2
l[4][1] = 2
l[8][2] = 2
z = 26
z1 = 8
z2 = 2
running_correct = 0
for round in range(1, 4):
valid_numbers = False
numbers = []
while not valid_numbers:
print()
numbers = read_10_numbers()
valid_numbers = True
for number in numbers:
if number < 0 or number > 2:
print("ONLY USE THE DIGITS '0', '1', OR '2'.")
print("LET'S TRY AGAIN.")
valid_numbers = False
break
print(
"\n%-14s%-14s%-14s%-14s"
% ("MY GUESS", "YOUR NO.", "RESULT", "NO. RIGHT")
)
for number in numbers:
s = 0
my_guess = 0
for j in range(0, 3):
# What did the original author have in mind ?
# The first expression always results in 0 because a is always 0
s1 = a * k[z2][j] + b * l[int(z1)][j] + c * m[int(z)][j]
if s < s1:
s = s1
my_guess = j
elif s1 == s:
if random.random() >= 0.5:
my_guess = j
result = ""
if my_guess != number:
result = "WRONG"
else:
running_correct += 1
result = "RIGHT"
m[int(z)][number] = m[int(z)][number] + 1
l[int(z1)][number] = l[int(z1)][number] + 1
k[int(z2)][number] = k[int(z2)][number] + 1
z = z - (z / 9) * 9
z = 3 * z + number
print(
"\n%-14d%-14d%-14s%-14d"
% (my_guess, number, result, running_correct)
)
z1 = z - (z / 9) * 9
z2 = number
print_summary_report(running_correct)
continue_game = read_continue_choice()
print("\nTHANKS FOR THE GAME.")
if __name__ == "__main__":
main()

View File

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

View File

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

View File

@@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Digits", "Digits.vbproj", "{837EB2E4-3EE6-447A-8AF7-91CA08841B93}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{837EB2E4-3EE6-447A-8AF7-91CA08841B93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{837EB2E4-3EE6-447A-8AF7-91CA08841B93}.Debug|Any CPU.Build.0 = Debug|Any CPU
{837EB2E4-3EE6-447A-8AF7-91CA08841B93}.Release|Any CPU.ActiveCfg = Release|Any CPU
{837EB2E4-3EE6-447A-8AF7-91CA08841B93}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,8 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>Digits</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>16.9</LangVersion>
</PropertyGroup>
</Project>

View File

@@ -1,3 +0,0 @@
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)

View File

@@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EvenWins", "EvenWins.csproj", "{84209510-4089-4147-B220-E41E534A228B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{84209510-4089-4147-B220-E41E534A228B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84209510-4089-4147-B220-E41E534A228B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84209510-4089-4147-B220-E41E534A228B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84209510-4089-4147-B220-E41E534A228B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,3 +0,0 @@
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/)

View File

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

View File

@@ -1,3 +0,0 @@
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

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

View File

@@ -1,197 +0,0 @@
// EVEN WINS
//
// 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 ma = [];
var ya = [];
// Main program
async function main()
{
print(tab(31) + "EVEN WINS\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
print("\n");
print("\n");
y1 = 0;
m1 = 0;
print(" THIS IS A TWO PERSON GAME CALLED 'EVEN WINS.'\n");
print("TO PLAY THE GAME, THE PLAYERS NEED 27 MARBLES OR\n");
print("OTHER OBJECTS ON A TABLE.\n");
print("\n");
print("\n");
print(" THE 2 PLAYERS ALTERNATE TURNS, WITH EACH PLAYER\n");
print("REMOVING FROM 1 TO 4 MARBLES ON EACH MOVE. THE GAME\n");
print("ENDS WHEN THERE ARE NO MARBLES LEFT, AND THE WINNER\n");
print("IS THE ONE WITH AN EVEN NUMBER OF MARBLES.\n");
print("\n");
print("\n");
print(" THE ONLY RULES ARE THAT (1) YOU MUST ALTERNATE TURNS,\n");
print("(2) YOU MUST TAKE BETWEEN 1 AND 4 MARBLES EACH TURN,\n");
print("AND (3) YOU CANNOT SKIP A TURN.\n");
print("\n");
print("\n");
print("\n");
while (1) {
print(" TYPE A '1' IF YOU WANT TO GO FIRST, AND TYPE\n");
print("A '0' IF YOU WANT ME TO GO FIRST.\n");
c = parseInt(await input());
print("\n");
if (c != 0) {
t = 27;
print("\n");
print("\n");
print("\n");
print("TOTAL= " + t + "\n");
print("\n");
print("\n");
print("WHAT IS YOUR FIRST MOVE");
m = 0;
} else {
t = 27;
m = 2;
print("\n");
print("TOTAL= " + t + "\n");
print("\n");
m1 += m;
t -= m;
}
while (1) {
if (m) {
print("I PICK UP " + m + " MARBLES.\n");
if (t == 0)
break;
print("\n");
print("TOTAL= " + t + "\n");
print("\n");
print(" AND WHAT IS YOUR NEXT MOVE, MY TOTAL IS " + m1 + "\n");
}
while (1) {
y = parseInt(await input());
print("\n");
if (y < 1 || y > 4) {
print("\n");
print("THE NUMBER OF MARBLES YOU MUST TAKE BE A POSITIVE\n");
print("INTEGER BETWEEN 1 AND 4.\n");
print("\n");
print(" WHAT IS YOUR NEXT MOVE?\n");
print("\n");
} else if (y > t) {
print(" YOU HAVE TRIED TO TAKE MORE MARBLES THAN THERE ARE\n");
print("LEFT. TRY AGAIN.\n");
} else {
break;
}
}
y1 += y;
t -= y;
if (t == 0)
break;
print("TOTAL= " + t + "\n");
print("\n");
print("YOUR TOTAL IS " + y1 + "\n");
if (t < 0.5)
break;
r = t % 6;
if (y1 % 2 != 0) {
if (t >= 4.2) {
if (r <= 3.4) {
m = r + 1;
m1 += m;
t -= m;
} else if (r < 4.7 || r > 3.5) {
m = 4;
m1 += m;
t -= m;
} else {
m = 1;
m1 += m;
t -= m;
}
} else {
m = t;
t -= m;
print("I PICK UP " + m + " MARBLES.\n");
print("\n");
print("TOTAL = 0\n");
m1 += m;
break;
}
} else {
if (r < 1.5 || r > 5.3) {
m = 1;
m1 += m;
t -= m;
} else {
m = r - 1;
m1 += m;
t -= m;
if (t < 0.2) {
print("I PICK UP " + m + " MARBLES.\n");
print("\n");
break;
}
}
}
}
print("THAT IS ALL OF THE MARBLES.\n");
print("\n");
print(" MY TOTAL IS " + m1 + ", YOUR TOTAL IS " + y1 +"\n");
print("\n");
if (m1 % 2 != 0) {
print(" YOU WON. DO YOU WANT TO PLAY\n");
} else {
print(" I WON. DO YOU WANT TO PLAY\n");
}
print("AGAIN? TYPE 1 FOR YES AND 0 FOR NO.\n");
a1 = parseInt(await input());
if (a1 == 0)
break;
m1 = 0;
y1 = 0;
}
print("\n");
print("OK. SEE YOU LATER\n");
}
main();

View File

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

View File

@@ -1,152 +0,0 @@
// GAME OF EVEN WINS
//
// 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 r = [[], []];
// Main program
async function main()
{
print(tab(28) + "GAME OF EVEN WINS\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
print("\n");
print("\n");
print("DO YOU WANT INSTRUCTIONS (YES OR NO)");
str = await input();
print("\n");
if (str != "NO") {
print("THE GAME IS PLAYED AS FOLLOWS:\n");
print("\n");
print("AT THE BEGINNING OF THE GAME, A RANDOM NUMBER OF CHIPS ARE\n");
print("PLACED ON THE BOARD. THE NUMBER OF CHIPS ALWAYS STARTS\n");
print("AS AN ODD NUMBER. ON EACH TURN, A PLAYER MUST TAKE ONE,\n");
print("TWO, THREE, OR FOUR CHIPS. THE WINNER IS THE PLAYER WHO\n");
print("FINISHES WITH A TOTAL NUMBER OF CHIPS THAT IS EVEN.\n");
print("THE COMPUTER STARTS OUT KNOWING ONLY THE RULES OF THE\n");
print("GAME. IT GRADUALLY LEARNS TO PLAY WELL. IT SHOULD BE\n");
print("DIFFICULT TO BEAT THE COMPUTER AFTER TWENTY GAMES IN A ROW.\n");
print("TRY IT!!!!\n");
print("\n");
print("TO QUIT AT ANY TIME, TYPE A '0' AS YOUR MOVE.\n");
print("\n");
}
l = 0;
b = 0;
for (i = 0; i <= 5; i++) {
r[1][i] = 4;
r[0][i] = 4;
}
while (1) {
a = 0;
b = 0;
e = 0;
l = 0;
p = Math.floor((13 * Math.random() + 9) / 2) * 2 + 1;
while (1) {
if (p == 1) {
print("THERE IS 1 CHIP ON THE BOARD.\n");
} else {
print("THERE ARE " + p + " CHIPS ON THE BOARD.\n");
}
e1 = e;
l1 = l;
e = a % 2;
l = p % 6;
if (r[e][l] < p) {
m = r[e][l];
if (m <= 0) {
m = 1;
b = 1;
break;
}
p -= m;
if (m == 1)
print("COMPUTER TAKES 1 CHIP LEAVING " + p + "... YOUR MOVE");
else
print("COMPUTER TAKES " + m + " CHIPS LEAVING " + p + "... YOUR MOVE");
b += m;
while (1) {
m = parseInt(await input());
if (m == 0)
break;
if (m < 1 || m > 4 || m > p) {
print(m + " IS AN ILLEGAL MOVE ... YOUR MOVE");
} else {
break;
}
}
if (m == 0)
break;
if (m == p)
break;
p -= m;
a += m;
} else {
if (p == 1) {
print("COMPUTER TAKES 1 CHIP.\n");
} else {
print("COMPUTER TAKES " + p + " CHIPS.\n");
}
r[e][l] = p;
b += p;
break;
}
}
if (m == 0)
break;
if (b % 2 != 0) {
print("GAME OVER ... YOU WIN!!!\n");
print("\n");
if (r[e][l] != 1) {
r[e][l]--;
} else if (r[e1][l1] != 1) {
r[e1][l1]--;
}
} else {
print("GAME OVER ... I WIN!!!\n");
print("\n");
}
}
}
main();

View File

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

View File

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

View File

@@ -1,179 +0,0 @@
#!/usr/bin/perl
use strict;
use warnings;
&main;
sub main {
&print_intro;
&game_play;
}
sub game_play {
my $marbles = 27;
my $turn = 0;
my $player_total = 0;
my $computer_total = 0;
print "TYPE A '1' IF YOU WANT TO GO FIRST AND TYPE A '0' IF YOU WANT ME TO GO FIRST\n";
my $choice = <STDIN>;
chomp($choice);
if ($choice == 0) {
until ($marbles == 0) {
my $computer_choice = &computer_select($marbles,$turn,$player_total);
$marbles = $marbles - $computer_choice;
$computer_total = $computer_total + $computer_choice;
print "MY TOTAL IS $computer_total\n";
print "TOTAL= $marbles\n";
if ($marbles == 0) {&determine_winner($computer_total,$player_total)};
my $player_choice = &player_select($marbles,$turn);
$marbles = $marbles - $player_choice;
$player_total = $player_total + $player_choice;
print "YOUR TOTAL IS $player_total\n";
$turn++;
print "TOTAL= $marbles\n";
if ($marbles == 0) {&determine_winner($computer_total,$player_total)};
}
}
elsif ($choice == 1) {
until ($marbles == 0) {
my $player_choice = &player_select($marbles,$turn);
$marbles = $marbles - $player_choice;
$player_total = $player_total + $player_choice;
$turn++;
print "YOUR TOTAL IS $player_total\n";
print "TOTAL= $marbles\n";
if ($marbles == 0) {&determine_winner($computer_total,$player_total)};
my $computer_choice = &computer_select($marbles,$turn,$player_total);
$marbles = $marbles - $computer_choice;
$computer_total = $computer_total + $computer_choice;
print "MY TOTAL IS $computer_total\n";
print "TOTAL= $marbles\n";
if ($marbles == 0) {&determine_winner($computer_total,$player_total)};
}
}
}
sub determine_winner {
my $computer = shift;
my $player = shift;
print "THAT IS ALL OF THE MARBLES.\n\n";
print "MY TOTAL IS $computer, YOUR TOTAL IS $player\n";
if ($player % 2 == 0) {
print " YOU WON.\n";
}
if ($computer % 2 == 0) {
print " I WON.\n";
}
my $answer = -1;
until ($answer == 1 || $answer == 0) {
print "DO YOU WANT TO PLAY AGAIN? TYPE 1 FOR YES AND 0 FOR NO.\n";
$answer=<STDIN>;
chomp($answer);
}
if ($answer == 1) {
&game_play;
}
else {
print "OK. SEE YOU LATER.\n";
exit;
}
}
sub player_select {
my $marbles = shift;
my $turn = shift;
my $validity="invalid";
if ($turn == 0) {
print "WHAT IS YOUR FIRST MOVE\n";
}
else {
print "WHAT IS YOUR NEXT MOVE\n";
}
until ($validity eq "valid") {
my $num = <STDIN>;
chomp($num);
my $validity=&validity_check($marbles,$num);
if ($validity eq "valid") {
return $num;
}
}
}
sub computer_select {
my $marbles = shift;
my $turn = shift;
my $player_total = shift;
my $num = 2;
my $validity = "invalid";
if ($turn == 0) {
print "I PICK UP $num MARBLES.\n\n";
}
else {
until ($validity eq "valid") {
my $R=$marbles-6*int(($marbles/6));
if (int($player_total/2) == $player_total/2) {
if ($R < 1.5 || $R > 5.3) {
$num = 1;
}
else {
$num = $R - 1;
}
}
elsif ($marbles < 4.2) {
$num = $marbles;
}
elsif ($R > 3.4) {
if ($R < 4.7 || $R > 3.5) {
$num = 4;
}
else {
$num = 1;
}
}
$validity=&validity_check($marbles,$num);
}
print "\nI PICK UP $num MARBLES.\n\n";
}
return $num;
}
sub validity_check {
my $marbles = shift;
my $num = shift;
if ($num > $marbles) {
print "YOU HAVE TRIED TO TAKE MORE MARBLES THAN THERE ARE LEFT. TRY AGAIN. THERE ARE $marbles MARBLES LEFT\n";
return "invalid";
}
if ($num > 0 && $num <= 4) {
return "valid";
}
if ($num < 1 || $num > 4) {
print "THE NUMBER OF MARBLES YOU TAKE MUST BE A POSITIVE INTEGER BETWEEN 1 AND 4\nWHAT IS YOUR NEXT MOVE?\n";
return "invalid";
}
else {
return "invalid";
}
}
sub print_intro {
print ' ' x 31 . "EVEN WINS\n";
print ' ' x 15 . "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n\n\n";
print "THIS IS A 2 PERSON GAME CALLED 'EVEN WINS'. TO PLAY THE GAME, THE PLAYERS NEED 27 MARBLES OR OTHER OBJECTS ON THE TABLE\n\n";
print "THE 2 PLAYERS ALTERNATE TURNS, WITH EACH PLAYER REMOVING FROM 1 TO 4 MARBLES ON EACH MOVE. THE GAME ENDS WHEN THERE ARE NO MARBLES LEFT, AND THE WINNER IS THE ONE WITH AN EVEN NUMBER OF MARBLES\n";
print "THE ONLY RULES ARE THAT (1) YOU MUST ALTERNATE TURNS, (2) YOU MUST TAKE BETWEEN 1 AND 4 MARBLES EACH TURN, AND (3) YOU CANNOT SKIP A TURN.\n\n";
}

View File

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

View File

@@ -1,235 +0,0 @@
# evenwins.py
#
# This version of evenwins.bas based on game decscription and does *not*
# follow the source. The computer chooses marbles at random.
#
# For simplicity, global variables are used to store the game state.
# A good exercise would be to replace this with a class.
#
# The code is not short, but hopefully it is easy for beginners to understand
# and modify.
#
# Infinite loops of the style "while True:" are used to simplify some of the
# code. The "continue" keyword is used in a few places to jump back to the top
# of the loop. The "return" keyword is also used to break out of functions.
# This is generally considered poor style, but in this case it simplifies the
# code and makes it easier to read (at least in my opinion). A good exercise
# would be to remove these infinite loops, and uses of continue, to follow a
# more structured style.
#
# global variables
marbles_in_middle = -1
human_marbles = -1
computer_marbles = -1
whose_turn = ""
def serious_error(msg):
"""
Only call this function during development for serious errors that are due
to mistakes in the program. Should never be called during a regular game.
"""
print("serious_error: " + msg)
exit(1)
def welcome_screen():
print("Welcome to Even Wins!")
print("Based on evenwins.bas from Creative Computing")
print()
print("Even Wins is a two-person game. You start with")
print("27 marbles in the middle of the table.")
print()
print("Players alternate taking marbles from the middle.")
print("A player can take 1 to 4 marbles on their turn, and")
print("turns cannot be skipped. The game ends when there are")
print("no marbles left, and the winner is the one with an even")
print("number of marbles.")
print()
def marbles_str(n):
if n == 1:
return "1 marble"
return f"{n} marbles"
def choose_first_player():
global whose_turn
while True:
ans = input("Do you want to play first? (y/n) --> ")
if ans == "y":
whose_turn = "human"
return
elif ans == "n":
whose_turn = "computer"
return
else:
print()
print('Please enter "y" if you want to play first,')
print('or "n" if you want to play second.')
print()
def next_player():
global whose_turn
if whose_turn == "human":
whose_turn = "computer"
elif whose_turn == "computer":
whose_turn = "human"
else:
serious_error(f"play_game: unknown player {whose_turn}")
# Converts a string s to an int, if possible.
def to_int(s):
try:
n = int(s)
return True, n
except Exception:
return False, 0
def print_board():
global marbles_in_middle
global human_marbles
global computer_marbles
print()
print(f" marbles in the middle: {marbles_in_middle} " + marbles_in_middle * "*")
print(f" # marbles you have: {human_marbles}")
print(f"# marbles computer has: {computer_marbles}")
print()
def human_turn():
global marbles_in_middle
global human_marbles
# get number in range 1 to min(4, marbles_in_middle)
max_choice = min(4, marbles_in_middle)
print("It's your turn!")
while True:
s = input(f"Marbles to take? (1 - {max_choice}) --> ")
ok, n = to_int(s)
if not ok:
print()
print(f" Please enter a whole number from 1 to {max_choice}")
print()
continue
if n < 1:
print()
print(" You must take at least 1 marble!")
print()
continue
if n > max_choice:
print()
print(f" You can take at most {marbles_str(max_choice)}")
print()
continue
print()
print(f"Okay, taking {marbles_str(n)} ...")
marbles_in_middle -= n
human_marbles += n
return
def game_over():
global marbles_in_middle
global human_marbles
global computer_marbles
print()
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print("!! All the marbles are taken: Game Over!")
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
print()
print_board()
if human_marbles % 2 == 0:
print("You are the winner! Congratulations!")
else:
print("The computer wins: all hail mighty silicon!")
print("")
def computer_turn():
global marbles_in_middle
global computer_marbles
global human_marbles
marbles_to_take = 0
print("It's the computer's turn ...")
r = marbles_in_middle - 6 * int(marbles_in_middle / 6) # line 500
if int(human_marbles / 2) == human_marbles / 2: # line 510
if r < 1.5 or r > 5.3: # lines 710 and 720
marbles_to_take = 1
else:
marbles_to_take = r - 1
elif marbles_in_middle < 4.2: # line 580
marbles_to_take = marbles_in_middle
elif r > 3.4: # line 530
if r < 4.7 or r > 3.5:
marbles_to_take = 4
else:
marbles_to_take = r + 1
print(f"Computer takes {marbles_str(marbles_to_take)} ...")
marbles_in_middle -= marbles_to_take
computer_marbles += marbles_to_take
def play_game():
global marbles_in_middle
global human_marbles
global computer_marbles
# initialize the game state
marbles_in_middle = 27
human_marbles = 0
computer_marbles = 0
print_board()
while True:
if marbles_in_middle == 0:
game_over()
return
elif whose_turn == "human":
human_turn()
print_board()
next_player()
elif whose_turn == "computer":
computer_turn()
print_board()
next_player()
else:
serious_error(f"play_game: unknown player {whose_turn}")
def main():
global whose_turn
welcome_screen()
while True:
choose_first_player()
play_game()
# ask if the user if they want to play again
print()
again = input("Would you like to play again? (y/n) --> ")
if again == "y":
print()
print("Ok, let's play again ...")
print()
else:
print()
print("Ok, thanks for playing ... goodbye!")
print()
return
if __name__ == "__main__":
main()

View File

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

View File

@@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "EvenWins", "EvenWins.vbproj", "{16D44A7A-9C05-4845-8289-3A65A4D978D0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{16D44A7A-9C05-4845-8289-3A65A4D978D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{16D44A7A-9C05-4845-8289-3A65A4D978D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{16D44A7A-9C05-4845-8289-3A65A4D978D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{16D44A7A-9C05-4845-8289-3A65A4D978D0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,8 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>EvenWins</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>16.9</LangVersion>
</PropertyGroup>
</Project>

View File

@@ -1,3 +0,0 @@
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)

View File

@@ -1,197 +0,0 @@
// Flip Flop Game
PrintGameInfo();
bool startNewGame = true;
string[] board = new string[] { "X", "X", "X", "X", "X", "X", "X", "X", "X", "X" };
do
{
int stepsCount = 0;
int lastMove = -1;
int moveIndex;
int gameSum;
double gameEntropyRate = Rnd();
bool toPlay = false;
bool setNewBoard = true;
Print();
Print("HERE IS THE STARTING LINE OF X'S.");
Print();
do
{
bool illegalEntry;
bool equalToLastMove;
if (setNewBoard)
{
PrintNewBoard();
board = new string[] { "X", "X", "X", "X", "X", "X", "X", "X", "X", "X" };
setNewBoard = false;
toPlay = true;
}
stepsCount++;
gameSum = 0;
// Read User's move
do
{
Write("INPUT THE NUMBER? ");
var input = Console.ReadLine();
illegalEntry = !int.TryParse(input, out moveIndex);
if (illegalEntry || moveIndex > 11)
{
illegalEntry = true;
Print("ILLEGAL ENTRY--TRY AGAIN.");
}
}
while (illegalEntry);
if (moveIndex == 11)
{
// Run new game, To start a new game at any point
toPlay = false;
stepsCount = 12;
startNewGame = true;
}
if (moveIndex == 0)
{
// To reset the line to all X, same game
setNewBoard = true;
toPlay = false;
}
if (toPlay)
{
board[moveIndex - 1] = board[moveIndex - 1] == "O" ? "X" : "O";
if (lastMove == moveIndex)
{
equalToLastMove = true;
}
else
{
equalToLastMove = false;
lastMove = moveIndex;
}
do
{
moveIndex = equalToLastMove
? GetMoveIndexWhenEqualeLastMove(moveIndex, gameEntropyRate)
: GetMoveIndex(moveIndex, gameEntropyRate);
board[moveIndex] = board[moveIndex] == "O" ? "X" : "O";
}
while (lastMove == moveIndex && board[moveIndex] == "X");
PrintGameBoard(board);
foreach (var item in board)
{
if (item == "O")
{
gameSum++;
}
}
}
}
while (stepsCount < 12 && gameSum < 10);
if (toPlay)
{
PrintGameResult(gameSum, stepsCount);
Write("DO YOU WANT TO TRY ANOTHER PUZZLE ");
var toContinue = Console.ReadLine();
if (!string.IsNullOrEmpty(toContinue) && toContinue?.ToUpper()[0] == 'N')
{
startNewGame = false;
}
Print();
}
}
while (startNewGame);
void Print(string str = "") => Console.WriteLine(str);
void Write(string value) => Console.Write(value);
string Tab(int pos) => new(' ', pos);
double Rnd() => new Random().NextDouble();
int GetMoveIndex(int moveIndex, double gameEntropyRate)
{
double rate = Math.Tan(gameEntropyRate + moveIndex / gameEntropyRate - moveIndex) - Math.Sin(gameEntropyRate / moveIndex) + 336 * Math.Sin(8 * moveIndex);
return Convert.ToInt32(Math.Floor(10 * (rate - Math.Floor(rate))));
}
int GetMoveIndexWhenEqualeLastMove(int moveIndex, double gameEntropyRate)
{
double rate = 0.592 * (1 / Math.Tan(gameEntropyRate / moveIndex + gameEntropyRate)) / Math.Sin(moveIndex * 2 + gameEntropyRate) - Math.Cos(moveIndex);
return Convert.ToInt32(Math.Floor(10 * (rate - Math.Floor(rate))));
}
void PrintNewBoard()
{
Print("1 2 3 4 5 6 7 8 9 10");
Print("X X X X X X X X X X");
Print();
}
void PrintGameBoard(string[] board)
{
Print("1 2 3 4 5 6 7 8 9 10");
foreach (var item in board)
{
Write($"{item} ");
}
Print();
Print();
}
void PrintGameResult(int gameSum, int stepsCount)
{
if (gameSum == 10)
{
Print($"VERY GOOD. YOU GUESSED IT IN ONLY {stepsCount} GUESSES.");
}
else
{
Print($"TRY HARDER NEXT TIME. IT TOOK YOU {stepsCount} GUESSES.");
}
}
void PrintGameInfo()
{
Print(Tab(32) + "FLIPFLOP");
Print(Tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
Print();
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).");
}

View File

@@ -1,10 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlipFlop", "FlipFlop.csproj", "{192EDAD4-5EF5-4B11-9EB3-B17FFAD0861F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{192EDAD4-5EF5-4B11-9EB3-B17FFAD0861F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{192EDAD4-5EF5-4B11-9EB3-B17FFAD0861F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{192EDAD4-5EF5-4B11-9EB3-B17FFAD0861F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{192EDAD4-5EF5-4B11-9EB3-B17FFAD0861F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {108E5099-D7AA-4260-B587-1B1FE1AF6B54}
EndGlobalSection
EndGlobal

View File

@@ -1,3 +0,0 @@
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/)

View File

@@ -1,287 +0,0 @@
import java.util.Scanner;
import java.lang.Math;
/**
* Game of FlipFlop
* <p>
* Based on the BASIC game of FlipFlop here
* https://github.com/coding-horror/basic-computer-games/blob/main/36%20Flip%20Flop/flipflop.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.
*
* Converted from BASIC to Java by Darren Cardenas.
*/
public class FlipFlop {
private final Scanner scan; // For user input
private enum Step {
RANDOMIZE, INIT_BOARD, GET_NUMBER, ILLEGAL_ENTRY, FLIP_POSITION, SET_X_FIRST, SET_X_SECOND,
GENERATE_R_FIRST, GENERATE_R_SECOND, PRINT_BOARD, QUERY_RETRY
}
public FlipFlop() {
scan = new Scanner(System.in);
} // End of constructor FlipFlop
public void play() {
showIntro();
startGame();
} // End of method play
private static void showIntro() {
System.out.println(" ".repeat(31) + "FLIPFLOP");
System.out.println(" ".repeat(14) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println("");
} // End of method showIntro
private void startGame() {
double mathVal = 0;
double randVal = 0;
double tmpVal = 0;
int index = 0;
int match = 0;
int numFlip = 0;
int numGuesses = 0;
Step nextStep = Step.RANDOMIZE;
String userResponse = "";
String[] board = new String[21];
System.out.println("THE OBJECT OF THIS PUZZLE IS TO CHANGE THIS:");
System.out.println("");
System.out.println("X X X X X X X X X X");
System.out.println("");
System.out.println("TO THIS:");
System.out.println("");
System.out.println("O O O O O O O O O O");
System.out.println("");
System.out.println("BY TYPING THE NUMBER CORRESPONDING TO THE POSITION OF THE");
System.out.println("LETTER ON SOME NUMBERS, ONE POSITION WILL CHANGE, ON");
System.out.println("OTHERS, TWO WILL CHANGE. TO RESET LINE TO ALL X'S, TYPE 0");
System.out.println("(ZERO) AND TO START OVER IN THE MIDDLE OF A GAME, TYPE ");
System.out.println("11 (ELEVEN).");
System.out.println("");
// Begin outer while loop
while (true) {
// Begin switch
switch (nextStep) {
case RANDOMIZE:
randVal = Math.random();
System.out.println("HERE IS THE STARTING LINE OF X'S.");
System.out.println("");
numGuesses = 0;
nextStep = Step.INIT_BOARD;
break;
case INIT_BOARD:
System.out.println("1 2 3 4 5 6 7 8 9 10");
System.out.println("X X X X X X X X X X");
System.out.println("");
// Avoid out of bounds error by starting at zero
for (index = 0; index <= 10; index++) {
board[index] = "X";
}
nextStep = Step.GET_NUMBER;
break;
case GET_NUMBER:
System.out.print("INPUT THE NUMBER? ");
userResponse = scan.nextLine();
try {
numFlip = Integer.parseInt(userResponse);
}
catch (NumberFormatException ex) {
nextStep = Step.ILLEGAL_ENTRY;
break;
}
// Command to start a new game
if (numFlip == 11) {
nextStep = Step.RANDOMIZE;
break;
}
if (numFlip > 11) {
nextStep = Step.ILLEGAL_ENTRY;
break;
}
// Command to reset the board
if (numFlip == 0) {
nextStep = Step.INIT_BOARD;
break;
}
if (match == numFlip) {
nextStep = Step.FLIP_POSITION;
break;
}
match = numFlip;
if (board[numFlip].equals("O")) {
nextStep = Step.SET_X_FIRST;
break;
}
board[numFlip] = "O";
nextStep = Step.GENERATE_R_FIRST;
break;
case ILLEGAL_ENTRY:
System.out.println("ILLEGAL ENTRY--TRY AGAIN.");
nextStep = Step.GET_NUMBER;
break;
case GENERATE_R_FIRST:
mathVal = Math.tan(randVal + numFlip / randVal - numFlip) - Math.sin(randVal / numFlip) + 336
* Math.sin(8 * numFlip);
tmpVal = mathVal - (int)Math.floor(mathVal);
numFlip = (int)(10 * tmpVal);
if (board[numFlip].equals("O")) {
nextStep = Step.SET_X_FIRST;
break;
}
board[numFlip] = "O";
nextStep = Step.PRINT_BOARD;
break;
case SET_X_FIRST:
board[numFlip] = "X";
if (match == numFlip) {
nextStep = Step.GENERATE_R_FIRST;
} else {
nextStep = Step.PRINT_BOARD;
}
break;
case FLIP_POSITION:
if (board[numFlip].equals("O")) {
nextStep = Step.SET_X_SECOND;
break;
}
board[numFlip] = "O";
nextStep = Step.GENERATE_R_SECOND;
break;
case GENERATE_R_SECOND:
mathVal = 0.592 * (1 / Math.tan(randVal / numFlip + randVal)) / Math.sin(numFlip * 2 + randVal)
- Math.cos(numFlip);
tmpVal = mathVal - (int)mathVal;
numFlip = (int)(10 * tmpVal);
if (board[numFlip].equals("O")) {
nextStep = Step.SET_X_SECOND;
break;
}
board[numFlip] = "O";
nextStep = Step.PRINT_BOARD;
break;
case SET_X_SECOND:
board[numFlip] = "X";
if (match == numFlip) {
nextStep = Step.GENERATE_R_SECOND;
break;
}
nextStep = Step.PRINT_BOARD;
break;
case PRINT_BOARD:
System.out.println("1 2 3 4 5 6 7 8 9 10");
for (index = 1; index <= 10; index++) {
System.out.print(board[index] + " ");
}
numGuesses++;
System.out.println("");
for (index = 1; index <= 10; index++) {
if (!board[index].equals("O")) {
nextStep = Step.GET_NUMBER;
break;
}
}
if (nextStep == Step.GET_NUMBER) {
break;
}
if (numGuesses > 12) {
System.out.println("TRY HARDER NEXT TIME. IT TOOK YOU " + numGuesses + " GUESSES.");
} else {
System.out.println("VERY GOOD. YOU GUESSED IT IN ONLY " + numGuesses + " GUESSES.");
}
nextStep = Step.QUERY_RETRY;
break;
case QUERY_RETRY:
System.out.print("DO YOU WANT TO TRY ANOTHER PUZZLE? ");
userResponse = scan.nextLine();
if (userResponse.toUpperCase().charAt(0) == 'N') {
return;
}
System.out.println("");
nextStep = Step.RANDOMIZE;
break;
default:
System.out.println("INVALID STEP");
nextStep = Step.QUERY_RETRY;
break;
} // End of switch
} // End outer while loop
} // End of method startGame
public static void main(String[] args) {
FlipFlop game = new FlipFlop();
game.play();
} // End of method main
} // End of class FlipFlop

View File

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

View File

@@ -1,3 +0,0 @@
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

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

View File

@@ -1,144 +0,0 @@
// FLIPFLOP
//
// 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 as = [];
// Main program
async function main()
{
print(tab(32) + "FLIPFLOP\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
print("\n");
// *** Created by Michael Cass
print("THE OBJECT OF THIS PUZZLE IS TO CHANGE THIS:\n");
print("\n");
print("X X X X X X X X X X\n");
print("\n");
print("TO THIS:\n");
print("\n");
print("O O O O O O O O O O\n");
print("\n");
print("BY TYPING THE NUMBER CORRESPONDING TO THE POSITION OF THE\n");
print("LETTER ON SOME NUMBERS, ONE POSITION WILL CHANGE, ON\n");
print("OTHERS, TWO WILL CHANGE. TO RESET LINE TO ALL X'S, TYPE 0\n");
print("(ZERO) AND TO START OVER IN THE MIDDLE OF A GAME, TYPE \n");
print("11 (ELEVEN).\n");
print("\n");
while (1) {
start = 1;
do {
z = 1;
if (start == 1) {
m = 0;
q = Math.random();
print("HERE IS THE STARTING LINE OF X'S.\n");
print("\n");
c = 0;
start = 2;
}
if (start == 2) {
print("1 2 3 4 5 6 7 8 9 10\n");
print("X X X X X X X X X X\n");
print("\n");
for (x = 1; x <= 10; x++)
as[x] = "X";
start = 0;
}
print("INPUT THE NUMBER");
while (1) {
n = parseInt(await input());
if (n >= 0 && n <= 11)
break;
print("ILLEGAL ENTRY--TRY AGAIN.\n");
}
if (n == 11) {
start = 1;
continue;
}
if (n == 0) {
start = 2;
continue;
}
if (m != n) {
m = n;
as[n] = (as[n] == "O" ? "X" : "O");
do {
r = Math.tan(q + n / q - n) - Math.sin(q / n) + 336 * Math.sin(8 * n);
n = r - Math.floor(r);
n = Math.floor(10 * n);
as[n] = (as[n] == "O" ? "X" : "O");
} while (m == n) ;
} else {
as[n] = (as[n] == "O" ? "X" : "O");
do {
r = 0.592 * (1 / Math.tan(q / n + q)) / Math.sin(n * 2 + q) - Math.cos(n);
n = r - Math.floor(r);
n = Math.floor(10 * n);
as[n] = (as[n] == "O" ? "X" : "O");
} while (m == n) ;
}
print("1 2 3 4 5 6 7 8 9 10\n");
for (z = 1; z <= 10; z++)
print(as[z] + " ");
c++;
print("\n");
for (z = 1; z <= 10; z++) {
if (as[z] != "O")
break;
}
} while (z <= 10) ;
if (c <= 12) {
print("VERY GOOD. YOU GUESSED IT IN ONLY " + c + " GUESSES.\n");
} else {
print("TRY HARDER NEXT TIME. IT TOOK YOU " + c + " GUESSES.\n");
}
print("DO YOU WANT TO TRY ANOTHER PUZZLE");
str = await input();
if (str.substr(0, 1) == "N")
break;
}
print("\n");
}
main();

View File

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

View File

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

View File

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

View File

@@ -1,129 +0,0 @@
# Flip Flop
#
# The object of this game is to change a row of ten X's
# X X X X X X X X X X
# to a row of ten O's:
# O O O O O O O O O O
# by typing in a number corresponding
# to the position of an "X" in the line. On
# some numbers one position will
# change while on other numbers, two
# will change. For example, inputting a 3
# may reverse the X and O in position 3,
# but it might possibly reverse some
# other position too! You ought to be able
# to change all 10 in 12 or fewer
# moves. Can you figure out a good win-
# ning strategy?
# To reset the line to all X's (same
# game), type 0 (zero). To start a new
# game at any point, type 11.
# The original author of this game was
# Michael Kass of New Hyde Park, New
# York.
import math
import random
from typing import Callable, List, Tuple
flip_dict = {"X": "O", "O": "X"}
def flip_bits(
row: List[str], m: int, n: int, r_function: Callable[[int], float]
) -> Tuple[List[str], int]:
"""
Function that flips the positions at the computed steps
"""
while m == n:
r = r_function(n)
n = r - int(math.floor(r))
n = int(10 * n)
if row[n] == "X":
row[n] = "O"
break
elif row[n] == "O":
row[n] = "X"
return row, n
def print_instructions():
print(" " * 32 + "FLIPFLOP")
print(" " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
print("\n" * 2)
print("THE OBJECT OF THIS PUZZLE IS TO CHANGE THIS:\n")
print("X X X X X X X X X X\n")
print("TO THIS:\n")
print("O O O O O O O O O O\n")
print("BY TYPING TH 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).\n")
def main():
q = random.random()
print("HERE IS THE STARTING LINE OF X'S.\n")
# We add an extra 0-th item because this sometimes is set to something
# but we never check what it is for completion of the puzzle
row = [""] + ["X"] * 10
counter_turns = 0
n = -1
legal_move = True
while row[1:] != ["O"] * 10:
if legal_move:
print(" ".join([str(i) for i in range(1, 11)]))
print(" ".join(row[1:]) + "\n")
m = input("INPUT THE NUMBER\n")
try:
m = int(m)
if m > 11 or m < 0:
raise ValueError()
except ValueError:
print("ILLEGAL ENTRY--TRY AGAIN")
legal_move = False
continue
legal_move = True
if m == 11:
# completely reset the puzzle
counter_turns = 0
row = [""] + ["X"] * 10
q = random.random()
continue
elif m == 0:
# reset the board, but not the counter or the random number
row = [""] + ["X"] * 10
elif m == n:
row[n] = flip_dict[row[n]]
r_function = lambda n_t: 0.592 * (1 / math.tan(q / n_t + q)) / math.sin(
n_t * 2 + q
) - math.cos(n_t)
row, n = flip_bits(row, m, n, r_function)
else:
n = m
row[n] = flip_dict[row[n]]
r_function = lambda n_t: (
math.tan(q + n_t / q - n_t)
- math.sin(n_t * 2 + q)
+ 336 * math.sin(8 * n_t)
)
row, n = flip_bits(row, m, n, r_function)
counter_turns += 1
print()
if counter_turns <= 12:
print(f"VERY GOOD. YOU GUESSED IT IN ONLY {counter_turns} GUESSES.")
else:
print(f"TRY HARDER NEXT TIME. IT TOOK YOU {counter_turns} GUESSES.")
return
if __name__ == "__main__":
print_instructions()
another = ""
while another != "NO":
main()
another = input("DO YOU WANT TO TRY ANOTHER PUZZLE\n")

View File

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

View File

@@ -1,162 +0,0 @@
#A class representing the internal state of a single game of flip flop
# state represents the list of X's (A in the original code)
# guesses represents the number of guesses the user has made (C in the original code)
# seed represents the random seed for an instance of the game (Q in the original code)
Game = Struct.new(:state, :guesses, :seed) do
#The original BASIC program used 1 indexed arrays while Ruby has 0-indexed arrays.
#We can't use 0 indexed arrays for the flip functions or we'll get divide by zero errors.
#These convenience functions allow us to modify and access internal game state in a 1-indexed fashion
def flip_letter(letter_number)
index = letter_number -1
if self.state[index] == 'X'
self.state[index] = 'O'
else
self.state[index] = 'X'
end
end
def letter_at(letter_number)
self.state[letter_number - 1]
end
end
def print_welcome
puts 'FLIPFLOP'.center(72)
puts 'CREATIVE COMPUTING MORRISTOWN, NEW JERSEY'.center(72)
puts <<~EOS
THE OBJECT OF THIS PUZZLE IS TO CHANGE THIS:
X X X X X X X X X X
TO THIS:
O O O O O O O O O O
BY TYPING THE NUMBER CORRESPONDING TO THE POSITION OF THE
LETTER ON SOME NUMBERS, ONE POSITION WILL CHANGE, ON
OTHERS, TWO WILL CHANGE. TO RESET LINE TO ALL X'S, TYPE 0
(ZERO) AND TO START OVER IN THE MIDDLE OF A GAME, TYPE
11 (ELEVEN).
EOS
end
def print_starting_message
puts <<~EOS
HERE IS THE STARTING LINE OF X'S.
1 2 3 4 5 6 7 8 9 10
X X X X X X X X X X
EOS
end
#Create a new game with [X,X,X,X,X,X,X,X,X,X] as the state
#0 as the number of guesses and a random seed between 0 and 1
def generate_new_game
Game.new(Array.new(10, 'X'), 0, rand())
end
#Given a game, an index, and a shuffle function, flip one or more letters
def shuffle_board(game, index, shuffle_function)
n = method(shuffle_function).call(game, index)
if game.letter_at(n) == "O"
game.flip_letter(n)
if index == n
n = shuffle_board(game, index, shuffle_function)
end
else
game.flip_letter(n)
end
return n
end
#Shuffle logic copied from original BASIC code
def shuffle_function1(game, index)
r = Math.tan(game.seed + index / game.seed - index) - Math.sin(game.seed / index) + 336 * Math.sin(8 * index)
n = r - r.floor
(10 * n).floor
end
def shuffle_function2(game, index)
r = 0.592 * (1/ Math.tan(game.seed / index + game.seed)) / Math.sin(index * 2 + game.seed) - Math.cos(index)
n = r - r.floor
(10 * n)
end
def play_game
print_starting_message
game = generate_new_game
working_index = nil
loop do
puts "INPUT THE NUMBER"
input = gets.chomp.downcase
#See if the user input a valid integer, fail otherwise
if numeric_input = Integer(input, exception: false)
#If 11 is entered, we're done with this version of the game
if numeric_input == 11
return :restart
end
if numeric_input > 11
puts 'ILLEGAL ENTRY--TRY AGAIN.'
next #illegal entries don't count towards your guesses
end
if working_index == numeric_input
game.flip_letter(numeric_input)
working_index = shuffle_board(game, numeric_input, :shuffle_function2)
#If 0 is entered, we want to reset the state, but not the random seed or number of guesses and keep playing
elsif numeric_input == 0
game.state = Array.new(10, 'X')
elsif game.letter_at(numeric_input) == "O"
game.flip_letter(numeric_input)
if numeric_input == working_index
working_index = shuffle_board(game, numeric_input, :shuffle_function1)
end
else
game.flip_letter(numeric_input)
working_index = shuffle_board(game, numeric_input, :shuffle_function1)
end
else
puts 'ILLEGAL ENTRY--TRY AGAIN.'
next #illegal entries don't count towards your guesses
end
game.guesses += 1
puts '1 2 3 4 5 6 7 8 9 10'
puts game.state.join(' ')
if game.state.all? { |x| x == 'O' }
if game.guesses > 12
puts "TRY HARDER NEXT TIME. IT TOOK YOU #{game.guesses} GUESSES."
else
puts "VERY GOOD. YOU GUESSED IT IN ONLY #{game.guesses} GUESSES."
end
#game is complete
return
end
end
end
#Execution starts
print_welcome
loop do
result = play_game
if result == :restart
next
end
puts 'DO YOU WANT TO TRY ANOTHER PUZZLE'
if gets.chomp.downcase[0] == 'n'
break
end
end

View File

@@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "FlipFlop", "FlipFlop.vbproj", "{4A5887DD-FA0C-47EE-B3A2-E334DCE3544C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4A5887DD-FA0C-47EE-B3A2-E334DCE3544C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A5887DD-FA0C-47EE-B3A2-E334DCE3544C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A5887DD-FA0C-47EE-B3A2-E334DCE3544C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A5887DD-FA0C-47EE-B3A2-E334DCE3544C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,8 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<RootNamespace>FlipFlop</RootNamespace>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>16.9</LangVersion>
</PropertyGroup>
</Project>

View File

@@ -1,3 +0,0 @@
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)

View File

@@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<LangVersion>10</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -1,22 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Football", "Football.csproj", "{092442FA-EA04-4A80-AB12-138E18CD480A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{092442FA-EA04-4A80-AB12-138E18CD480A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{092442FA-EA04-4A80-AB12-138E18CD480A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{092442FA-EA04-4A80-AB12-138E18CD480A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{092442FA-EA04-4A80-AB12-138E18CD480A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -1,3 +0,0 @@
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/)

View File

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

View File

@@ -1,3 +0,0 @@
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

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

View File

@@ -1,504 +0,0 @@
// FOOTBALL
//
// 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 player_data = [17,8,4,14,19,3,10,1,7,11,15,9,5,20,13,18,16,2,12,6,
20,2,17,5,8,18,12,11,1,4,19,14,10,7,9,15,6,13,16,3];
var aa = [];
var ba = [];
var ca = [];
var ha = [];
var ta = [];
var wa = [];
var xa = [];
var ya = [];
var za = [];
var ms = [];
var da = [];
var ps = [, "PITCHOUT","TRIPLE REVERSE","DRAW","QB SNEAK","END AROUND",
"DOUBLE REVERSE","LEFT SWEEP","RIGHT SWEEP","OFF TACKLE",
"WISHBONE OPTION","FLARE PASS","SCREEN PASS",
"ROLL OUT OPTION","RIGHT CURL","LEFT CURL","WISHBONE OPTION",
"SIDELINE PASS","HALF-BACK OPTION","RAZZLE-DAZZLE","BOMB!!!!"];
var p;
var t;
function field_headers()
{
print("TEAM 1 [0 10 20 30 40 50 60 70 80 90");
print(" 100] TEAM 2\n");
print("\n");
}
function separator()
{
str = "";
for (x = 1; x <= 72; x++)
str += "+";
print(str + "\n");
}
function show_ball()
{
print(tab(da[t] + 5 + p / 2) + ms[t] + "\n");
field_headers();
}
function show_scores()
{
print("\n");
print("TEAM 1 SCORE IS " + ha[1] + "\n");
print("TEAM 2 SCORE IS " + ha[2] + "\n");
print("\n");
if (ha[t] >= e) {
print("TEAM " + t + " WINS*******************");
return true;
}
return false;
}
function loss_posession() {
print("\n");
print("** LOSS OF POSSESSION FROM TEAM " + t + " TO TEAM " + ta[t] + "\n");
print("\n");
separator();
print("\n");
t = ta[t];
}
function touchdown() {
print("\n");
print("TOUCHDOWN BY TEAM " + t + " *********************YEA TEAM\n");
q = 7;
g = Math.random();
if (g <= 0.1) {
q = 6;
print("EXTRA POINT NO GOOD\n");
} else {
print("EXTRA POINT GOOD\n");
}
ha[t] = ha[t] + q;
}
// Main program
async function main()
{
print(tab(32) + "FOOTBALL\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
print("\n");
print("\n");
print("\n");
print("PRESENTING N.F.U. FOOTBALL (NO FORTRAN USED)\n");
print("\n");
print("\n");
while (1) {
print("DO YOU WANT INSTRUCTIONS");
str = await input();
if (str == "YES" || str == "NO")
break;
}
if (str == "YES") {
print("THIS IS A FOOTBALL GAME FOR TWO TEAMS IN WHICH PLAYERS MUST\n");
print("PREPARE A TAPE WITH A DATA STATEMENT (1770 FOR TEAM 1,\n");
print( "1780 FOR TEAM 2) IN WHICH EACH TEAM SCRAMBLES NOS. 1-20\n");
print("THESE NUMBERS ARE THEN ASSIGNED TO TWENTY GIVEN PLAYS.\n");
print("A LIST OF NOS. AND THEIR PLAYS IS PROVIDED WITH\n");
print("BOTH TEAMS HAVING THE SAME PLAYS. THE MORE SIMILAR THE\n");
print("PLAYS THE LESS YARDAGE GAINED. SCORES ARE GIVEN\n");
print("WHENEVER SCORES ARE MADE. SCORES MAY ALSO BE OBTAINED\n");
print("BY INPUTTING 99,99 FOR PLAY NOS. TO PUNT OR ATTEMPT A\n");
print("FIELD GOAL, INPUT 77,77 FOR PLAY NUMBERS. QUESTIONS WILL BE\n");
print("ASKED THEN. ON 4TH DOWN, YOU WILL ALSO BE ASKED WHETHER\n");
print("YOU WANT TO PUNT OR ATTEMPT A FIELD GOAL. IF THE ANSWER TO\n");
print("BOTH QUESTIONS IS NO IT WILL BE ASSUMED YOU WANT TO\n");
print("TRY AND GAIN YARDAGE. ANSWER ALL QUESTIONS YES OR NO.\n");
print("THE GAME IS PLAYED UNTIL PLAYERS TERMINATE (CONTROL-C).\n");
print("PLEASE PREPARE A TAPE AND RUN.\n");
}
print("\n");
print("PLEASE INPUT SCORE LIMIT ON GAME");
e = parseInt(await input());
for (i = 1; i <= 40; i++) {
if (i <= 20) {
aa[player_data[i - 1]] = i;
} else {
ba[player_data[i - 1]] = i - 20;
}
ca[i] = player_data[i - 1];
}
l = 0;
t = 1;
do {
print("TEAM " + t + " PLAY CHART\n");
print("NO. PLAY\n");
for (i = 1; i <= 20; i++) {
str = "" + ca[i + l];
while (str.length < 6)
str += " ";
str += ps[i];
print(str + "\n");
}
l += 20;
t = 2;
print("\n");
print("TEAR OFF HERE----------------------------------------------\n");
for (x = 1; x <= 11; x++)
print("\n");
} while (l == 20) ;
da[1] = 0;
da[2] = 3;
ms[1] = "--->";
ms[2] = "<---";
ha[1] = 0;
ha[2] = 0;
ta[1] = 2;
ta[2] = 1;
wa[1] = -1;
wa[2] = 1;
xa[1] = 100;
xa[2] = 0;
ya[1] = 1;
ya[2] = -1;
za[1] = 0;
za[2] = 100;
p = 0;
field_headers();
print("TEAM 1 DEFEND 0 YD GOAL -- TEAM 2 DEFENDS 100 YD GOAL.\n");
t = Math.floor(2 * Math.random() + 1);
print("\n");
print("THE COIN IS FLIPPED\n");
routine = 1;
while (1) {
if (routine <= 1) {
p = xa[t] - ya[t] * 40;
separator();
print("\n");
print("TEAM " + t + " RECEIVES KICK-OFF\n");
k = Math.floor(26 * Math.random() + 40);
}
if (routine <= 2) {
p = p - ya[t] * k;
}
if (routine <= 3) {
if (wa[t] * p >= za[t] + 10) {
print("\n");
print("BALL WENT OUT OF ENDZONE --AUTOMATIC TOUCHBACK--\n");
p = za[t] - wa[t] * 20;
if (routine <= 4)
routine = 5;
} else {
print("BALL WENT " + k + " YARDS. NOW ON " + p + "\n");
show_ball();
}
}
if (routine <= 4) {
while (1) {
print("TEAM " + t + " DO YOU WANT TO RUNBACK");
str = await input();
if (str == "YES" || str == "NO")
break;
}
if (str == "YES") {
k = Math.floor(9 * Math.random() + 1);
r = Math.floor(((xa[t] - ya[t] * p + 25) * Math.random() - 15) / k);
p = p - wa[t] * r;
print("\n");
print("RUNBACK TEAM " + t + " " + r + " YARDS\n");
g = Math.random();
if (g < 0.25) {
loss_posession();
routine = 4;
continue;
} else if (ya[t] * p >= xa[t]) {
touchdown();
if (show_scores())
return;
t = ta[t];
routine = 1;
continue;
} else if (wa[t] * p >= za[t]) {
print("\n");
print("SAFETY AGAINST TEAM " + t + " **********************OH-OH\n");
ha[ta[t]] = ha[ta[t]] + 2;
if (show_scores())
return;
print("TEAM " + t + " DO YOU WANT TO PUNT INSTEAD OF A KICKOFF");
str = await input();
p = za[t] - wa[t] * 20;
if (str == "YES") {
print("\n");
print("TEAM " + t + " WILL PUNT\n");
g = Math.random();
if (g < 0.25) {
loss_posession();
routine = 4;
continue;
}
print("\n");
separator();
k = Math.floor(25 * Math.random() + 35);
t = ta[t];
routine = 2;
continue;
}
touchdown();
if (show_scores())
return;
t = ta[t];
routine = 1;
continue;
} else {
routine = 5;
continue;
}
} else if (str == "NO") {
if (wa[t] * p >= za[t])
p = za[t] - wa[t] * 20;
}
}
if (routine <= 5) {
d = 1;
s = p;
}
if (routine <= 6) {
str = "";
for (i = 1; i <= 72; i++)
str += "=";
print(str + "\n");
print("TEAM " + t + " DOWN " + d + " ON " + p + "\n");
if (d == 1) {
if (ya[t] * (p + ya[t] * 10) >= xa[t])
c = 8;
else
c = 4;
}
if (c != 8) {
print(tab(27) + (10 - (ya[t] * p - ya[t] * s)) + " YARDS TO 1ST DOWN\n");
} else {
print(tab(27) + (xa[t] - ya[t] * p) + " YARDS\n");
}
show_ball();
if (d == 4)
routine = 8;
}
if (routine <= 7) {
u = Math.floor(3 * Math.random() - 1);
while (1) {
print("INPUT OFFENSIVE PLAY, DEFENSIVE PLAY");
str = await input();
if (t == 1) {
p1 = parseInt(str);
p2 = parseInt(str.substr(str.indexOf(",") + 1));
} else {
p2 = parseInt(str);
p1 = parseInt(str.substr(str.indexOf(",") + 1));
}
if (p1 == 99) {
if (show_scores())
return;
if (p1 == 99)
continue;
}
if (p1 < 1 || p1 > 20 || p2 < 1 || p2 > 20) {
print("ILLEGAL PLAY NUMBER, CHECK AND\n");
continue;
}
break;
}
}
if (d == 4 || p1 == 77) {
while (1) {
print("DOES TEAM " + t + " WANT TO PUNT");
str = await input();
if (str == "YES" || str == "NO")
break;
}
if (str == "YES") {
print("\n");
print("TEAM " + t + " WILL PUNT\n");
g = Math.random();
if (g < 0.25) {
loss_posession();
routine = 4;
continue;
}
print("\n");
separator();
k = Math.floor(25 * Math.random() + 35);
t = ta[t];
routine = 2;
continue;
}
while (1) {
print("DOES TEAM " + t + " WANT TO ATTEMPT A FIELD GOAL");
str = await input();
if (str == "YES" || str == "NO")
break;
}
if (str == "YES") {
print("\n");
print("TEAM " + t + " WILL ATTEMPT A FIELD GOAL\n");
g = Math.random();
if (g < 0.025) {
loss_posession();
routine = 4;
continue;
} else {
f = Math.floor(35 * Math.random() + 20);
print("\n");
print("KICK IS " + f + " YARDS LONG\n");
p = p - wa[t] * f;
g = Math.random();
if (g < 0.35) {
print("BALL WENT WIDE\n");
} else if (ya[t] * p >= xa[t]) {
print("FIELD GOLD GOOD FOR TEAM " + t + " *********************YEA");
q = 3;
ha[t] = ha[t] + q;
if (show_scores())
return;
t = ta[t];
routine = 1;
continue;
}
print("FIELD GOAL UNSUCCESFUL TEAM " + t + "-----------------TOO BAD\n");
print("\n");
separator();
if (ya[t] * p < xa[t] + 10) {
print("\n");
print("BALL NOW ON " + p + "\n");
t = ta[t];
show_ball();
routine = 4;
continue;
} else {
t = ta[t];
routine = 3;
continue;
}
}
} else {
routine = 7;
continue;
}
}
y = Math.floor(Math.abs(aa[p1] - ba[p2]) / 19 * ((xa[t] - ya[t] * p + 25) * Math.random() - 15));
print("\n");
if (t == 1 && aa[p1] < 11 || t == 2 && ba[p2] < 11) {
print("THE BALL WAS RUN\n");
} else if (u == 0) {
print("PASS INCOMPLETE TEAM " + t + "\n");
y = 0;
} else {
g = Math.random();
if (g <= 0.025 && y > 2) {
print("PASS COMPLETED\n");
} else {
print("QUARTERBACK SCRAMBLED\n");
}
}
p = p - wa[t] * y;
print("\n");
print("NET YARDS GAINED ON DOWN " + d + " ARE " + y + "\n");
g = Math.random();
if (g <= 0.025) {
loss_posession();
routine = 4;
continue;
} else if (ya[t] * p >= xa[t]) {
touchdown();
if (show_scores())
return;
t = ta[t];
routine = 1;
continue;
} else if (wa[t] * p >= za[t]) {
print("\n");
print("SAFETY AGAINST TEAM " + t + " **********************OH-OH\n");
ha[ta[t]] = ha[ta[t]] + 2;
if (show_scores())
return;
print("TEAM " + t + " DO YOU WANT TO PUNT INSTEAD OF A KICKOFF");
str = await input();
p = za[t] - wa[t] * 20;
if (str == "YES") {
print("\n");
print("TEAM " + t + " WILL PUNT\n");
g = Math.random();
if (g < 0.25) {
loss_posession();
routine = 4;
continue;
}
print("\n");
separator();
k = Math.floor(25 * Math.random() + 35);
t = ta[t];
routine = 2;
continue;
}
touchdown();
if (show_scores())
return;
t = ta[t];
routine = 1;
} else if (ya[t] * p - ya[t] * s >= 10) {
routine = 5;
} else {
d++;
if (d != 5) {
routine = 6;
} else {
print("\n");
print("CONVERSION UNSUCCESSFUL TEAM " + t + "\n");
t = ta[t];
print("\n");
separator();
routine = 5;
}
}
}
}
main();

Some files were not shown because too many files have changed in this diff Show More