
Frog Mania is a flash game. It is quite easy to play, so this is not about its solver, but the way to get the underlying matrix representation of each level.

Alt+PrintScreen to get the whole game screen image like above. then use the code below to get the Empty/Frog/Dragonfly pattern.
Basic idea:
* Trim the whole image to get the pool
* binarize to only the white frog eyes and dragonfly wings
* split it into 5×6 items
* judge each part by the white zone’s position, whether it’s on the left/right/up/down part of the item
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
(*find both min and max in list fast*)
minMax = Compile[{ {list, _Integer, 1} },
Module[{currentMin, currentMax},
currentMin = currentMax = First[list];
Do[Which[x < currentMin, currentMin = x, x > currentMax,
currentMax = x], {x, list}];
{currentMin, currentMax}], CompilationTarget -> "C",
RuntimeOptions -> "Speed"];
getpat[l_] := Module[{},
imd = ImageData[l];
If[Max[imd] == 0, Return["_"]];
dms = IntegerPart[Dimensions[imd]/2.];
If[Max[imd[[All, ;; dms[[2]]]]] == 0, Return["→"]];
If[Max[imd[[All, dms[[2]] ;;]]] == 0, Return["←"]];
If[Max[imd[[;; dms[[1]], All]]] == 0, Return["↓"]];
If[Max[imd[[dms[[1]] ;;, All]]] == 0, Return["↑"]];
Return["D"]
];
GetFrogManiaMatrix[img_] := Module[{TimeScoreOuterColor = {248, 217, 152}/255., PoolColor = {120, 211, 255}/255., EyeColor = 0.95, minx, t, imgt},
(* get only the pool zone*)
minx = Max[PixelValuePositions[img, TimeScoreOuterColor][[All, 1]]];
t = Transpose[Select[Sort[PixelValuePositions[img, PoolColor]], #[[1]] > minx &]];
imgt = ImageTrim[img, Transpose[Map[minMax, t]]];
Map[getpat, ImagePartition[Binarize[imgt, EyeColor], ImageDimensions[imgt]/{6, 5}], {2}] // Grid
]
GetFrogManiaMatrix[img]
_ ↓ _ ← ↓ ←
← _ _ D ↓ _
D _ _ _ _ _
_ → _ ↓ D _
↑ _ → → D ↑
|
mixMax function is taken from here.




近期评论