Infinite minesweeper game
This game implementation uses sets instead of arrays:
# array logic
if grid[x][y].is_mine:
...
# set logic
if (x, y) in coordinates.mines:
...
The result of this simple change is that the game can progress indefinitely without the need to explicitly resize arrays.
I originally prototyped this game in Python, then wrote it in C++, and then rewrote it here in Python.
This program was much easier to write in Python than in C++. For such a bloated language, C++ lacks many useful features.
- C++
std::unordered_set
cannot be used directly withstd::pair
. I had to write a hash function that basically treatedstd::pair<long, long>
as a string. - Python integers have unlimited precision whereas C++ has no such data type. Expect to see integer overflow once you move the cursor past
LONG_MIN
orLONG_MAX
. - It took until C++20 for
std::unordered_set
to get thecontains
method. Previous versions of C++ had to use the iterator syntax.
This project requires Python 3.10 or newer and uses only the standard library. You do not need to install anything else, unless you are on Windows:
The Windows version of Python doesn't include the
curses
module. A ported version called UniCurses is available.
Use the -h
flag to see the help text.
python3 -m pymines -h
Key | Action |
---|---|
Arrow keys | Move cursor |
Enter | Uncover cell at cursor |
Space | Flag or chord cell at cursor |
w s a d |
Scroll window (fine) |
W S A D |
Scroll window (coarse) |
0 |
Scroll to (0, 0) |
c |
Center window to cursor |
r |
Refresh window |
q |
Quit |
Have fun! ♾️