Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Procedure:
- for each revealed cell:
- if neighbors.Unknown == cellValue:
- neighbors:FlagAll()
- elseif #neighbors.Flagged == cellValue:
- open all non-flagged neighbors
- else:
- add each non-flagged neighbor to a groupped flag:
- a groupped flag is multiple cells grouped together that function as 1 to groupSize-1 flagged cells
- (logic for grouped flags functions the same as normal flags. i.e, i group is treated as one cell)
- for example, 3 cells grouped together with a flag value of 2
- this means that between the 3 cells there are 2 mines/regular flags but which 2 specifically is currently unknown
- repeat this logic until the board state does not change
- --]]
- -- code:
- local realBoard = {}
- local gameBoard = {}
- local liveBoard = {}
- local showBoard = {}
- local width = 9
- local height = 9
- local mines = 10
- local function shuffle(myTable)
- local function isValid(x,y)
- local function toXY(i)
- local function toIndex(x,y)
- local Neighbors = {}
- function Neighbors.All(x,y)
- function Neighbors.Unknown(x,y)
- function Neighbors.Mines(x,y)
- function Neighbors.Flagged(x,y)
- function Neighbors:Flag(x,y)
- function Neighbors:Open(x,y)
- function Neighbors:Clear(x,y)
- local function getEmptyCells()
- local function display()
- local function update()
- local function expand(x,y)
- local function chord(x,y)
- local isFirst = true
- local function open(x,y)
- if isFirst then
- isFirst = false
- return firstMove(x,y)
- end
- local c = toIndex(x,y)
- if liveBoard[c] == 2 then return end
- liveBoard[c] = 1
- end
- local function flag(x,y)
- local function groupFlag(cells,minFlags,maxFlags)
- for _, i in ipairs(cells) do
- if liveBoard[i]
- liveBoard[i] = {minFlags, maxFlags, {unpack(cells)}}
- end
- end
- local function reduceGroupFlags()
- local groups = {}
- for _, i in ipairs(liveBoard) do
- if type(i) ~= "table" then continue end
- if #i.Cells == i.Flags then
- for _, c in ipairs(i.Cells) do
- liveBoard[c] = 2
- end
- end
- end
- end
- local function validate(firstMove)
- local function labelCells()
- function firstMove(x,y)
- local function setup()
Advertisement
Comments
-
- The idea of this approach is to mimic how a human player would solve the game.
-
- This approach is basically using set theory:
- youtu.be/8j7bkNXNx4M
-
- https://www.chiark.greenend.org.uk/~sgtatham/puzzles/js/mines.html
Add Comment
Please, Sign In to add comment
Advertisement