mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-21 14:50:54 -08:00
Merge pull request #622 from MartinThoma/fix-flake8-issues
STY: Fix Flake8 issues
This commit is contained in:
@@ -2,4 +2,3 @@
|
|||||||
20 PRINT "You entered: ";A;B;C
|
20 PRINT "You entered: ";A;B;C
|
||||||
30 PRINT "--------------------------"
|
30 PRINT "--------------------------"
|
||||||
40 GOTO 10
|
40 GOTO 10
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,2 @@
|
|||||||
10 A=1: B=-2: C=0.7: D=123456789: E=-0.0000000001
|
10 A=1: B=-2: C=0.7: D=123456789: E=-0.0000000001
|
||||||
20 PRINT "|";A;"|";B;"|";C;"|";D;"|";E;"|"
|
20 PRINT "|";A;"|";B;"|";C;"|";D;"|";E;"|"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,3 @@
|
|||||||
20 PRINT "2: ";RND(-2);RND(1);RND(1);RND(1)
|
20 PRINT "2: ";RND(-2);RND(1);RND(1);RND(1)
|
||||||
30 PRINT "3: ";RND(-5);RND(1);RND(1);RND(1)
|
30 PRINT "3: ";RND(-5);RND(1);RND(1);RND(1)
|
||||||
40 PRINT "4: ";RND(-2);RND(1);RND(1);RND(1)
|
40 PRINT "4: ";RND(-2);RND(1);RND(1);RND(1)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -243,4 +243,3 @@ fn _list_files(vec: &mut Vec<PathBuf>, path: &Path) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,4 +4,3 @@ As published in Basic Computer Games (1978), as found at Annarchive:
|
|||||||
|
|
||||||
Conversion to Lua
|
Conversion to Lua
|
||||||
- [Lua.org](https://www.lua.org)
|
- [Lua.org](https://www.lua.org)
|
||||||
|
|
||||||
|
|||||||
@@ -6,85 +6,69 @@ An ancient African game (see also Kalah, Mancala).
|
|||||||
Ported by Dave LeCompte
|
Ported by Dave LeCompte
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
# PORTING NOTES
|
||||||
|
#
|
||||||
PORTING NOTES
|
# This game started out as 70 lines of BASIC, and I have ported it
|
||||||
|
# before. I find it somewhat amazing how efficient (densely packed) the
|
||||||
This game started out as 70 lines of BASIC, and I have ported it
|
# original code is. Of course, the original code has fairly cryptic
|
||||||
before. I find it somewhat amazing how efficient (densely packed) the
|
# variable names (as was forced by BASIC's limitation on long (2+
|
||||||
original code is. Of course, the original code has fairly cryptic
|
# character) variable names). I have done my best here to interpret what
|
||||||
variable names (as was forced by BASIC's limitation on long (2+
|
# each variable is doing in context, and rename them appropriately.
|
||||||
character) variable names). I have done my best here to interpret what
|
#
|
||||||
each variable is doing in context, and rename them appropriately.
|
# I have endeavored to leave the logic of the code in place, as it's
|
||||||
|
# interesting to see a 2-ply game tree evaluation written in BASIC,
|
||||||
I have endeavored to leave the logic of the code in place, as it's
|
# along with what a reader in 2021 would call "machine learning".
|
||||||
interesting to see a 2-ply game tree evaluation written in BASIC,
|
#
|
||||||
along with what a reader in 2021 would call "machine learning".
|
# As each game is played, the move history is stored as base-6
|
||||||
|
# digits stored losing_book[game_number]. If the human player wins or
|
||||||
As each game is played, the move history is stored as base-6
|
# draws, the computer increments game_number, effectively "recording"
|
||||||
digits stored losing_book[game_number]. If the human player wins or
|
# that loss to be referred to later. As the computer evaluates moves, it
|
||||||
draws, the computer increments game_number, effectively "recording"
|
# checks the potential game state against these losing game records, and
|
||||||
that loss to be referred to later. As the computer evaluates moves, it
|
# if the potential move matches with the losing game (up to the current
|
||||||
checks the potential game state against these losing game records, and
|
# number of moves), that move is evaluated at a two point penalty.
|
||||||
if the potential move matches with the losing game (up to the current
|
#
|
||||||
number of moves), that move is evaluated at a two point penalty.
|
# Compare this, for example with MENACE, a mechanical device for
|
||||||
|
# "learning" tic-tac-toe:
|
||||||
Compare this, for example with MENACE, a mechanical device for
|
# https://en.wikipedia.org/wiki/Matchbox_Educable_Noughts_and_Crosses_Engine
|
||||||
"learning" tic-tac-toe:
|
#
|
||||||
https://en.wikipedia.org/wiki/Matchbox_Educable_Noughts_and_Crosses_Engine
|
# The base-6 representation allows game history to be VERY efficiently
|
||||||
|
# represented. I considered whether to rewrite this representation to be
|
||||||
The base-6 representation allows game history to be VERY efficiently
|
# easier to read, but I elected to TRY to document it, instead.
|
||||||
represented. I considered whether to rewrite this representation to be
|
#
|
||||||
easier to read, but I elected to TRY to document it, instead.
|
# Another place where I have made a difficult decision between accuracy
|
||||||
|
# and correctness is inside the "wrapping" code where it considers
|
||||||
Another place where I have made a difficult decision between accuracy
|
# "while human_move_end > 13". The original BASIC code reads:
|
||||||
and correctness is inside the "wrapping" code where it considers
|
#
|
||||||
"while human_move_end > 13". The original BASIC code reads:
|
# 830 IF L>13 THEN L=L-14:R=1:GOTO 830
|
||||||
|
#
|
||||||
830 IF L>13 THEN L=L-14:R=1:GOTO 830
|
# I suspect that the intention is not to assign 1 to R, but to increment
|
||||||
|
# R. I discuss this more in a porting note comment next to the
|
||||||
I suspect that the intention is not to assign 1 to R, but to increment
|
# translated code. If you wish to play a more accurate version of the
|
||||||
R. I discuss this more in a porting note comment next to the
|
# game as written in the book, you can convert the increment back to an
|
||||||
translated code. If you wish to play a more accurate version of the
|
# assignment.
|
||||||
game as written in the book, you can convert the increment back to an
|
#
|
||||||
assignment.
|
# I continue to be impressed with this jewel of a game; as soon as I had
|
||||||
|
# the AI playing against me, it was beating me. I've been able to score
|
||||||
|
# a few wins against the computer, but even at its 2-ply lookahead, it
|
||||||
I continue to be impressed with this jewel of a game; as soon as I had
|
# beats me nearly always. I would like to become better at this game to
|
||||||
the AI playing against me, it was beating me. I've been able to score
|
# explore the effectiveness of the "losing book" machine learning.
|
||||||
a few wins against the computer, but even at its 2-ply lookahead, it
|
#
|
||||||
beats me nearly always. I would like to become better at this game to
|
#
|
||||||
explore the effectiveness of the "losing book" machine learning.
|
# EXERCISES FOR THE READER
|
||||||
|
# One could go many directions with this game:
|
||||||
|
# - change the initial number of stones in each pit
|
||||||
EXERCISES FOR THE READER
|
# - change the number of pits
|
||||||
One could go many directions with this game:
|
# - only allow capturing if you end on your side of the board
|
||||||
|
# - don't allow capturing at all
|
||||||
- change the initial number of stones in each pit
|
# - don't drop a stone into the enemy "home"
|
||||||
|
# - go clockwise, instead
|
||||||
- change the number of pits
|
# - allow the player to choose to go clockwise or counterclockwise
|
||||||
|
# - instead of a maximum of two moves, allow each move that ends on the
|
||||||
- only allow capturing if you end on your side of the board
|
# "home" to be followed by a free move.
|
||||||
|
# - increase the AI lookahead
|
||||||
- don't allow capturing at all
|
# - make the scoring heuristic a little more nuanced
|
||||||
|
# - store history to a file on disk (or in the cloud!) to allow the AI
|
||||||
- don't drop a stone into the enemy "home"
|
# to learn over more than a single session
|
||||||
|
|
||||||
- go clockwise, instead
|
|
||||||
|
|
||||||
- allow the player to choose to go clockwise or counterclockwise
|
|
||||||
|
|
||||||
- instead of a maximum of two moves, allow each move that ends on the
|
|
||||||
"home" to be followed by a free move.
|
|
||||||
|
|
||||||
- increase the AI lookahead
|
|
||||||
|
|
||||||
- make the scoring heuristic a little more nuanced
|
|
||||||
|
|
||||||
- store history to a file on disk (or in the cloud!) to allow the AI
|
|
||||||
to learn over more than a single session
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
game_number = 0
|
game_number = 0
|
||||||
|
|||||||
0
20_Buzzword/java/src/Buzzword.java
Executable file → Normal file
0
20_Buzzword/java/src/Buzzword.java
Executable file → Normal file
1
38_Fur_Trader/c/furtrader.c
Executable file → Normal file
1
38_Fur_Trader/c/furtrader.c
Executable file → Normal file
@@ -472,4 +472,3 @@ int main( void )
|
|||||||
|
|
||||||
return 0; /* exit OK */
|
return 0; /* exit OK */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,37 +14,35 @@ Conversion to MITS BASIC by Steve North
|
|||||||
Port to Python by Dave LeCompte
|
Port to Python by Dave LeCompte
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
# PORTING NOTES:
|
||||||
PORTING NOTES:
|
#
|
||||||
|
# I printed out the BASIC code and hand-annotated what each little block
|
||||||
I printed out the BASIC code and hand-annotated what each little block
|
# of code did, which feels amazingly retro.
|
||||||
of code did, which feels amazingly retro.
|
#
|
||||||
|
# I encourage other porters that have a complex knot of GOTOs and
|
||||||
I encourage other porters that have a complex knot of GOTOs and
|
# semi-nested subroutines to do hard-copy hacking, it might be a
|
||||||
semi-nested subroutines to do hard-copy hacking, it might be a
|
# different perspective that helps.
|
||||||
different perspective that helps.
|
#
|
||||||
|
# A spoiler - the objective of the game is not documented, ostensibly to
|
||||||
A spoiler - the objective of the game is not documented, ostensibly to
|
# give the human player a challenge. If a player (human or computer)
|
||||||
give the human player a challenge. If a player (human or computer)
|
# advances a pawn across the board to the far row, that player wins. If
|
||||||
advances a pawn across the board to the far row, that player wins. If
|
# a player has no legal moves (either by being blocked, or all their
|
||||||
a player has no legal moves (either by being blocked, or all their
|
# pieces having been captured), that player loses.
|
||||||
pieces having been captured), that player loses.
|
#
|
||||||
|
# The original BASIC had 2 2-dimensional tables stored in DATA at the
|
||||||
The original BASIC had 2 2-dimensional tables stored in DATA at the
|
# end of the program. This encoded all 19 different board configurations
|
||||||
end of the program. This encoded all 19 different board configurations
|
# (Hexapawn is a small game), with reflections in one table, and then in
|
||||||
(Hexapawn is a small game), with reflections in one table, and then in
|
# a parallel table, for each of the 19 rows, a list of legal moves was
|
||||||
a parallel table, for each of the 19 rows, a list of legal moves was
|
# encoded by turning them into 2-digit decimal numbers. As gameplay
|
||||||
encoded by turning them into 2-digit decimal numbers. As gameplay
|
# continued, the AI would overwrite losing moves with 0 in the second
|
||||||
continued, the AI would overwrite losing moves with 0 in the second
|
# array.
|
||||||
array.
|
#
|
||||||
|
# My port takes this "parallel array" structure and turns that
|
||||||
My port takes this "parallel array" structure and turns that
|
# information into a small Python class, BoardLayout. BoardLayout stores
|
||||||
information into a small Python class, BoardLayout. BoardLayout stores
|
# the board description and legal moves, but stores the moves as (row,
|
||||||
the board description and legal moves, but stores the moves as (row,
|
# column) 2-tuples, which is easier to read. The logic for checking if a
|
||||||
column) 2-tuples, which is easier to read. The logic for checking if a
|
# BoardLayout matches the current board, as well as removing losing move
|
||||||
BoardLayout matches the current board, as well as removing losing move
|
# have been moved into methods of this class.
|
||||||
have been moved into methods of this class.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
import random
|
import random
|
||||||
@@ -238,7 +236,7 @@ def get_coordinates():
|
|||||||
try:
|
try:
|
||||||
print("YOUR MOVE?")
|
print("YOUR MOVE?")
|
||||||
response = input()
|
response = input()
|
||||||
m1, m2 = [int(c) for c in response.split(",")]
|
m1, m2 = (int(c) for c in response.split(","))
|
||||||
return m1, m2
|
return m1, m2
|
||||||
except ValueError as ve:
|
except ValueError as ve:
|
||||||
print_illegal()
|
print_illegal()
|
||||||
@@ -362,12 +360,12 @@ def human_has_move(board):
|
|||||||
|
|
||||||
|
|
||||||
def get_board_spaces():
|
def get_board_spaces():
|
||||||
""" generates the space names (1-9)"""
|
"""generates the space names (1-9)"""
|
||||||
yield from range(1, 10)
|
yield from range(1, 10)
|
||||||
|
|
||||||
|
|
||||||
def get_board_spaces_with(board, val):
|
def get_board_spaces_with(board, val):
|
||||||
""" generates spaces containing pieces of type val"""
|
"""generates spaces containing pieces of type val"""
|
||||||
for i in get_board_spaces():
|
for i in get_board_spaces():
|
||||||
if board_contents(board, i) == val:
|
if board_contents(board, i) == val:
|
||||||
yield i
|
yield i
|
||||||
|
|||||||
@@ -6,16 +6,15 @@ Math exercise/demonstration
|
|||||||
Ported by Dave LeCompte
|
Ported by Dave LeCompte
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
# PORTING NOTE
|
||||||
PORTING NOTE
|
#
|
||||||
|
# The title, as printed ingame, is "NICOMA", hinting at a time when
|
||||||
The title, as printed ingame, is "NICOMA", hinting at a time when
|
# filesystems weren't even 8.3, but could only support 6 character
|
||||||
filesystems weren't even 8.3, but could only support 6 character
|
# filenames.
|
||||||
filenames.
|
|
||||||
"""
|
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def print_with_tab(spaces_count, msg):
|
def print_with_tab(spaces_count, msg):
|
||||||
if spaces_count > 0:
|
if spaces_count > 0:
|
||||||
spaces = " " * spaces_count
|
spaces = " " * spaces_count
|
||||||
@@ -23,6 +22,7 @@ def print_with_tab(spaces_count, msg):
|
|||||||
spaces = ""
|
spaces = ""
|
||||||
print(spaces + msg)
|
print(spaces + msg)
|
||||||
|
|
||||||
|
|
||||||
def get_yes_or_no():
|
def get_yes_or_no():
|
||||||
while True:
|
while True:
|
||||||
response = input().upper()
|
response = input().upper()
|
||||||
|
|||||||
@@ -60,4 +60,3 @@ fn welcome() {
|
|||||||
|
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,14 +6,12 @@ A poetry generator
|
|||||||
Ported by Dave LeCompte
|
Ported by Dave LeCompte
|
||||||
"""
|
"""
|
||||||
|
|
||||||
"""
|
# PORTING EDITORIAL NOTE:
|
||||||
PORTING EDITORIAL NOTE:
|
#
|
||||||
|
# The original code is a pretty convoluted mesh of GOTOs and global
|
||||||
The original code is a pretty convoluted mesh of GOTOs and global
|
# state. This adaptation pulls things apart into phrases, but I have
|
||||||
state. This adaptation pulls things apart into phrases, but I have
|
# left the variables as globals, which makes goes against decades of
|
||||||
left the variables as globals, which makes goes against decades of
|
# wisdom that global state is bad.
|
||||||
wisdom that global state is bad.
|
|
||||||
"""
|
|
||||||
|
|
||||||
PAGE_WIDTH = 64
|
PAGE_WIDTH = 64
|
||||||
|
|
||||||
@@ -27,22 +25,27 @@ k = 0
|
|||||||
phrase = 1
|
phrase = 1
|
||||||
line = ""
|
line = ""
|
||||||
|
|
||||||
|
|
||||||
def print_centered(msg):
|
def print_centered(msg):
|
||||||
spaces = " " * ((PAGE_WIDTH - len(msg)) // 2)
|
spaces = " " * ((PAGE_WIDTH - len(msg)) // 2)
|
||||||
print (spaces + msg)
|
print(spaces + msg)
|
||||||
|
|
||||||
|
|
||||||
def process_phrase_1():
|
def process_phrase_1():
|
||||||
global line
|
global line
|
||||||
|
|
||||||
line_1_options = ["MIDNIGHT DREARY",
|
line_1_options = [
|
||||||
|
"MIDNIGHT DREARY",
|
||||||
"FIERY EYES",
|
"FIERY EYES",
|
||||||
"BIRD OR FIEND",
|
"BIRD OR FIEND",
|
||||||
"THING OF EVIL",
|
"THING OF EVIL",
|
||||||
"PROPHET"]
|
"PROPHET",
|
||||||
|
]
|
||||||
|
|
||||||
line = line + line_1_options[i]
|
line = line + line_1_options[i]
|
||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
def process_phrase_2():
|
def process_phrase_2():
|
||||||
global line
|
global line
|
||||||
global u
|
global u
|
||||||
@@ -52,12 +55,14 @@ def process_phrase_2():
|
|||||||
("THRILLED ME", None),
|
("THRILLED ME", None),
|
||||||
("STILL SITTING....", None),
|
("STILL SITTING....", None),
|
||||||
("NEVER FLITTING", 2),
|
("NEVER FLITTING", 2),
|
||||||
("BURNED", None)]
|
("BURNED", None),
|
||||||
|
]
|
||||||
words, u_modifier = line_2_options[i]
|
words, u_modifier = line_2_options[i]
|
||||||
line += words
|
line += words
|
||||||
if not (u_modifier is None):
|
if not (u_modifier is None):
|
||||||
u = u_modifier
|
u = u_modifier
|
||||||
|
|
||||||
|
|
||||||
def process_phrase_3():
|
def process_phrase_3():
|
||||||
global line
|
global line
|
||||||
|
|
||||||
@@ -73,6 +78,7 @@ def process_phrase_3():
|
|||||||
if (not only_if_u) or (u > 0):
|
if (not only_if_u) or (u > 0):
|
||||||
line = line + words
|
line = line + words
|
||||||
|
|
||||||
|
|
||||||
def process_phrase_4():
|
def process_phrase_4():
|
||||||
global line
|
global line
|
||||||
|
|
||||||
@@ -81,10 +87,12 @@ def process_phrase_4():
|
|||||||
("YET AGAIN"),
|
("YET AGAIN"),
|
||||||
("SLOWLY CREEPING"),
|
("SLOWLY CREEPING"),
|
||||||
("...EVERMORE"),
|
("...EVERMORE"),
|
||||||
("NEVERMORE")]
|
("NEVERMORE"),
|
||||||
|
]
|
||||||
|
|
||||||
line += phrases[i]
|
line += phrases[i]
|
||||||
|
|
||||||
|
|
||||||
def maybe_comma():
|
def maybe_comma():
|
||||||
# line 210
|
# line 210
|
||||||
global u
|
global u
|
||||||
@@ -136,7 +144,7 @@ def main():
|
|||||||
1: process_phrase_1,
|
1: process_phrase_1,
|
||||||
2: process_phrase_2,
|
2: process_phrase_2,
|
||||||
3: process_phrase_3,
|
3: process_phrase_3,
|
||||||
4: process_phrase_4
|
4: process_phrase_4,
|
||||||
}
|
}
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
@@ -156,5 +164,6 @@ def main():
|
|||||||
continue
|
continue
|
||||||
pick_phrase()
|
pick_phrase()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -8,20 +8,49 @@ medals = {
|
|||||||
"silver": 0,
|
"silver": 0,
|
||||||
"bronze": 0,
|
"bronze": 0,
|
||||||
}
|
}
|
||||||
max_speeds = [14,18,26,29,18,25,28,32,29,20,29,29,25,21,26,29,20,21,20,18,26,25,33,31,22]
|
max_speeds = [
|
||||||
|
14,
|
||||||
|
18,
|
||||||
|
26,
|
||||||
|
29,
|
||||||
|
18,
|
||||||
|
25,
|
||||||
|
28,
|
||||||
|
32,
|
||||||
|
29,
|
||||||
|
20,
|
||||||
|
29,
|
||||||
|
29,
|
||||||
|
25,
|
||||||
|
21,
|
||||||
|
26,
|
||||||
|
29,
|
||||||
|
20,
|
||||||
|
21,
|
||||||
|
20,
|
||||||
|
18,
|
||||||
|
26,
|
||||||
|
25,
|
||||||
|
33,
|
||||||
|
31,
|
||||||
|
22,
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def ask(question):
|
def ask(question):
|
||||||
print(question, end="? ")
|
print(question, end="? ")
|
||||||
return input().upper()
|
return input().upper()
|
||||||
|
|
||||||
|
|
||||||
def ask_int(question):
|
def ask_int(question):
|
||||||
reply = ask(question)
|
reply = ask(question)
|
||||||
return int(reply) if reply.isnumeric() else -1
|
return int(reply) if reply.isnumeric() else -1
|
||||||
|
|
||||||
|
|
||||||
def pre_run():
|
def pre_run():
|
||||||
print("\nType \"INS\" for instructions")
|
print('\nType "INS" for instructions')
|
||||||
print("Type \"MAX\" for approximate maximum speeds")
|
print('Type "MAX" for approximate maximum speeds')
|
||||||
print("Type \"RUN\" for the beginning of the race")
|
print('Type "RUN" for the beginning of the race')
|
||||||
cmd = ask("Command--")
|
cmd = ask("Command--")
|
||||||
while cmd != "RUN":
|
while cmd != "RUN":
|
||||||
if cmd == "INS":
|
if cmd == "INS":
|
||||||
@@ -48,7 +77,8 @@ def pre_run():
|
|||||||
print(f" {i + 1} {max_speeds[i]}")
|
print(f" {i + 1} {max_speeds[i]}")
|
||||||
cmd = ask("Command--")
|
cmd = ask("Command--")
|
||||||
else:
|
else:
|
||||||
cmd = ask(f"\"{cmd}\" is an illegal command--Retry")
|
cmd = ask(f'"{cmd}" is an illegal command--Retry')
|
||||||
|
|
||||||
|
|
||||||
def run():
|
def run():
|
||||||
global medals
|
global medals
|
||||||
@@ -63,7 +93,7 @@ def run():
|
|||||||
old_speed = speed
|
old_speed = speed
|
||||||
opt = ask_int("Option")
|
opt = ask_int("Option")
|
||||||
while opt < 1 or opt > 8:
|
while opt < 1 or opt > 8:
|
||||||
if(opt == 0):
|
if opt == 0:
|
||||||
print(f"You've taken {int(time)} seconds.")
|
print(f"You've taken {int(time)} seconds.")
|
||||||
else:
|
else:
|
||||||
print("What?")
|
print("What?")
|
||||||
@@ -71,7 +101,7 @@ def run():
|
|||||||
|
|
||||||
if opt == 8:
|
if opt == 8:
|
||||||
print("***Cheat")
|
print("***Cheat")
|
||||||
if random() < .7:
|
if random() < 0.7:
|
||||||
print("An official caught you!")
|
print("An official caught you!")
|
||||||
print(f"You took {int(time + random())} seconds.")
|
print(f"You took {int(time + random())} seconds.")
|
||||||
return
|
return
|
||||||
@@ -99,8 +129,10 @@ def run():
|
|||||||
speed -= int(random() * (10 - 5) + 5)
|
speed -= int(random() * (10 - 5) + 5)
|
||||||
print(f" {int(speed)} M.P.H.")
|
print(f" {int(speed)} M.P.H.")
|
||||||
if speed > max_speeds[i]:
|
if speed > max_speeds[i]:
|
||||||
if random() < ((speed - max_speeds[i]) * .1) + .2:
|
if random() < ((speed - max_speeds[i]) * 0.1) + 0.2:
|
||||||
print(f"You went over the maximum speed and {'snagged a flag' if random() < .5 else 'wiped out'}!")
|
print(
|
||||||
|
f"You went over the maximum speed and {'snagged a flag' if random() < .5 else 'wiped out'}!"
|
||||||
|
)
|
||||||
print(f"You took {int(time + random())} seconds")
|
print(f"You took {int(time + random())} seconds")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@@ -113,26 +145,27 @@ def run():
|
|||||||
else:
|
else:
|
||||||
time += max_speeds[i] - speed + 1
|
time += max_speeds[i] - speed + 1
|
||||||
if speed > max_speeds[i]:
|
if speed > max_speeds[i]:
|
||||||
time += .5
|
time += 0.5
|
||||||
break
|
break
|
||||||
print(f"\nYou took {int(time + random())} seconds.")
|
print(f"\nYou took {int(time + random())} seconds.")
|
||||||
avg = time / gates
|
avg = time / gates
|
||||||
if avg < 1.5 - (lvl * .1):
|
if avg < 1.5 - (lvl * 0.1):
|
||||||
print("Yout won a gold medal!")
|
print("Yout won a gold medal!")
|
||||||
medals["gold"] += 1
|
medals["gold"] += 1
|
||||||
elif avg < 2.9 - (lvl * .1):
|
elif avg < 2.9 - (lvl * 0.1):
|
||||||
print("You won a silver medal!")
|
print("You won a silver medal!")
|
||||||
medals["silver"] += 1
|
medals["silver"] += 1
|
||||||
elif avg < 4.4 - (lvl * .01):
|
elif avg < 4.4 - (lvl * 0.01):
|
||||||
print("You won a bronze medal!")
|
print("You won a bronze medal!")
|
||||||
medals["bronze"] += 1
|
medals["bronze"] += 1
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
gates = ask_int("How many gates does this course have (1 to 25)")
|
gates = ask_int("How many gates does this course have (1 to 25)")
|
||||||
if gates < 1:
|
if gates < 1:
|
||||||
print("Try again,")
|
print("Try again,")
|
||||||
else:
|
else:
|
||||||
if(gates > 25):
|
if gates > 25:
|
||||||
print("25 is the limit.")
|
print("25 is the limit.")
|
||||||
break
|
break
|
||||||
|
|
||||||
@@ -152,7 +185,7 @@ while True:
|
|||||||
if answer == "YES" or answer == "NO":
|
if answer == "YES" or answer == "NO":
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print("Please type \"YES\" or \"NO\"")
|
print('Please type "YES" or "NO"')
|
||||||
if answer == "NO":
|
if answer == "NO":
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user