Algorithm of C[o]re
MineSwee++ 2 is close-source. However, I decide to make the algorithm of C[o]re public. If you have any idea on improving it, feel free to contribute.
The following pseudo-code is used since MineSwee++ 2 Release Candidate V (2.1.503).
GetGridWithBestProbability(board) returns (row, col)
board: the board being played
row: the row index of the grid to open
col: the column index of the grid to open
begin
initialize board_sum with all 0
initialize board_no_mines_around_sum with all 0
num_mines ← number of mines flagged in board
num_mines_left ← 51 - num_mines
num_matched_board ← 0
while num_matched_board is not large enough and time is not up do
begin
board2 ← generate a board with num_mines_left 1's randomly spread in suited places
and (256 - num_mines_left) 0's in other places
if ((1's of board2) and (mines of board)) matches conditions of board then
begin
add board2 to board_sum
for each corresponding grid in board, grid2 in board2,
gridnma in board_no_mines_around do
begin
if total number of mines around (grid and grid2) = 0 then
begin
gridnma ← 1
end
else
begin
gridnma ← 0
end
end
add board_no_mines_around to board_no_mines_around_sum
num_matched_board ← num_matched_board + 1
end
end
if num_matched_board = 0 then
begin
return (0, 0)
end
best_grid_row ← 0
best_grid_col ← 0
best_grid_probability ← 0
best_grid_probability_no_mines_around ← 0
for r ← 1 to 16 do
begin
for c ← 1 to 16 do
begin
if board_sum[r][c] ≥ best_grid_probability then
begin
if board_sum[r][c] - best_grid_probability > num_matched_board × 0.03
or (board_no_mines_around_sum[r][c] ≤ best_grid_probability_no_mines_around
and neither r nor c is margin) then
begin
best_grid_row ← r
best_grid_col ← c
best_grid_probability ← board_sum[r][c]
best_grid_probability_no_mines_around ← board_no_mines_around_sum[r][c]
end
end
end
end
return (best_grid_row, best_grid_col)
end
|