A simple minesweeper generator for Python 3
Project description
A simple minesweeper generator for Python 3
Created by Steven Shrewsbury (stshrewsburyDev)
Changelogs:
Version 2.0
- Rewrote all code
- Changed import name to
minesweeper
- All functions/class names updated to be more clear
- Added
config
to the generator class - Removed
gridInfo
function
Installation:
Install with pip:
pip install minesweeperPy
Update with pip:
pip install minesweeperPy --upgrade
Install from source:
python setup.py install
Using in your code:
Importing:
import minesweeper
Creating a new generator:
cols = 8 # Number of collums in each grid
rows = 5 # Number of rows in each grid
my_generator = minesweeper.Generator(cols, rows)
Notes:
- The values you enter into a generator object can be changed at any point using
Generator.config()
- The number of cells in each grid is calculated by multiplying the column count by the row count:
Cols: | Rows: | Cells: |
---|---|---|
8 | 5 | 40 |
10 | 10 | 100 |
25 | 20 | 500 |
48 | 60 | 2880 |
Generating a new grid:
mines = 10 # Number of mines to put in the grid
my_grid = my_generator.generate(mines)
Notes:
- If you wish to get just the 2D list grid then refer to the generating of a "raw" grid
- The number of mines cannot be smaller than 0
- The number of mines cannot be larger than the total cells in the target grid (eg: a 10x10 grid can have a max of 100 mines)
Output:
>>>my_grid
{'blank_id': ' ',
'grid': [['1', '2', 'M', '2', 'M', 'M', '3', '1'],
['2', 'M', '3', '3', '3', 'M', '3', 'M'],
['M', '4', 'M', '2', '1', '1', '2', '1'],
['1', '3', 'M', '3', '1', '1', ' ', ' '],
[' ', '1', '1', '2', 'M', '1', ' ', ' ']],
'mine_id': 'M',
'size_x': 8,
'size_y': 5}
Generating a "raw" grid:
mines = 10 # Number of mines to put in the grid
my_grid = my_generator.generate_raw(mines)
Output:
>>>my_grid
[['1', '2', 'M', '2', 'M', 'M', '3', '1'],
['2', 'M', '3', '3', '3', 'M', '3', 'M'],
['M', '4', 'M', '2', '1', '1', '2', '1'],
['1', '3', 'M', '3', '1', '1', ' ', ' '],
[' ', '1', '1', '2', 'M', '1', ' ', ' ']]
Using custom blank and mine cell IDs:
cols = 8 # Number of collums in each grid
rows = 5 # Number of rows in each grid
blank_ID = "_" # The cell "placeholder" for blank cells
mine_ID = "$" # The cell "placeholder" for mine cells
my_generator = minesweeper.Generator(cols, rows, blank_ID, mine_ID)
A generated grid with this generator example would look like this:
{'blank_id': '_',
'grid': [['1', '2', '$', '2', '$', '$', '3', '1'],
['2', '$', '3', '3', '3', '$', '3', '$'],
['$', '4', '$', '2', '1', '1', '2', '1'],
['1', '3', '$', '3', '1', '1', '_', '_'],
['_', '1', '1', '2', '$', '1', '_', '_']],
'mine_id': '$',
'size_x': 8,
'size_y': 5}
Configuring an existing generator object:
new_cols = 12
new_rows = 10
new_blank_ID = "-"
new_mine_ID = "%"
my_generator.config(new_cols, new_rows, new_blank_ID, new_mine_ID)
Using a preset:
Without custom cell IDs:
level = minesweeper.Presets.easy
my_grid = minesweeper.generate_preset(level)
With custom cell IDs:
level = minesweeper.Presets.easy
blank_ID = "_"
mine_ID = "$"
my_grid = minesweeper.generate_preset(level, blank_ID, mine_ID)
Using a "raw" output type:
level = minesweeper.Presets.easy
my_grid = minesweeper.generate_preset_raw(level)
Note:
- All outputs of these are the same as the normal grids.
Links:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
minesweeperPy-2.0.tar.gz
(4.6 kB
view hashes)
Built Distribution
Close
Hashes for minesweeperPy-2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc38b4bac1d33c02f6abe062fdcd5379f332f92a629588f4b22f470ef207d259 |
|
MD5 | 75bcfde45b1834ffc96b929a23868790 |
|
BLAKE2b-256 | 6f810f6bc4541177581638063a595fcff95629265302e52fe354f418f58c9d5d |