coding-horror / basic-computer-games

An updated version of the classic "Basic Computer Games" book, with well-written examples in a variety of common MEMORY SAFE, SCRIPTING programming languages. See https://coding-horror.github.io/basic-computer-games/
The Unlicense
10.84k stars 1.33k forks source link

56 life for two python #769

Closed sajidsarker closed 2 years ago

sajidsarker commented 2 years ago

I've created a port for 56 - Life for Two in Python!

However, it appears there is some issue with some of the logic which I could not parse clearly from BASIC (terrible nesting of GOTOs), so I needed to check the available Javascript port as reference.

I wished to open a pull request for now, hopefully allowing others to have eyes on whether I made a mistake or otherwise.

coding-horror commented 2 years ago

python checks failed?

sajidsarker commented 2 years ago

Dear Jeff (@coding-horror)

python checks failed?

I made the fix and am trying again. Sorry, I was travelling and could not attend to this!

I have added one new commit with a correction based on the suggestion of the Python validation check output:

from typing import List

coding-horror commented 2 years ago

Here's the error from the failed check

Run mypy . --exclude [7](https://github.com/coding-horror/basic-computer-games/runs/7437486918?check_suite_focus=true#step:5:8)9_Slalom --exclude 27_Civil_War --exclude 3[8](https://github.com/coding-horror/basic-computer-games/runs/7437486918?check_suite_focus=true#step:5:9)_Fur_Trader --exclude 81_Splat --exclude 0[9](https://github.com/coding-horror/basic-computer-games/runs/7437486918?check_suite_focus=true#step:5:10)_Battle --exclude 40_Gomoko --exclude 36_Flip_Flop --exclude 43_Hammurabi --exclude 04_Awari --exclude 78_Sine_Wave --exclude 77_Salvo --exclude 34_Digits --exclude 17_Bullfight --exclude 16_Bug
56_Life_for_Two/python/life_for_two.py:22: error: Argument 1 to "append" of "list" has incompatible type "List[<nothing>]"; expected "int"
56_Life_for_Two/python/life_for_two.py:24: error: "int" has no attribute "append"
56_Life_for_Two/python/life_for_two.py:50: error: Unsupported target for indexed assignment ("int")
56_Life_for_Two/python/life_for_two.py:60: error: Unsupported target for indexed assignment ("int")
56_Life_for_Two/python/life_for_two.py:61: error: Unsupported target for indexed assignment ("int")
56_Life_for_Two/python/life_for_two.py:67: error: Value of type "int" is not indexable
56_Life_for_Two/python/life_for_two.py:68: error: Value of type "int" is not indexable
56_Life_for_Two/python/life_for_two.py:70: error: Unsupported target for indexed assignment ("int")
56_Life_for_Two/python/life_for_two.py:70: error: Value of type "int" is not indexable
56_Life_for_Two/python/life_for_two.py:90: error: Value of type "int" is not indexable
56_Life_for_Two/python/life_for_two.py:91: error: Unsupported target for indexed assignment ("int")
56_Life_for_Two/python/life_for_two.py:95: error: Value of type "int" is not indexable
56_Life_for_Two/python/life_for_two.py:99: error: Unsupported target for indexed assignment ("int")
56_Life_for_Two/python/life_for_two.py:[10](https://github.com/coding-horror/basic-computer-games/runs/7437486918?check_suite_focus=true#step:5:11)3: error: Unsupported target for indexed assignment ("int")
56_Life_for_Two/python/life_for_two.py:107: error: Unsupported target for indexed assignment ("int")
56_Life_for_Two/python/life_for_two.py:[11](https://github.com/coding-horror/basic-computer-games/runs/7437486918?check_suite_focus=true#step:5:12)5: error: Incompatible types in assignment (expression has type "str", variable has type "List[str]")
56_Life_for_Two/python/life_for_two.py:1[16](https://github.com/coding-horror/basic-computer-games/runs/7437486918?check_suite_focus=true#step:5:17): error: Incompatible types in assignment (expression has type "str", variable has type "List[str]")
56_Life_for_Two/python/life_for_two.py:1[17](https://github.com/coding-horror/basic-computer-games/runs/7437486918?check_suite_focus=true#step:5:18): error: "List[str]" has no attribute "split"
56_Life_for_Two/python/life_for_two.py:1[18](https://github.com/coding-horror/basic-computer-games/runs/7437486918?check_suite_focus=true#step:5:19): error: "List[str]" has no attribute "split"
Found [19](https://github.com/coding-horror/basic-computer-games/runs/7437486918?check_suite_focus=true#step:5:20) errors in 1 file (checked 86 source files)
Error: Process completed with exit code 1.
sajidsarker commented 2 years ago

Dear Jeff (@coding-horror)

I've gone ahead and removed the type hinting to avoid these errors altogether!

Thank you very much for the review!