Skip to content

Commit

Permalink
Use docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinThoma committed Apr 2, 2022
1 parent c500424 commit 4b3b991
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 323 deletions.
4 changes: 2 additions & 2 deletions 08_Batnum/python/batnum.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import IntEnum
from typing import Tuple, Any
from typing import Any, Tuple


class WinOptions(IntEnum):
Expand Down Expand Up @@ -41,7 +41,7 @@ def _missing_(cls, value: Any) -> "StartOptions":


def print_intro() -> None:
"""Prints out the introduction and rules for the game."""
"""Print out the introduction and rules for the game."""
print("BATNUM".rjust(33, " "))
print("CREATIVE COMPUTING MORRISSTOWN, NEW JERSEY".rjust(15, " "))
print()
Expand Down
38 changes: 18 additions & 20 deletions 20_Buzzword/python/buzzword.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
######################################################################
#
# Buzzword Generator
#
# From: BASIC Computer Games (1978)
# Edited by David H. Ahl
#
# "This program is an invaluable aid for preparing speeches and
# briefings about education technology. This buzzword generator
# provides sets of three highly-acceptable words to work into your
# material. Your audience will never know that the phrases don't
# really mean much of anything because they sound so great! Full
# instructions for running are given in the program.
#
# "This version of Buzzword was written by David Ahl."
#
#
# Python port by Jeff Jetton, 2019
#
######################################################################
"""
Buzzword Generator
From: BASIC Computer Games (1978)
Edited by David H. Ahl
"This program is an invaluable aid for preparing speeches and
briefings about education technology. This buzzword generator
provides sets of three highly-acceptable words to work into your
material. Your audience will never know that the phrases don't
really mean much of anything because they sound so great! Full
instructions for running are given in the program.
"This version of Buzzword was written by David Ahl."
Python port by Jeff Jetton, 2019
"""


import random
Expand Down
43 changes: 20 additions & 23 deletions 21_Calendar/python/calendar.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
########################################################
# Calendar
#
# From: BASIC Computer Games (1978)
# Edited by David Ahl#
#
# This program prints out a calendar
# for any year. You must specify the
# starting day of the week of the year in
# statement 130. (Sunday(0), Monday
# (-1), Tuesday(-2), etc.) You can determine
# this by using the program WEEKDAY.
# You must also make two changes
# for leap years in statement 360 and 620.
# The program listing describes the necessary
# changes. Running the program produces a
# nice 12-month calendar.
# The program was written by Geofrey
# Chase of the Abbey, Portsmouth, Rhode Island.
#
########################################################
"""
Calendar
From: BASIC Computer Games (1978)
Edited by David Ahl#
This program prints out a calendar
for any year. You must specify the
starting day of the week of the year in
statement 130. (Sunday(0), Monday
(-1), Tuesday(-2), etc.) You can determine
this by using the program WEEKDAY.
You must also make two changes
for leap years in statement 360 and 620.
The program listing describes the necessary
changes. Running the program produces a
nice 12-month calendar.
The program was written by Geofrey
Chase of the Abbey, Portsmouth, Rhode Island.
"""

from typing import Tuple

Expand Down Expand Up @@ -150,8 +149,6 @@ def main() -> None:
if __name__ == "__main__":
main()

########################################################
#
########################################################
#
# Porting notes:
Expand Down
49 changes: 23 additions & 26 deletions 33_Dice/python/dice.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
########################################################
#
# Dice
#
# From: BASIC Computer Games (1978)
# Edited by David H. Ahl
#
# "Not exactly a game, this program simulates rolling
# a pair of dice a large number of times and prints out
# the frequency distribution. You simply input the
# number of rolls. It is interesting to see how many
# rolls are necessary to approach the theoretical
# distribution:
#
# 2 1/36 2.7777...%
# 3 2/36 5.5555...%
# 4 3/36 8.3333...%
# etc.
#
# "Daniel Freidus wrote this program while in the
# seventh grade at Harrison Jr-Sr High School,
# Harrison, New York."
#
# Python port by Jeff Jetton, 2019
#
########################################################
"""
Dice
From: BASIC Computer Games (1978)
Edited by David H. Ahl
"Not exactly a game, this program simulates rolling
a pair of dice a large number of times and prints out
the frequency distribution. You simply input the
number of rolls. It is interesting to see how many
rolls are necessary to approach the theoretical
distribution:
2 1/36 2.7777...%
3 2/36 5.5555...%
4 3/36 8.3333...%
etc.
"Daniel Freidus wrote this program while in the
seventh grade at Harrison Jr-Sr High School,
Harrison, New York."
Python port by Jeff Jetton, 2019
"""

import random

