Removed spaces from top-level directory names.

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

7
82_Stars/README.md Normal file
View File

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

View File

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

34
82_Stars/csharp/Stars.sln Normal file
View File

@@ -0,0 +1,34 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
MinimumVisualStudioVersion = 15.0.26124.0
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Stars", "Stars\Stars.csproj", "{5832C21C-4DE5-475E-893D-745DA15F1AAC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Debug|x64.ActiveCfg = Debug|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Debug|x64.Build.0 = Debug|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Debug|x86.ActiveCfg = Debug|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Debug|x86.Build.0 = Debug|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Release|Any CPU.Build.0 = Release|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Release|x64.ActiveCfg = Release|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Release|x64.Build.0 = Release|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Release|x86.ActiveCfg = Release|Any CPU
{5832C21C-4DE5-475E-893D-745DA15F1AAC}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@@ -0,0 +1,94 @@
using System;
namespace Stars
{
internal class Game
{
private readonly int _maxNumber;
private readonly int _maxGuessCount;
private readonly Random _random;
public Game(int maxNumber, int maxGuessCount)
{
_maxNumber = maxNumber;
_maxGuessCount = maxGuessCount;
_random = new Random();
}
internal void DisplayInstructions()
{
if (Input.GetString("Do you want instructions? ").Equals("N", StringComparison.InvariantCultureIgnoreCase))
{
return;
}
Console.WriteLine($"I am thinking of a number between 1 and {_maxNumber}.");
Console.WriteLine("Try to guess my number. After you guess, I");
Console.WriteLine("will type one or more stars (*). The more");
Console.WriteLine("stars I type, the close you are to my number.");
Console.WriteLine("One star (*) means far away, seven stars (*******)");
Console.WriteLine($"means really close! You get {_maxGuessCount} guesses.");
}
internal void Play()
{
Console.WriteLine();
Console.WriteLine();
var target = _random.Next(_maxNumber) + 1;
Console.WriteLine("Ok, I am thinking of a number. Start guessing.");
AcceptGuesses(target);
}
private void AcceptGuesses(int target)
{
for (int guessCount = 1; guessCount <= _maxGuessCount; guessCount++)
{
Console.WriteLine();
var guess = Input.GetNumber("Your guess? ");
if (guess == target)
{
DisplayWin(guessCount);
return;
}
DisplayStars(target, guess);
}
DisplayLoss(target);
}
private static void DisplayStars(int target, float guess)
{
var stars = Math.Abs(guess - target) switch
{
>= 64 => "*",
>= 32 => "**",
>= 16 => "***",
>= 8 => "****",
>= 4 => "*****",
>= 2 => "******",
_ => "*******"
};
Console.WriteLine(stars);
}
private static void DisplayWin(int guessCount)
{
Console.WriteLine();
Console.WriteLine(new string('*', 79));
Console.WriteLine();
Console.WriteLine($"You got it in {guessCount} guesses!!! Let's play again...");
}
private void DisplayLoss(int target)
{
Console.WriteLine();
Console.WriteLine($"Sorry, that's {_maxGuessCount} guesses. The number was {target}.");
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
namespace Stars
{
internal static class Input
{
// Float, because that's what the BASIC input operation returns
internal static float GetNumber(string prompt)
{
Console.Write(prompt);
while (true)
{
var response = Console.ReadLine();
if (float.TryParse(response, out var value))
{
return value;
}
Console.WriteLine("!Number expected - retry input line");
Console.Write("? ");
}
}
internal static string GetString(string prompt)
{
Console.Write(prompt);
return Console.ReadLine();
}
}
}

View File

@@ -0,0 +1,30 @@
using System;
namespace Stars
{
class Program
{
static void Main(string[] args)
{
DisplayTitle();
var game = new Game(maxNumber: 100, maxGuessCount: 7);
game.DisplayInstructions();
while (true)
{
game.Play();
}
}
private static void DisplayTitle()
{
Console.WriteLine(" Stars");
Console.WriteLine(" Creative Computing Morristown, New Jersey");
Console.WriteLine();
Console.WriteLine();
Console.WriteLine();
}
}
}

View File

@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>

3
82_Stars/java/README.md Normal file
View File

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

View File

@@ -0,0 +1,242 @@
import java.util.Arrays;
import java.util.Scanner;
/**
* Game of Stars
*
* Based on the Basic game of Stars here
* https://github.com/coding-horror/basic-computer-games/blob/main/82%20Stars/stars.bas
*
* 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 Stars {
public static final int HIGH_NUMBER_RANGE = 100;
public static final int MAX_GUESSES = 7;
private enum GAME_STATE {
STARTING,
INSTRUCTIONS,
START_GAME,
GUESSING,
WON,
LOST,
GAME_OVER
}
// Used for keyboard input
private final Scanner kbScanner;
// Current game state
private GAME_STATE gameState;
// Players guess count;
private int playerTotalGuesses;
// Players current guess
private int playerCurrentGuess;
// Computers random number
private int computersNumber;
public Stars() {
gameState = GAME_STATE.STARTING;
// Initialise kb scanner
kbScanner = new Scanner(System.in);
}
/**
* Main game loop
*
*/
public void play() {
do {
switch (gameState) {
// Show an introduction the first time the game is played.
case STARTING:
intro();
gameState = GAME_STATE.INSTRUCTIONS;
break;
// Ask if instructions are needed and display if yes
case INSTRUCTIONS:
if(yesEntered(displayTextAndGetInput("DO YOU WANT INSTRUCTIONS? "))) {
instructions();
}
gameState = GAME_STATE.START_GAME;
break;
// Generate computers number for player to guess, etc.
case START_GAME:
init();
System.out.println("OK, I AM THINKING OF A NUMBER, START GUESSING.");
gameState = GAME_STATE.GUESSING;
break;
// Player guesses the number until they get it or run out of guesses
case GUESSING:
playerCurrentGuess = playerGuess();
// Check if the player guessed the number
if(playerCurrentGuess == computersNumber) {
gameState = GAME_STATE.WON;
} else {
// incorrect guess
showStars();
playerTotalGuesses++;
// Ran out of guesses?
if (playerTotalGuesses > MAX_GUESSES) {
gameState = GAME_STATE.LOST;
}
}
break;
// Won game.
case WON:
System.out.println(stars(79));
System.out.println("YOU GOT IT IN " + playerTotalGuesses
+ " GUESSES!!! LET'S PLAY AGAIN...");
gameState = GAME_STATE.START_GAME;
break;
// Lost game by running out of guesses
case LOST:
System.out.println("SORRY, THAT'S " + MAX_GUESSES
+ " GUESSES. THE NUMBER WAS " + computersNumber);
gameState = GAME_STATE.START_GAME;
break;
}
// Endless loop since the original code did not allow the player to exit
} while (gameState != GAME_STATE.GAME_OVER);
}
/**
* Shows how close a players guess is to the computers number by
* showing a series of stars - the more stars the closer to the
* number.
*
*/
private void showStars() {
int d = Math.abs(playerCurrentGuess - computersNumber);
int starsToShow;
if(d >=64) {
starsToShow = 1;
} else if(d >=32) {
starsToShow = 2;
} else if (d >= 16) {
starsToShow = 3;
} else if (d >=8) {
starsToShow = 4;
} else if( d>= 4) {
starsToShow = 5;
} else if(d>= 2) {
starsToShow = 6;
} else {
starsToShow = 7;
}
System.out.println(stars(starsToShow));
}
/**
* Show a number of stars (asterisks)
* @param number the number of stars needed
* @return the string encoded with the number of required stars
*/
private String stars(int number) {
char[] stars = new char[number];
Arrays.fill(stars, '*');
return new String(stars);
}
/**
* Initialise variables before each new game
*
*/
private void init() {
playerTotalGuesses = 1;
computersNumber = randomNumber();
}
public void instructions() {
System.out.println("I AM THINKING OF A WHOLE NUMBER FROM 1 TO " + HIGH_NUMBER_RANGE);
System.out.println("TRY TO GUESS MY NUMBER. AFTER YOU GUESS, I");
System.out.println("WILL TYPE ONE OR MORE STARS (*). THE MORE");
System.out.println("STARS I TYPE, THE CLOSER YOU ARE TO MY NUMBER.");
System.out.println("ONE STAR (*) MEANS FAR AWAY, SEVEN STARS (*******)");
System.out.println("MEANS REALLY CLOSE! YOU GET " + MAX_GUESSES + " GUESSES.");
}
public void intro() {
System.out.println("STARS");
System.out.println("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
System.out.println();
}
/**
* Get players guess from kb
*
* @return players guess as an int
*/
private int playerGuess() {
return Integer.parseInt((displayTextAndGetInput("YOUR GUESS? ")));
}
/**
* 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) {
// Cycle through the variable number of values and test each
for(String val:values) {
if(text.equalsIgnoreCase(val)) {
return true;
}
}
// no matches
return false;
}
/*
* 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();
}
/**
* Generate random number
*
* @return random number
*/
private int randomNumber() {
return (int) (Math.random()
* (HIGH_NUMBER_RANGE) + 1);
}
}

View File

@@ -0,0 +1,9 @@
import java.lang.reflect.AnnotatedType;
public class StarsGame {
public static void main(String[] args) {
Stars stars = new Stars();
stars.play();
}
}

View File

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

View File

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

View File

@@ -0,0 +1,108 @@
// STARS
//
// Converted from BASIC to Javascript by Qursch
//
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 guesses = 7;
var limit = 100;
// Main program
async function main()
{
print(tab(33) + "STARS\n");
print(tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY\n");
print("\n\n\n");
// Instructions
print("DO YOU WANT INSTRUCTIONS? (Y/N)");
var instructions = await input();
if(instructions.toLowerCase()[0] == "y") {
print(`I AM THINKING OF A WHOLE NUMBER FROM 1 TO ${limit}\n`);
print("TRY TO GUESS MY NUMBER. AFTER YOU GUESS, I\n");
print("WILL TYPE ONE OR MORE STARS (*). THE MORE\n");
print("STARS I TYPE, THE CLOSER YOU ARE TO MY NUMBER.\n");
print("ONE STAR (*) MEANS FAR AWAY, SEVEN STARS (*******)\n");
print(`MEANS REALLY CLOSE! YOU GET ${guesses} GUESSES.\n\n\n`);
}
// Game loop
while (true) {
var randomNum = Math.floor(Math.random() * limit) + 1;
var loss = true;
print("\nOK, I AM THINKING OF A NUMBER, START GUESSING.\n\n");
for(var guessNum=1; guessNum <= guesses; guessNum++) {
// Input guess
print("YOUR GUESS");
var guess = parseInt(await input());
// Check if guess is correct
if(guess == randomNum) {
loss = false;
print("\n\n" + "*".repeat(50) + "!!!\n");
print(`YOU GOT IT IN ${guessNum} GUESSES!!! LET'S PLAY AGAIN...\n`);
break;
}
// Output distance in stars
var dist = Math.abs(guess - randomNum);
if(isNaN(dist)) print("*");
else if(dist >= 64) print("*");
else if(dist >= 32) print("**");
else if(dist >= 16) print("***");
else if(dist >= 8) print("****");
else if(dist >= 4) print("*****");
else if(dist >= 2) print("******");
else print("*******")
print("\n\n")
}
if(loss) {
print(`SORRY, THAT'S ${guesses} GUESSES. THE NUMBER WAS ${randomNum}\n`);
}
}
}
main();

View File

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

3
82_Stars/perl/README.md Normal file
View File

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

View File

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

141
82_Stars/python/stars.py Normal file
View File

@@ -0,0 +1,141 @@
######################################################################
#
# Stars
#
# From: BASIC Computer Games (1978)
# Edited by David H. Ahl
#
# "In this game, the computer selects a random number from 1 to 100
# (or any value you set [for MAX_NUM]). You try to guess the number
# and the computer gives you clues to tell you how close you're
# getting. One star (*) means you're far away from the number; seven
# stars (*******) means you're really close. You get 7 guesses.
#
# "On the surface this game is very similar to GUESS; however, the
# guessing strategy is quite different. See if you can come up with
# one or more approaches to finding the mystery number.
#
# "Bob Albrecht of People's Computer Company created this game."
#
#
# Python port by Jeff Jetton, 2019
#
######################################################################
import random
# Some contants
MAX_NUM = 100
MAX_GUESSES = 7
def print_instructions():
# "*** Instructions on how to play"
print("I am thinking of a whole number from 1 to %d" % MAX_NUM)
print("Try to guess my number. After you guess, I")
print("will type one or more stars (*). The more")
print("stars I type, the closer you are to my number.")
print("one star (*) means far away, seven stars (*******)")
print("means really close! You get %d guesses." % MAX_GUESSES)
def print_stars(secret_number, guess):
diff = abs(guess - secret_number)
stars = ""
for i in range(8):
if diff < 2**i:
stars += "*"
print(stars)
def get_guess():
valid_response = False
while not valid_response:
guess = input("Your guess? ")
if guess.isdigit():
valid_response = True
guess = int(guess)
return(guess)
# Display intro text
print("\n Stars")
print("Creative Computing Morristown, New Jersey")
print("\n\n")
# "*** Stars - People's Computer Center, MenloPark, CA"
response = input("Do you want instructions? ")
if response.upper()[0] == "Y":
print_instructions()
still_playing = True
while still_playing:
# "*** Computer thinks of a number"
secret_number = random.randint(1, MAX_NUM)
print("\n\nOK, I am thinking of a number, start guessing.")
# Init/start guess loop
guess_number = 0
player_has_won = False
while (guess_number < MAX_GUESSES) and not player_has_won:
print("")
guess = get_guess()
guess_number += 1
if guess == secret_number:
# "*** We have a winner"
player_has_won = True
print("*************************" +
"*************************!!!")
print("You got it in %d guesses!!!" % guess_number)
else:
print_stars(secret_number, guess)
# End of guess loop
# "*** Did not guess in [MAX_GUESS] guesses"
if not player_has_won:
print("\nSorry, that's %d guesses, number was %d" %
(guess_number, secret_number))
# Keep playing?
response = input("\nPlay again? ")
if response.upper()[0] != "Y":
still_playing = False
######################################################################
#
# Porting Notes
#
# The original program never exited--it just kept playing rounds
# over and over. This version asks to continue each time.
#
#
# Ideas for Modifications
#
# Let the player know how many guesses they have remaining after
# each incorrect guess.
#
# Ask the player to select a skill level at the start of the game,
# which will affect the values of MAX_NUM and MAX_GUESSES.
# For example:
#
# Easy = 8 guesses, 1 to 50
# Medium = 7 guesses, 1 to 100
# Hard = 6 guesses, 1 to 200
#
######################################################################

3
82_Stars/ruby/README.md Normal file
View File

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

54
82_Stars/stars.bas Normal file
View File

@@ -0,0 +1,54 @@
10 PRINT TAB(34);"STARS"
20 PRINT TAB(15);"CREATIVE COMPUTING MORRISTOWN, NEW JERSEY"
30 PRINT:PRINT:PRINT
100 REM *** STARS - PEOPLE'S COMPUTER CENTER, MENLO PARK, CA
140 REM *** A IS LIMIT ON NUMBER, M IS NUMBER OF GUESSES
150 A=100:M=7
170 INPUT "DO YOU WANT INSTRUCTIONS";A$
190 IF LEFT$(A$,1)="N" THEN 280
200 REM *** INSTRUCTIONS ON HOW TO PLAY
210 PRINT "I AM THINKING OF A WHOLE NUMBER FROM 1 TO";A
220 PRINT "TRY TO GUESS MY NUMBER. AFTER YOU GUESS, I"
230 PRINT "WILL TYPE ONE OR MORE STARS (*). THE MORE"
240 PRINT "STARS I TYPE, THE CLOSER YOU ARE TO MY NUMBER."
250 PRINT "ONE STAR (*) MEANS FAR AWAY, SEVEN STARS (*******)"
260 PRINT "MEANS REALLY CLOSE! YOU GET";M;"GUESSES."
270 REM *** COMPUTER THINKS OF A NUMBER
280 PRINT
290 PRINT
300 X=INT(A*RND(1)+1)
310 PRINT "OK, I AM THINKING OF A NUMBER, START GUESSING."
320 REM *** GUESSING BEGINS, HUMAN GETS M GUESSES
330 FOR K=1 TO M
340 PRINT
350 PRINT "YOUR GUESS";
360 INPUT G
370 IF G=X THEN 600
380 D=ABS(G-X)
390 IF D>=64 THEN 510
400 IF D>=32 THEN 500
410 IF D>=16 THEN 490
420 IF D>=8 THEN 480
430 IF D>=4 THEN 470
440 IF D>=2 THEN 460
450 PRINT "*";
460 PRINT "*";
470 PRINT "*";
480 PRINT "*";
490 PRINT "*";
500 PRINT "*";
510 PRINT "*";
520 PRINT
530 NEXT K
540 REM *** DID NOT GUESS IN M GUESSES
550 PRINT
560 PRINT "SORRY, THAT'S";M;"GUESSES. THE NUMBER WAS";X
580 GOTO 650
590 REM *** WE HAVE A WINNER
600 PRINT:FOR N=1 TO 79
610 PRINT "*";
620 NEXT N
630 PRINT:PRINT
640 PRINT "YOU GOT IT IN";K;"GUESSES!!! LET'S PLAY AGAIN..."
650 GOTO 280
660 END

3
82_Stars/vbnet/README.md Normal file
View File

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