How I wrote a command-line Minesweeper game with Python in 30 minutes which is packaged as a Docker container
--
I know it is not a big deal writing a minesweeper game but it is still a thing, if you write it in 30 minutes, right? :)
I will share the repository but first, let me explain how it started. It all started in a technical challenge, it has been asked for creating an “X” by “X” matrix and put “M” amount of “A” letter in it randomly.
I have created some for loops and created the matrix first then created another function for creating a list of random numbers in the range of 0 to (X*X) depending on the mine counts (M) and completed these in approximately 5 minutes.
After that, it has been asked to put the numbers into the cells depending on the mines around them which don’t have mines in them. So this challenge became creating a simple minesweeper game. This part took some more time. :)
Then I had a code which is some kinda part of a minesweeper game. So I decided to work further on it to create a command-line minesweeper game! Of course, it took more than 30 minutes later to polish it a bit and add some simple CI to push it to the docker repository but anyway the main skeleton was ready in 30 minutes.
I don’t want to give details about the functions in this simple program. Most of them, giving an idea with their names about what it is doing exactly. For example, create_mine_field, is_there_a_mine, is_in matrix, etc. But even if you have any questions please feel free to ask in comments below.
I know it is not an actual game but it is good if you are bored in a terminal and want to have some quick fun.
If you think that you can do it better or improve it, PRs are welcome! :)
https://github.com/omerkarabacak/minesweeper
How to run it
with Python
USAGE:
python3 minesweeper.py <size> <mine_count>
EXAMPLE:
python3 minesweeper.py 4 4
with Docker
USAGE:
docker run -it ghcr.io/omerkarabacak/minesweeper:1.0 <size> <mine_count>
EXAMPLE:
docker run -it ghcr.io/omerkarabacak/minesweeper:1.0 4 4