mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-22 07:10:42 -08:00
Python: Add type annotations to all 'print' functions (#662)
* Add test to superstartrek and fixes several issues in superstartrek - I probably introduced them 🙈
* Mastermind type annotations
This commit is contained in:
@@ -26,12 +26,12 @@ MoveRecord = collections.namedtuple(
|
||||
)
|
||||
|
||||
|
||||
def print_centered(msg):
|
||||
def print_centered(msg: str) -> None:
|
||||
spaces = " " * ((PAGE_WIDTH - len(msg)) // 2)
|
||||
print(spaces + msg)
|
||||
|
||||
|
||||
def print_header(title):
|
||||
def print_header(title: str) -> None:
|
||||
print_centered(title)
|
||||
print_centered("CREATIVE COMPUTING MORRISTOWN, NEW JERSEY")
|
||||
print()
|
||||
@@ -62,7 +62,7 @@ def is_legal_board_coordinate(x, y):
|
||||
|
||||
|
||||
class Board:
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
self.spaces = [[0 for y in range(8)] for x in range(8)]
|
||||
for x in range(8):
|
||||
if (x % 2) == 0:
|
||||
@@ -74,7 +74,7 @@ class Board:
|
||||
self.spaces[x][5] = COMPUTER_PIECE
|
||||
self.spaces[x][1] = HUMAN_PIECE
|
||||
|
||||
def __str__(self):
|
||||
def __str__(self) -> str:
|
||||
pieces = {
|
||||
EMPTY_SPACE: ".",
|
||||
HUMAN_PIECE: "O",
|
||||
@@ -336,7 +336,7 @@ class Board:
|
||||
return True
|
||||
|
||||
|
||||
def print_instructions():
|
||||
def print_instructions() -> None:
|
||||
print("THIS IS THE GAME OF CHECKERS. THE COMPUTER IS X,")
|
||||
print("AND YOU ARE O. THE COMPUTER WILL MOVE FIRST.")
|
||||
print("SQUARES ARE REFERRED TO BY A COORDINATE SYSTEM.")
|
||||
@@ -351,17 +351,17 @@ def print_instructions():
|
||||
print()
|
||||
|
||||
|
||||
def print_human_won():
|
||||
def print_human_won() -> None:
|
||||
print()
|
||||
print("YOU WIN.")
|
||||
|
||||
|
||||
def print_computer_won():
|
||||
def print_computer_won() -> None:
|
||||
print()
|
||||
print("I WIN.")
|
||||
|
||||
|
||||
def play_game():
|
||||
def play_game() -> None:
|
||||
board = Board()
|
||||
|
||||
while True:
|
||||
|
||||
Reference in New Issue
Block a user