What to use for flow free-like game random level creation?

后端 未结 5 2181
难免孤独
难免孤独 2020-12-12 15:50

I need some advice. I\'m developing a game similar to Flow Free wherein the gameboard is composed of a grid and colored dots, and the user has to connect the same colored do

5条回答
  •  天涯浪人
    2020-12-12 16:22

    Updated answer: I implemented a new generator using the idea of "dual puzzles". This allows much sparser and higher quality puzzles than any previous method I know of. The code is on github. I'll try to write more details about how it works, but here is an example puzzle: enter link description here

    Old answer: I have implemented the following algorithm in my numberlink solver and generator. In enforces the rule, that a path can never touch itself, which is normal in most 'hardcore' numberlink apps and puzzles

    1. First the board is tiled with 2x1 dominos in a simple, deterministic way. If this is not possible (on an odd area paper), the bottom right corner is left as a singleton.
    2. Then the dominos are randomly shuffled by rotating random pairs of neighbours. This is is not done in the case of width or height equal to 1.
    3. Now, in the case of an odd area paper, the bottom right corner is attached to one of its neighbour dominos. This will always be possible.
    4. Finally, we can start finding random paths through the dominos, combining them as we pass through. Special care is taken not to connect 'neighbour flows' which would create puzzles that 'double back on themselves'.
    5. Before the puzzle is printed we 'compact' the range of colours used, as much as possible.
    6. The puzzle is printed by replacing all positions that aren't flow-heads with a .

    My numberlink format uses ascii characters instead of numbers. Here is an example:

    $ bin/numberlink --generate=35x20
    Warning: Including non-standard characters in puzzle
    
    35 20
    ....bcd.......efg...i......i......j
    .kka........l....hm.n....n.o.......
    .b...q..q...l..r.....h.....t..uvvu.
    ....w.....d.e..xx....m.yy..t.......
    ..z.w.A....A....r.s....BB.....p....
    .D.........E.F..F.G...H.........IC.
    .z.D...JKL.......g....G..N.j.......
    P...a....L.QQ.RR...N....s.....S.T..
    U........K......V...............T..
    WW...X.......Z0..M.................
    1....X...23..Z0..........M....44...
    5.......Y..Y....6.........C.......p
    5...P...2..3..6..VH.......O.S..99.I
    ........E.!!......o...."....O..$$.%
    .U..&&..J.\\.(.)......8...*.......+
    ..1.......,..-...(/:.."...;;.%+....
    ..c<<.==........)./..8>>.*.?......@
    .[..[....]........:..........?..^..
    ..._.._.f...,......-.`..`.7.^......
    {{......].....|....|....7.......@..
    

    And here I run it through my solver (same seed):

    $ bin/numberlink --generate=35x20 | bin/numberlink --tubes
    Found a solution!
    ┌──┐bcd───┐┌──efg┌─┐i──────i┌─────j
    │kka│└───┐││l┌─┘│hm│n────n┌o│┌────┐
    │b──┘q──q│││l│┌r└┐│└─h┌──┐│t││uvvu│
    └──┐w┌───┘d└e││xx│└──m│yy││t││└──┘│
    ┌─z│w│A────A┌┘└─r│s───┘BB││┌┘└p┌─┐│
    │D┐└┐│┌────E│F──F│G──┐H┐┌┘││┌──┘IC│
    └z└D│││JKL┌─┘┌──┐g┌─┐└G││N│j│┌─┐└┐│
    P──┐a││││L│QQ│RR└┐│N└──┘s││┌┘│S│T││
    U─┐│┌┘││└K└─┐└─┐V││└─────┘││┌┘││T││
    WW│││X││┌──┐│Z0││M│┌──────┘││┌┘└┐││
    1┐│││X│││23││Z0│└┐││┌────M┌┘││44│││
    5│││└┐││Y││Y│┌─┘6││││┌───┐C┌┘│┌─┘│p
    5││└P│││2┘└3││6─┘VH│││┌─┐│O┘S┘│99└I
    ┌┘│┌─┘││E┐!!│└───┐o┘│││"│└─┐O─┘$$┌%
    │U┘│&&│└J│\\│(┐)┐└──┘│8││┌*└┐┌───┘+
    └─1└─┐└──┘,┐│-└┐│(/:┌┘"┘││;;│%+───┘
    ┌─c<<│==┌─┐││└┐│)│/││8>>│*┌?│┌───┐@
    │[──[└─┐│]││└┐│└─┘:┘│└──┘┌┘┌┘?┌─^││
    └─┐_──_│f││└,│└────-│`──`│7┘^─┘┌─┘│
    {{└────┘]┘└──┘|────|└───7└─────┘@─┘
    

    I've tested replacing step (4) with a function that iteratively, randomly merges two neighboring paths. However it game much denser puzzles, and I already think the above is nearly too dense to be difficult.

    Here is a list of problems I've generated of different size: https://github.com/thomasahle/numberlink/blob/master/puzzles/inputs3

提交回复
热议问题