23
2
Given a level from a simple platform game, your task is to make a program or function to determine if a level is winnable. Platform game levels are 4 characters tall and any number of characters wide. There is exactly one platform for each horizontal space in a level:
======= =
== = =
=== =====
= ==== ===
The game consists of jumps. Jumps start from the space above the platform which is being jumped from, and end in the space above the platform which is being jumped to (these can be above the 4 platform height levels). To complete a jump, it must be possible to move from the start point to the end point in four or less (including the start/end points) up, down, left, and right moves which do not pass through a platform. Here are some examples (marked with A for start platform and B for end platform):
>>>
^ B
=A
=
>>>>
=A B=
>>
^B
A
Horizontal moves along a platform are just jumps which only move in one direction:
>>
==AB===
The player would start on the leftmost platform, and wins by standing on the rightmost one (marked with v
s):
v === v
=== ==
Test cases
Winnable:
=== ==
= =====
=
==
= ==
=== ====
==== =
===
=
===
== == =
=
= == == =
Unwinnable:
======
======
======= =
= =
=
=
=
=
= =
== == ====
Rules
Your program should output one distinct value if a level is winnable, and a different one if it isn't. It can take input in any reasonable form, such as an ASCII art with any two distinct characters, a matrix, or a 2d array.
Code golf, so shortest answer per language wins.
The second test case has a gap -- is that allowed? May we take input column by column? – xnor – 2019-12-02T23:53:08.533
@xnor The gap is 2 wide, so it is jumpable. You may take input column-by-column. – Redwolf Programs – 2019-12-03T00:04:42.217
1Why is the last case unwinnable? – Nick Kennedy – 2019-12-03T00:07:26.883
@NickKennedy Any jump would be 5 units. Falling is included in the jump limit. – Redwolf Programs – 2019-12-03T00:08:22.490
@xnor Oh, oops, there should be some unreachable platforms above for that one. Thanks for pointing that out. – Redwolf Programs – 2019-12-03T00:10:57.013
@RedwolfPrograms I see - it was the counting of the start that through me. I was expecting it to involve four moves (right, down, down, down). – Nick Kennedy – 2019-12-03T00:11:24.800
3There should be a testcase where the player needs to move left to complete the level – Embodiment of Ignorance – 2019-12-03T04:21:46.337
2Another good pair of test cases would be where platforms alternate between the top and bottom position for a while, and you need to choose the upper or lower path at the start but only one of them gets to the finish. – xnor – 2019-12-03T05:38:46.777
1Is the requirement "which [The moving] do not pass through a platform" really needed? Could anyone provide a testcase which may yield different result when this requirement is removed? – tsh – 2019-12-03T08:20:03.763
3Suggested testcase: $ \begin{bmatrix} &&=&&&=\\=&&&=\&=&&&=\end{bmatrix} $ – tsh – 2019-12-03T08:23:09.440
3Suggested testcase: $ \begin{bmatrix} &=&&&=&&&=&&&=\\\=&&=&=&&=&=&&=&=&& \end{bmatrix} $ – tsh – 2019-12-03T09:07:14.727
@tsh Imagine the last winnable testcase, but the first one is at height 3. You'd be able to jump to the one below, except you'd be stopped by the one in front of you. – Redwolf Programs – 2019-12-03T13:34:17.103
4@tsh The "[moves] which do not pass through a platform" rule can be safely ignored because of the "one platform per column" rule. You can simply jump on any platform that blocks an otherwise legal jump. (In the proposed counterexample, the platform in column 3 does not block a jump from column 1 to column 2.) – Nitrodon – 2019-12-03T18:34:48.343
@Nitrodon But by jumping to the one on level 4 it is impossible to win – Redwolf Programs – 2019-12-03T18:56:52.063
@RedwolfPrograms The platform on level 4 doesn't block anything. In that test case, you would jump from the platform on level 3 (column 1) to the platform on level 1 (column 2). – Nitrodon – 2019-12-03T19:02:10.723
@Nitrodon But if it were at level 3 the level 4 one would block you, since you'd have to pass through it – Redwolf Programs – 2019-12-03T19:43:32.743
Suggests simple test case for block test [[0,0,0,1,0], [1,1,1,0,0], [0,0,0,0,0], [0,0,0,0,1]] – AZTECCO – 2019-12-03T23:47:39.803
1Why is the second unwinnable test case unwinnable? Mario would have no problem with it. – Eric Duminil – 2019-12-04T13:22:20.630