最近私はAlcazarというゲームをしています。それはあなたの目標が1つのドアから入力し、すべての正方形を通過し、別のドアを介して終了するボードパズルゲームです。唯一のルールは次のとおりです。
- 一度入力し、一度離れる;
- すべての四角形を通り抜ける:
- 正方形を複数回通過しない
下の画像は、Alcazarボードの例とその右の解決済みのパズルを示しています(もちろんこれは簡単です)。
より多くのパズルを見つけるには、 http://www.theincrediblecompany.com/try-alcazar
をダウンロードしてください。 PlayStoreでの試合(PS:広告ではない)。
私の問題は、1レベルを除いて、ゲームをほぼ終了したことです。私は単にそれを解決する方法を見つけることができません。したがって、私が提案する課題は、通常の
1 解決可能な 2 Alcazarレベルを解決するアルゴリズムを作成することです。
もちろん、画像を読んでパズルを解くためにイメージ通訳を作る人はいませんか?そこで私は上記のパズルをボックスの描画文字を使って再描画しました。パズルとその解決策は次のようになります:
╔═══════╗ ╔═══════╗
║▒ ▒ ▒ ▒║ ║┌─┐ ┌─┐║
║ ║ ║ ║│ │ │║│║
╣▒ ▒ ▒║▒╠ ╣│ └─┘║└╠
║ ══╦═╩═╣ ║│══╦═╩═╣
║▒ ▒║▒ ▒║ ║└─┐║┌─┐║
║ ║ ║ ==> ║ │║│ │║
╣▒ ▒║▒ ▒║ ╣┐ │║│ │║
║ ║ ║ ║ ║│║│║│ │║
╣▒║▒ ▒ ▒║ ╣│║└─┘ │║
║ ║ ║ ║│║ │║
║▒ ▒ ▒ ▒║ ║└─────┘║
╚═══════╝ ╚═══════╝
上記のボードでは、▒
は塗りつぶすセルです。
細胞間に垂直および水平の隙間があることを観察することができる。これは、壁を追加するためにセルの間にスペースを挿入する必要があったためです。これは、唯一の重要な細胞は、各細胞の上、下、左、右のものであることを意味する。対角線は情報を失うことなく取り除くことができます。例えば、下のボードでは、どちらも同じパズルを表しています。
╔════╩╗ ═ ═ ╩
║▒ ▒ ▒║ ║▒ ▒ ▒║
║ ═══ ║ ═
║▒ ▒ ▒║ == ║▒ ▒ ▒║
║ ║
║▒ ▒ ▒║ ║▒ ▒ ▒║
╚╦════╝ ╦═ ══
これはソリューションにも有効です。つまり、セルを接続する必要はありません。
╔════╩╗ ╔════╩╗ ╔════╩╗
║▒ ▒ ▒║ ║┌───┘║ ║┌ ─ ┘║
║ ═══ ║ ║│═══ ║ ║ ═══ ║
║▒ ▒ ▒║ == ║└───┐║ => ║└ ─ ┐║
║ ║ ║ │║ ║ ║
║▒ ▒ ▒║ ║┌───┘║ ║┌ ─ ┘║
╚╦════╝ ╚╦════╝ ╚╦════╝
上記の例では、両方のソリューションが同じ意味を持ちます。
はい、テストケース。どうぞ:
パズル1
╔════╩╗ ╔════╩╗
║▒ ▒ ▒║ ║┌ ─ ┘║
║ ═══ ║ ║ ═══ ║
║▒ ▒ ▒║ => ║└ ─ ┐║
║ ║ ║ ║
║▒ ▒ ▒║ ║┌ ─ ┘║
╚╦════╝ ╚╦════╝
パズル2
╔═════╗ ╔═════╗
║▒ ▒ ▒║ ║┌ ─ ┐║
║ ║ ║ ║ ║ ║
╣▒ ▒║▒║ ╣└ ┐║│║
║ ║ ║ ║ => ║ ║ ║ ║
╣▒║▒ ▒╠ ╣┐║│ │╠
║ ║ ║ ║ ║ ║
║▒ ▒ ▒║ ║└ ┘ │║
╚════╦╝ ╚════╦╝
パズル3
╔════╩══╗ ╔════╩══╗
║▒ ▒ ▒ ▒║ ║┌ ┐ └ ┐║
║ ║ ║ ║ ║ ║ ║ ║
╣▒║▒ ▒║▒╠ ╣┘║└ ┐║│╠
║ ╚══ ║ ║ ║ ╚══ ║ ║
║▒ ▒ ▒ ▒╠ => ║┌ ─ ┘ │╠
║ ═══ ║ ║ ═══ ║
║▒ ▒ ▒ ▒║ ║│ ┌ ┐ │║
║ ║ ║ ║ ║ ║
║▒ ▒║▒ ▒║ ║└ ┘║└ ┘║
╚═══╩═══╝ ╚═══╩═══╝
パズル4
╔═══════╗ ╔═══════╗
║▒ ▒ ▒ ▒║ ║┌ ┐ ┌ ┐║
║ ║ ║ ║ ║ ║
╣▒ ▒ ▒║▒╠ ╣│ └ ┘║└╠
║ ══╦═╩═╣ ║ ══╦═╩═╣
║▒ ▒║▒ ▒║ ║└ ┐║┌ ┐║
║ ║ ║ => ║ ║ ║
╣▒ ▒║▒ ▒║ ╣┐ │║│ │║
║ ║ ║ ║ ║ ║ ║ ║
╣▒║▒ ▒ ▒║ ╣│║└ ┘ │║
║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒║ ║└ ─ ─ ┘║
╚═══════╝ ╚═══════╝
パズル5
╔══╩══════╗ ╔══╩══════╗
║▒ ▒ ▒ ▒ ▒║ ║┌ ─ ┐ ┌ ┐║
║ ║ ║ ║ ║ ║
║▒ ▒║▒ ▒ ▒╠ ║└ ┐║└ ┘ │╠
║ ╠════ ║ ║ ╠════ ║
║▒ ▒║▒ ▒ ▒║ => ║┌ ┘║┌ ─ ┘║
║ ║ ║ ║ ║ ║
║▒ ▒║▒ ▒ ▒╠ ║└ ┐║└ ─ ─╠
║ ╠═════╣ ║ ╠═════╣
║▒ ▒║▒ ▒ ▒║ ║┌ ┘║┌ ─ ┐║
║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒║ ║└ ─ ┘ ┌ ┘║
╚══╦═══╦══╝ ╚══╦═══╦══╝
パズル6
╔═══════════╗ ╔═══════════╗
║▒ ▒ ▒ ▒ ▒ ▒║ ║┌ ┐ ┌ ┐ ┌ ┐║
║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒║ ║│ └ ┘ └ ┘ │║
║ ═══ ║ ║ ═══ ║
║▒ ▒ ▒ ▒ ▒ ▒║ ║└ ┐ ┌ ─ ─ ┘║
║ ═══ ║ ║ ═══ ║
╣▒ ▒ ▒ ▒ ▒ ▒╠ => ╣┐ │ │ ┌ ┐ ┌╠
║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒║ ║│ │ │ │ │ │║
║ ║ ║ ║ ║ ║ ║ ║
║▒ ▒║▒ ▒║▒ ▒║ ║│ │║│ │║│ │║
║ ║ ║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒║ ║└ ┘ └ ┘ └ ┘║
╚═══════════╝ ╚═══════════╝
パズル7
╔════╩════════╦╩╗ ╔════╩════════╦╩╗
║▒ ▒ ▒ ▒ ▒ ▒ ▒║▒║ ║┌ ─ ─ ─ ─ ─ ┐║│║
║ ║ ║ ║ ║ ║ ║ ║ ║ ║
║▒║▒ ▒ ▒ ▒║▒ ▒ ▒║ ║│║┌ ─ ─ ┐║┌ ┘ │║
║ ║ ║ ═══ ║ ║ ║ ║ ║ ═══ ║ ║
║▒ ▒║▒ ▒ ▒ ▒ ▒ ▒╠ ║│ │║┌ ─ ┘ └ ┐ │╠
║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║ ║│ │ └ ┐ ┌ ┐ └ ┘║
║ ║ ║ ══╣ ║ ║ ║ ══╣
║▒ ▒ ▒║▒║▒ ▒ ▒ ▒║ ║│ └ ┐║│║│ └ ─ ┐║
║ ║ ║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║ ║│ ┌ ┘ │ └ ┐ ┌ ┘║
║ ║ ══╣ => ║ ║ ══╣
║▒ ▒ ▒ ▒ ▒ ▒║▒ ▒║ ║└ ┘ ┌ ┘ ┌ ┘║└ ┐║
╠══ ║ ╚══ ║ ╠══ ║ ╚══ ║
║▒ ▒ ▒ ▒ ▒║▒ ▒ ▒║ ║┌ ┐ └ ┐ │║┌ ─ ┘║
║ ║ ║ ║ ║ ║ ║ ║ ║ ║
║▒ ▒ ▒║▒║▒ ▒ ▒ ▒║ ║│ └ ┐║│║│ └ ─ ┐║
║ ║ ║ ║ ╔══ ║ ║ ║ ║ ║ ╔══ ║
║▒║▒ ▒ ▒ ▒║▒ ▒ ▒║ ║│║┌ ┘ │ │║┌ ┐ │║
║ ║ ║ ║ ║ ║ ║ ║ ║ ║
║▒ ▒ ▒ ▒║▒ ▒ ▒ ▒║ ║│ └ ─ ┘║└ ┘ │ │║
║ ╚══ ║ ║ ╚══ ║
║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║ ║└ ─ ─ ─ ─ ─ ┘ │║
╚════╦═╦═╦═════╦╝ ╚════╦═╦═╦═════╦╝
パズル8(申し訳ありませんが、私は本当にこの解決策を持っていません)
╔══╩╦══╩═══╩═╩═╩═══╩╗
║▒ ▒║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║
║ ║ ║
╣▒ ▒║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║
║ ╚══ ╔══ ╔═══╣
╣▒ ▒ ▒ ▒║▒ ▒ ▒ ▒║▒ ▒╠
║ ║ ╔══ ║ ║
╣▒ ▒ ▒ ▒ ▒ ▒║▒ ▒ ▒ ▒╠
║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒╠
║ ║ ║
╣▒ ▒ ▒ ▒ ▒ ▒║▒ ▒ ▒ ▒╠
║ ╔═══╗ ╚══ ║
╣▒ ▒║▒ ▒║▒ ▒ ▒ ▒ ▒ ▒║
║ ║ ║ ║
╣▒ ▒║▒ ▒║▒ ▒ ▒ ▒ ▒ ▒╠
║ ══╝ ║ ╔══ ║
║▒ ▒ ▒ ▒║▒ ▒ ▒ ▒║▒ ▒║
║ ══╗ ╚══ ╔══ ║ ║
╣▒ ▒ ▒║▒ ▒ ▒║▒ ▒ ▒ ▒╠
║ ║ ║ ║ ║
╣▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║▒ ▒║
║ ═══ ══╗ ║ ║
╣▒ ▒ ▒ ▒ ▒ ▒║▒ ▒ ▒ ▒╠
╠══ ║ ║ ╔══ ║
║▒ ▒║▒ ▒ ▒ ▒ ▒ ▒║▒ ▒╠
║ ╚══ ║ ║ ║ ║
╣▒ ▒ ▒ ▒║▒ ▒║▒ ▒ ▒ ▒╠
║ ║ ║ ║
║▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒ ▒║
╚══╦═══╦═══╦═╦═╦═╦═╦╝
入力
The 入力 of your code can have any representation as long as it
follow these rules:
-
It must be a graphical 入力. So it is not possible to read a
coordinate list, for example. -
Horizontal walls, vertical walls, and doors must be distinct,
and they must be made of a visible character (no blank
characters). -
The
▒
can be replaced by blanks. I just used a
different character to highlight them.
出力
The 出力 can also have any representation as long as it follows
these rules:
-
It must be a graphical 出力. That is, one can see the path by
looking at it. -
Rule number one implies that the path characters be different.
That is, there are going to be at least 6 path characters;
horizontal, vertical, and corners. -
For the answer to be valid, the 出力 must be the same board as the
入力 (obviously) with all the cells (in my representation, the
▒
) filled. Filling the gaps between the cells is
optional.
スコアリング
This is code-golf,
so the shortest code in bytes wins.
1 There are some Alcazar levels that have optional
cells and tunnels. These will not be considered.
2 There are some Alcazar boards that are
impossible.
Python 3, 809
728 723 714
693 688 684
663 657 641
639 627 610
571 569 bytes
Edit: Saved 55 bytes thanks to
@Felipe Nardi Batista
TIO上で最後のテストケースを60秒間実行しませんが、正しく動作するはずです。パスの座標のリストを返します。一部
バイトの400は、I/Oからデータリストを取得するために使用されます。
A=enumerate
I,J="═║"
B=range
L=len
K=-1
Z=1,0
X=0,1
C=K,0
V=0,K
E=lambda a,b,p:(((a,b)in d)*L(p)==H*h)*p or max([E(q+a,w+b,p+[(q+a,w+b)])for q,w in y[a][b]if~-((q+a,w+b)in p)*-h>w+b>K