Skip to content

Commit

Permalink
Use NamedTuple; Fix camelCase->snake_case
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Apr 2, 2022
1 parent ac184fe commit e17388d
Show file tree
Hide file tree
Showing 13 changed files with 167 additions and 178 deletions.
9 changes: 4 additions & 5 deletions 01_Acey_Ducey/python/acey_ducey_oo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
Python port by Aviyam Fischer, 2022
"""

from typing import List, Literal, TypeAlias, get_args
from typing import List, Literal, NamedTuple, TypeAlias, get_args

Suit: TypeAlias = Literal["\u2665", "\u2666", "\u2663", "\u2660"]
Rank: TypeAlias = Literal[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]


class Card:
def __init__(self, suit: Suit, rank: Rank) -> None:
self.suit = suit
self.rank = rank
class Card(NamedTuple):
suit: Suit
rank: Rank

def __str__(self) -> str:
r = str(self.rank)
Expand Down
8 changes: 2 additions & 6 deletions 02_Amazing/python/amazing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@


class Maze:
def __init__(
self,
width: int,
length: int,
):
def __init__(self, width: int, length: int) -> None:
assert width >= 2 and length >= 2
used: List[List[int]] = []
walls: List[List[int]] = []
Expand Down Expand Up @@ -117,7 +113,7 @@ def build_maze(width: int, length: int) -> Maze:
else:
while True:
if position.col != width - 1:
position.col = position.col + 1
position.col += 1
elif position.row != length - 1:
position.row, position.col = position.row + 1, 0
else:
Expand Down
12 changes: 6 additions & 6 deletions 06_Banner/python/banner.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ def print_banner() -> None:

for statement_char in statement:
s = letters[statement_char].copy()
xStr = character
x_str = character
if character == "ALL":
xStr = statement_char
if xStr == " ":
x_str = statement_char
if x_str == " ":
print("\n" * (7 * horizontal))
else:
for u in range(0, 7):
Expand All @@ -103,13 +103,13 @@ def print_banner() -> None:
f[u] = 8 - k
break
for _t1 in range(1, horizontal + 1):
line_str = " " * int((63 - 4.5 * vertical) * g1 / len(xStr) + 1)
line_str = " " * int((63 - 4.5 * vertical) * g1 / len(x_str) + 1)
for b in range(0, f[u] + 1):
if j[b] == 0:
for _ in range(1, vertical + 1):
line_str = line_str + " " * len(xStr)
line_str = line_str + " " * len(x_str)
else:
line_str = line_str + xStr * vertical
line_str = line_str + x_str * vertical
print(line_str)
print("\n" * (2 * horizontal - 1))
# print("\n" * 75) # Feed some more paper from the printer
Expand Down
16 changes: 8 additions & 8 deletions 08_Batnum/python/batnum.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ def get_params() -> Tuple[int, int, int, StartOptions, WinOptions]:
"""This requests the necessary parameters to play the game.
Returns a set with the five game parameters:
pileSize - the starting size of the object pile
minSelect - minimum selection that can be made on each turn
maxSelect - maximum selection that can be made on each turn
startOption - 1 if the computer is first
pile_size - the starting size of the object pile
min_select - minimum selection that can be made on each turn
max_select - maximum selection that can be made on each turn
start_option - 1 if the computer is first
or 2 if the player is first
winOption - 1 if the goal is to take the last object
win_option - 1 if the goal is to take the last object
or 2 if the goal is to not take the last object
"""
pile_size = get_pile_size()
Expand Down Expand Up @@ -123,7 +123,7 @@ def player_move(
to take and doing some basic validation around that input. Then it
checks for any win conditions.
Returns a boolean indicating whether the game is over and the new pileSize."""
Returns a boolean indicating whether the game is over and the new pile_size."""
player_done = False
while not player_done:
player_move = int(input("YOUR MOVE "))
Expand Down Expand Up @@ -167,7 +167,7 @@ def computer_move(
win/lose conditions and then calculating how many objects
the computer will take.
Returns a boolean indicating whether the game is over and the new pileSize."""
Returns a boolean indicating whether the game is over and the new pile_size."""
# First, check for win conditions on this move
# In this case, we win by taking the last object and
# the remaining pile is less than max select
Expand Down Expand Up @@ -200,7 +200,7 @@ def play_game(
of the win/lose conditions is met.
"""
game_over = False
# playersTurn is a boolean keeping track of whether it's the
# players_turn is a boolean keeping track of whether it's the
# player's or computer's turn
players_turn = start_option == StartOptions.PlayerFirst

Expand Down
10 changes: 5 additions & 5 deletions 25_Chief/python/chief.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def game() -> None:
print("\nHuh, I Knew I was unbeatable")
print("And here is how i did it")
print_solution(comp_guess)
input("")
input()
else:
resp3 = float(input("\nHUH!! what was you original number? "))

Expand All @@ -48,7 +48,7 @@ def game() -> None:
)
print("Here is how i did it")
print_solution(comp_guess)
input("")
input()
else:
print("\nSo you think you're so smart, EH?")
print("Now, Watch")
Expand All @@ -58,14 +58,14 @@ def game() -> None:

if resp4.lower() == "yes":
print("\nOk, Lets play again sometime bye!!!!")
input("")
input()
else:
print("\nYOU HAVE MADE ME VERY MAD!!!!!")
print("BY THE WRATH OF THE MATHEMATICS AND THE RAGE OF THE GODS")
print("THERE SHALL BE LIGHTNING!!!!!!!")
print_lightning_bolt()
print("\nI Hope you believe me now, for your own sake")
input("")
input()


if __name__ == "__main__":
Expand All @@ -75,4 +75,4 @@ def game() -> None:
game()
else:
print("Ok, Nevermind. Let me go back to my great slumber, Bye")
input("")
input()
6 changes: 3 additions & 3 deletions 32_Diamond/python/diamond.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@


def print_diamond(begin_width, end_width, step, width, count) -> None:
edgeString = "CC"
edge_string = "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):
if a >= len(edge_string):
line_buffer += fill
else:
line_buffer += edgeString[a]
line_buffer += edge_string[a]
line_buffer += " " * (
(width * (across + 1) + (width - n) // 2) - len(line_buffer)
)
Expand Down
Loading

0 comments on commit e17388d

Please sign in to comment.