Skip to content

Commit 3ead607

Browse files
committed
gameoflife
1 parent 8be7426 commit 3ead607

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

gameoflife/gameoflife.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,11 @@ def update(board: Board, surface: Surface) -> Board:
137137
new_row = empty_row()
138138
for x, cell in enumerate(row):
139139
neighbor_count = neighbors(x, row, prev_row, next_row, surface)
140-
new_row.append(
141-
LIVE if neighbor_count == 3 else cell if neighbor_count == 2 else DEAD
142-
)
140+
# "normal" RULE B3/S23
141+
new_cell = LIVE if neighbor_count == 3 else cell if neighbor_count == 2 else DEAD
142+
# RULE B3/S12345
143+
# new_cell = LIVE if neighbor_count == 3 else cell if neighbor_count in [1, 2, 3, 4, 5] else DEAD
144+
new_row.append(new_cell)
143145
new_board.append(new_row)
144146
prev_row = row
145147
return new_board

gameoflife/gameoflife_screensaver

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/sh
2-
DELAY=0.02
3-
FILES="${FILES:-samples}"
2+
BASE="$(dirname "$0")"
3+
DELAY="${DELAY:-0.02}"
4+
FILES="${FILES:-$BASE/samples}"
45
MAX_ITERATIONS="${MAX_ITERATIONS:-300}"
56

67
# Allow the user to skip to next by pressing Ctrl-C
@@ -9,14 +10,14 @@ MAX_ITERATIONS="${MAX_ITERATIONS:-300}"
910
while true; do
1011
# Shuffle file order each loop
1112
for file in $(find "$FILES" -type f -iname *.txt | shuf); do
12-
"$(dirname "$0")"/gameoflife.py \
13+
"$BASE/gameoflife.py" \
1314
--file "$file" \
1415
--pretty --color on --delay "$DELAY" \
1516
--expand-to-size \
1617
--iterations "$MAX_ITERATIONS" \
1718
$@
1819
done
19-
"$(dirname "$0")"/gameoflife.py \
20+
"$BASE/gameoflife.py" \
2021
--random \
2122
--pretty --color on --delay "$DELAY" \
2223
--expand-to-size \

0 commit comments

Comments
 (0)