8y/o son & I try to translate 1982 BASIC version of war to python. Spaghetti code (& more!) prevents success. So I write a new one from scratch
https://gist.github.com/matthewdeanmartin/5265d9dbee4e9cabbdfa2ad1c2224f04
I immediately generalized to n players because I didn't want to mess with player1, player2 variables. Dict-as-a-object's a big help. Some code is harder without the higher-level concepts being introduced fast.
♡ 1 ↻ 0Python's lack of a break for nested while/for constructions means you *must* add functions or the "simpler" code with no functions is hard to reason about & will just have bugs (break doesn't do what you think) or complexity (ad hoc flags)
♡ 1 ↻ 0Also, all these for loops, should be converted to list comprehension patterns. And the dict should be upgrade to a real class. Each of these makes the code "simpler" at the cost of needing another concept you might not have learned about as an 8 y/o coder
♡ 1 ↻ 0