Package: pygame-minesweeper-core
IntroductionThis minesweeper core library contains the basic functionality of the game.Minesweeper is a single-player puzzle computer game. The objective of the game is to clear a rectangular board containing hidden "mines" or bombs without detonating any of them, with help from clues about the number of neighboring mines in each field. The game originates from the 1960s, and has been written for many computing platforms in use today. It has many variations and offshoots.MotivationThe motivation of these minesweeper projects is to learn the tooling around python projects, how to create CI/CD pipelines for python projects, and distributing python eggs.Getting StartedInstallationpython3-mpipinstallpygame-minesweeper-core# orpipinstallpygame-minesweeper-coreGeneralThere are two classes in this library Board and BoardTile. The Board class contains data of the whole board/game while the BoardTile class only contains data of a single tile. To initialize a new game create a Board class with the required params. A board will be always generated randomly and the first tile that gets opened will never contain a mine. If an empty tile gets opened, adjacent tiles will also get opened.Boardfromminesweeperimportcoreboard=core.Board(rows=10,cols=10,mines=30)There is only a handful of methods and properties you should care about when using the Board class and those are:methodsreturnsgame_new(self, rows: int, cols: int, mines: int):initialize a new game with given parametersgame_reset()initialize a new game with the same parameterstile_open(i: int, j: int) -> List[BoardTile]The valueiis the row/y-axis andjis the col/x-axis. The function returns a list of BoardTiles objects that represents tiles that get opened. The function will return an empty list if you try to open a tile that is already opened, if the game is lost or won, or if you open tile that is out of bounds. The functions open adjacent tiles recursively if the tile has zero adjacent mines. The first tiles that get opened can never be a mine.tile_valid(i : int, j : int) -> boolReturns true ifiandjis inside boundariespropertiesreturnsstr-> strstring representation of the boardis_game_over -> boolreturns true of the player has lostis_game_finished -> boolreturns true if the player has wonrows -> intnumber of rows in the gamecols -> intnumber of column in the gamemines -> intnumber of mines in the gamesolution -> stra string representation of the solutiontimer -> floata floating point number of play time. The timer will start when the first tile gets opened and when stops when either player has lost or won.BoardTilepropertiesreturnsi -> intThe row of the tilej -> intthe columns of the tiletype -> strstring representation of the tilenumber -> intint representation of the tilestaticreturnsmine"x"unopened"t"zero"0"one"1"two"2"three"3"four"4"five"5"six"6"seven"7"eight"8"Examplefromminesweeperimportcoredefmain():board=core.Board(rows=10,cols=10,mines=30)tiles=board.tile_open(5,5)fortileintiles:print(f"tile={tile.type}, ({tile.i},{tile.j})")print(board.is_game_over)print(board.is_game_finished)print(board)print(board.solution)if__name__=="__main__":main()# Outputstile=0,(5,5)tile=1,(5,6)tile=0,(5,4)tile=2,(5,3)tile=1,(6,4)tile=0,(6,5)tile=0,(6,6)tile=0,(6,7)tile=1,(6,8)tile=1,(7,7)tile=1,(7,8)tile=2,(7,6)tile=1,(5,7)tile=2,(5,8)tile=1,(7,5)tile=2,(7,4)tile=3,(6,3)tile=1,(4,4)tile=0,(4,5)tile=1,(4,6)tile=1,(3,5)tile=2,(3,6)tile=2,(3,4)tile=4,(4,3)False

False

tttttttttt
tttttttttt
tttttttttt
tttt212ttt
ttt4101ttt
ttt200112t
ttt310001t
tttt21211t
tttttttttt
tttttttttt

x33xx3x2xx3xx34x323x2x533x212224xx2122x1x5x4101x32x5x200112x
x43310001112xx21211001333x3x32001x22x3xxReferenceshttps://en.wikipedia.org/wiki/Minesweeper_(video_game)