Merge branch 'coding-horror:main' into rust-port-amazing

This commit is contained in:
Anthony Rubick
2022-03-07 09:17:35 +00:00
committed by GitHub
554 changed files with 9644 additions and 5545 deletions

View File

@@ -1,8 +1,8 @@
using System;
using System.Collections.Generic;
namespace Amazing
{
using System;
using System.Collections.Generic;
namespace Amazing
{
class AmazingGame
{
private const int FIRST_COL = 0;
@@ -35,9 +35,9 @@ namespace Amazing
}
public void Play()
{
Console.WriteLine(Tab(28) + "AMAZING PROGRAM");
Console.WriteLine(Tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
{
Console.WriteLine(Tab(28) + "AMAZING PROGRAM");
Console.WriteLine(Tab(15) + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY");
Console.WriteLine();
int width = 0;
@@ -113,25 +113,25 @@ namespace Amazing
{
if (i == enterCol) Console.Write(". ");
else Console.Write(".--");
}
Console.WriteLine(".");
}
Console.WriteLine(".");
for (int i = 0; i < grid.Length; i++)
{
{
Console.Write("I");
for (int j = 0; j < grid.Width; j++)
{
if (grid.Cells[i,j].ExitType == EXIT_UNSET || grid.Cells[i, j].ExitType == EXIT_DOWN)
Console.Write(" I");
else Console.Write(" ");
}
Console.WriteLine();
}
Console.WriteLine();
for (int j = 0; j < grid.Width; j++)
{
if (grid.Cells[i,j].ExitType == EXIT_UNSET || grid.Cells[i, j].ExitType == EXIT_RIGHT)
Console.Write(":--");
else Console.Write(": ");
}
}
Console.WriteLine(".");
}
}
@@ -164,7 +164,7 @@ namespace Amazing
}
private String DisplayTextAndGetInput(String text)
{
{
Console.WriteLine(text);
return Console.ReadLine();
}
@@ -308,13 +308,13 @@ namespace Amazing
return newCell;
}
}
}
class Program
{
static void Main(string[] args)
}
class Program
{
static void Main(string[] args)
{
new AmazingGame().Play();
}
}
}
new AmazingGame().Play();
}
}
}

View File

@@ -259,4 +259,4 @@ public class Amazing {
return newCell;
}
}
}
}

View File

@@ -12,10 +12,10 @@ 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");

View File

@@ -14,4 +14,3 @@ begin
AmazingApp:= TAmazingApplication.Create;
AmazingApp.Run;
end.

View File

@@ -101,4 +101,3 @@ begin
end;
end.

View File

@@ -277,4 +277,3 @@ begin
end;
end.

View File

@@ -68,4 +68,3 @@ begin
end;
end.

View File

@@ -281,4 +281,3 @@ begin
//DebugWalls;
PrintMaze;
end.

View File