Expand Down
40 changes: 19 additions & 21 deletions 41_Guess/python/guess.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
########################################################
#
# Guess
#
# From: Basic Computer Games (1978)
#
# "In program Guess, the computer chooses a random
# integer between 0 and any limit and any limit you
# set. You must then try to guess the number the
# computer has choosen using the clues provideed by
# the computer.
# You should be able to guess the number in one less
# than the number of digits needed to represent the
# number in binary notation - i.e. in base 2. This ought
# to give you a clue as to the optimum search technique.
# Guess converted from the original program in FOCAL
# which appeared in the book "Computers in the Classroom"
# by Walt Koetke of Lexington High School, Lexington,
# Massaschusetts.
#
########################################################
"""
Guess
From: Basic Computer Games (1978)
"In program Guess, the computer chooses a random
integer between 0 and any limit and any limit you
set. You must then try to guess the number the
computer has choosen using the clues provideed by
the computer.
You should be able to guess the number in one less
than the number of digits needed to represent the
number in binary notation - i.e. in base 2. This ought
to give you a clue as to the optimum search technique.
Guess converted from the original program in FOCAL
which appeared in the book "Computers in the Classroom"
by Walt Koetke of Lexington High School, Lexington,
Massaschusetts.
"""

# Altough the introduction says that the computer chooses
# a number between 0 and any limit, it actually chooses
Expand Down
99 changes: 51 additions & 48 deletions 48_High_IQ/python/High_IQ.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,46 @@
def new_board():
# Using a dictionary in python to store the board, since we are not including all numbers within a given range.
board = {}
for i in [
13,
14,
15,
22,
23,
24,
29,
30,
31,
32,
33,
34,
35,
38,
39,
40,
42,
43,
44,
47,
48,
49,
50,
51,
52,
53,
58,
59,
60,
67,
68,
69,
]:
board[i] = "!"
board[41] = "O"
return board
from typing import Dict


def new_board() -> Dict[int, str]:
"""
Using a dictionary in python to store the board,
since we are not including all numbers within a given range.
"""
return {
13: "!",
14: "!",
15: "!",
22: "!",
23: "!",
24: "!",
29: "!",
30: "!",
31: "!",
32: "!",
33: "!",
34: "!",
35: "!",
38: "!",
39: "!",
40: "!",
42: "!",
43: "!",
44: "!",
47: "!",
48: "!",
49: "!",
50: "!",
51: "!",
52: "!",
53: "!",
58: "!",
59: "!",
60: "!",
67: "!",
68: "!",
69: "!",
41: "O",
}


def print_instructions() -> None:
Expand Down Expand Up @@ -73,7 +76,7 @@ def print_instructions() -> None:
)


def print_board(board) -> None:
def print_board(board: Dict[int, str]) -> None:
"""Prints the boards using indexes in the passed parameter"""
print(" " * 2 + board[13] + board[14] + board[15])
print(" " * 2 + board[22] + board[23] + board[24])
Expand Down Expand Up @@ -131,7 +134,7 @@ def play_game() -> None:
print("SAVE THIS PAPER AS A RECORD OF YOUR ACCOMPLISHMENT!")


def move(board):
def move(board: Dict[int, str]) -> bool:
"""Queries the user to move. Returns false if the user puts in an invalid input or move, returns true if the move was successful"""
start_input = input("MOVE WHICH PIECE? ")

Expand All @@ -154,7 +157,7 @@ def move(board):
return False

difference = abs(start - end)
center = (end + start) / 2
center = int((end + start) / 2)
if (
(difference == 2 or difference == 18)
and board[end] == "O"
Expand All @@ -175,20 +178,20 @@ def main() -> None:
play_game()


def is_game_finished(board):
# Checks all locations and whether or not a move is possible at that location.
def is_game_finished(board) -> bool:
"""Check all locations and whether or not a move is possible at that location."""
for pos in board.keys():
if board[pos] == "!":
for space in [1, 9]:
# Checks if the next location has a peg
nextToPeg = ((pos + space) in board) and board[pos + space] == "!"
next_to_peg = ((pos + space) in board) and board[pos + space] == "!"
# Checks both going forward (+ location) or backwards (-location)
hasMovableSpace = (
has_movable_space = (
not ((pos - space) in board and board[pos - space] == "!")
) or (
not ((pos + space * 2) in board and board[pos + space * 2] == "!")
)
if nextToPeg and hasMovableSpace:
if next_to_peg and has_movable_space:
return False
return True

Expand Down
2 changes: 1 addition & 1 deletion 51_Hurkle/python/hurkle.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


def direction(A, B, X, Y) -> None:
"""Prints the direction hint for finding the hurkle."""
"""Print the direction hint for finding the hurkle."""

print("GO ", end="")
if Y < B:
Expand Down
Loading

0 comments on commit 4b3b991

Please sign in to comment.