I implemented a crude version of the game of Battleship in Python. This is all about x and y coordinates. How should one store such a pair of coordinates? I chose a tuple. A tuple in Python is a set of comma separated numbers. Normally they are programmed within parentheses. I just happened to represent the ship coordinates using tuples. Then I put those tuples in a list.
The good thing about tuples is that you access the elements of a tuple like you would a list, with brackets. A zero based index goes in the bracket. The values in the tuple are immutable. Once set, you cannot change them. This is fine as the ships in Battleship are not changing during the game.
Previously I had learned to use the int() function to convert a string to an integer. Well now I know there is also a str() function to convert an integer to a string. Useful information. Where to go next? I might implement a simple encryption method in Python. Or I might go full tilt and try to code the game of Othello. Still might also want to investigate a Python library. So much to learn. So little time.
Reproducing a Race Condition
-
We have a job at work that runs every Wednesday night. All of a sudden, it
aborted the last 2 weeks. This caused some critical data to be late. The
main ...