@@ -79,7 +79,7 @@ sub input_dimensions {
print 'WHAT ARE YOUR WIDTH AND LENGTH? ';
($w, $h) = <STDIN> =~ / \d+ /xg;
if ($w < 1 || $h < 1) {
say "MEANINGLESS DIMENSIONS. TRY AGAIN."
}

View File

@@ -1,20 +1,20 @@
import random
# Python translation by Frank Palazzolo - 2/2021
print(' '*28+'AMAZING PROGRAM')
print(' '*15+'CREATIVE COMPUTING MORRISTOWN, NEW JERSEY')
print(" " * 28 + "AMAZING PROGRAM")
print(" " * 15 + "CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
print()
print()
print()
while True:
width, length = input('What are your width and length?').split(',')
width, length = input("What are your width and length?").split(",")
width = int(width)
length = int(length)
if width != 1 and length != 1:
break
print('Meaningless dimensions. Try again.')
print("Meaningless dimensions. Try again.")
# Build two 2D arrays
#
@@ -32,90 +32,87 @@ while True:
used = []
walls = []
for i in range(length):
used.append([0]*width)
walls.append([0]*width)
used.append([0] * width)
walls.append([0] * width)
# Use direction variables with nice names
GO_LEFT,GO_UP,GO_RIGHT,GO_DOWN=[0,1,2,3]
GO_LEFT, GO_UP, GO_RIGHT, GO_DOWN = [0, 1, 2, 3]
# Give Exit directions nice names
EXIT_DOWN = 1
EXIT_RIGHT = 2
# Pick a random entrance, mark as used
enter_col=random.randint(0,width-1)
row,col=0,enter_col
count=1
used[row][col]=count
count=count+1
enter_col = random.randint(0, width - 1)
row, col = 0, enter_col
count = 1
used[row][col] = count
count = count + 1
while count!=width*length+1:
while count != width * length + 1:
# remove possible directions that are blocked or
# hit cells that we have already processed
possible_dirs = [GO_LEFT,GO_UP,GO_RIGHT,GO_DOWN]
if col==0 or used[row][col-1]!=0:
possible_dirs = [GO_LEFT, GO_UP, GO_RIGHT, GO_DOWN]
if col == 0 or used[row][col - 1] != 0:
possible_dirs.remove(GO_LEFT)
if row==0 or used[row-1][col]!=0:
if row == 0 or used[row - 1][col] != 0:
possible_dirs.remove(GO_UP)
if col==width-1 or used[row][col+1]!=0:
if col == width - 1 or used[row][col + 1] != 0:
possible_dirs.remove(GO_RIGHT)
if row==length-1 or used[row+1][col]!=0:
possible_dirs.remove(GO_DOWN)
if row == length - 1 or used[row + 1][col] != 0:
possible_dirs.remove(GO_DOWN)
# If we can move in a direction, move and make opening
if len(possible_dirs)!=0:
direction=random.choice(possible_dirs)
if direction==GO_LEFT:
col=col-1
walls[row][col]=EXIT_RIGHT
elif direction==GO_UP:
row=row-1
walls[row][col]=EXIT_DOWN
elif direction==GO_RIGHT:
walls[row][col]=walls[row][col]+EXIT_RIGHT
col=col+1
elif direction==GO_DOWN:
walls[row][col]=walls[row][col]+EXIT_DOWN
row=row+1
used[row][col]=count
count=count+1
if len(possible_dirs) != 0:
direction = random.choice(possible_dirs)
if direction == GO_LEFT:
col = col - 1
walls[row][col] = EXIT_RIGHT
elif direction == GO_UP:
row = row - 1
walls[row][col] = EXIT_DOWN
elif direction == GO_RIGHT:
walls[row][col] = walls[row][col] + EXIT_RIGHT
col = col + 1
elif direction == GO_DOWN:
walls[row][col] = walls[row][col] + EXIT_DOWN
row = row + 1
used[row][col] = count
count = count + 1
# otherwise, move to the next used cell, and try again
else:
while True:
if col!=width-1:
col=col+1
elif row!=length-1:
row,col=row+1,0
if col != width - 1:
col = col + 1
elif row != length - 1:
row, col = row + 1, 0
else:
row,col=0,0
if used[row][col]!=0:
row, col = 0, 0
if used[row][col] != 0:
break
# Add a random exit
col=random.randint(0,width-1)
row=length-1
walls[row][col]=walls[row][col]+1
col = random.randint(0, width - 1)
row = length - 1
walls[row][col] = walls[row][col] + 1
# Print the maze
for col in range(width):
if col==enter_col:
print('. ',end='')
if col == enter_col:
print(". ", end="")
else:
print('.--',end='')
print('.')
print(".--", end="")
print(".")
for row in range(length):
print('I',end='')
print("I", end="")
for col in range(width):
if walls[row][col]<2:
print(' I',end='')
if walls[row][col] < 2:
print(" I", end="")
else:
print(' ',end='')
print(" ", end="")
print()
for col in range(width):
if walls[row][col]==0 or walls[row][col]==2:
print(':--',end='')
if walls[row][col] == 0 or walls[row][col] == 2:
print(":--", end="")
else:
print(': ',end='')
print('.')
print(": ", end="")
print(".")

View File

@@ -213,4 +213,4 @@ class Amazing
end
end
Amazing.new.run
Amazing.new.run

View File

@@ -145,7 +145,7 @@ Module Program
Return SelectRandomDirection(Directions.Up, Directions.Down)
ElseIf SolutionCompleted Then 'We're on the bottom row, can only go up
Return GoUp()
Else 'We're on the bottom row, can only go up, but there's no solution
Else 'We're on the bottom row, can only go up, but there's no solution
Return SelectRandomDirection(Directions.Up, Directions.SolveAndReset)
End If
'== Definitely can go Up and Right ==