![]() I did not optimize the randomness of the generated mine position, therefore some games could be impossible or too easy. This is simply to demonstrate the algorithm described in this answer. I've taken the liberty of playing a little with JS bin here came up with a functional Minesweeper game demo. For example, to ensure that at least 3 neighboring cells are not mines, or even perhaps favor limiting the number of mines that are too far from each other, etc. Increment grid by 1īecause this algorithm could lead into creating a board with some mines grouped too much together, or worse very dispersed (thus boring to solve), you can then add extra validation when generating mine_x and mine_y number. ![]() Grid = -number_of_mines // negative value = mine Get random mine_x and mine_y where grid(mine_x, mine_y) is not a mine Perhaps something in the lines of : grid = // initialize all cells to 0
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |