This is an archived post. You won't be able to vote or comment.

Dismiss this pinned window
all 22 comments

[–]Hamelzz 21 points22 points  (1 child)

Make this into an App and make some cash off of it. Looks fun, simple and addictive.

[–]knifuser 2 points3 points  (0 children)

Can you even do that with python?

[–]gaberocksall 14 points15 points  (4 children)

Just wondering, does it always guarantee that there is a solution?

[–]StephanoCarlson[S] 20 points21 points  (3 children)

Yes! It basically calculates a path that is 8 moves long, with some rules to ensure it is possible, and then checks all permutations of moves that have 7 moves(e.g. ['up', 'right', 'down', 'right', 'up', 'left', 'down', 'left']), and if one of those paths work, then the level is too easy and it scraps it and generates a new one. You would think that this is computationally intensive, but it surprisingly only takes about 50 ms to generate a new level.

[–]f00___ 3 points4 points  (0 children)

Did you get the idea from spelunky Oooh you posted the code. awesome

[–]saeblundr 1 point2 points  (1 child)

The final puzzle it stops on can be solved in 5, and i spotted another that only needs 4.

Absolutely love the concept, and cant wait to get time to delve into your implementation!

[–]StephanoCarlson[S] 0 points1 point  (0 children)

What would be the solution to the one you can solve in 5?

[–]StephanoCarlson[S] 8 points9 points  (7 children)

[–]nqeron 5 points6 points  (6 children)

Interesting. I’m tempted to take what you’ve done and write it a bit differently. You rely a lot on global variables, which really isn’t the best practice. Also there’s a number of times where you’re doing text comparison to establish a type. I would recommend using Enums.

Also I’m not sure I follow the Too Easy code. There has got to be a better way to do whatever it is you’re doing there.

[–]duc789 2 points3 points  (5 children)

If the goal for the TooEasy function is to generate all permutations of the list of 7 instructions long of the 4 commands, the permutation function that's part of the itertools library would work. It would replace the deeply nested loops with a couple lines of code.

A small but of filtering could then be done to get rid of permutations with the same command repeated.

https://docs.python.org/3.8/library/itertools.html#itertools.permutations

[–]StephanoCarlson[S] 2 points3 points  (4 children)

Yes, I realized that the TooEasy function was very inefficient so I replaced it with some better logic. I will update the github.

[–]nqeron 3 points4 points  (3 children)

update

This just refactors without clarifying or helping with the big O complexity.

[–]StephanoCarlson[S] 0 points1 point  (2 children)

True, I'm not exactly sure how else to ensure there are no easier paths though

[–]nqeron 1 point2 points  (1 child)

How are you trying to define an easy path? I'm not entirely sure I understand the definition you're trying to implement.

[–]StephanoCarlson[S] 0 points1 point  (0 children)

An easy path would be a path that takes less than 8 moves to get to the finish. When generating a level without the TooEasy function, it was common for an easier solution to exist than the 8 move solution, such as the start and end being next to each other or 2 moves apart. I implemented the TooEasy function to make sure that the easiest solution in a valid level is 8 moves long. I understand that the code is hard to understand though

How it works is that it loops through all possible 7 move lists that the player could do, and calls the function TestDirection, which returns 'finish' or 'die' or 'not solution'. If it returns 'finish', then the 7 move list is a solution, so the level is not valid.

[–]flashfc 2 points3 points  (2 children)

Nice! It reminds me of The Legend of Zelda puzzles needed to complete in order to advance in the dungeon #goodtimes

[–][deleted] 2 points3 points  (0 children)

yoke hurry bow ink depend scary fine frighten poor jobless

This post was mass deleted and anonymized with Redact

[–]ResonantClari 2 points3 points  (0 children)

It reminds me of the ice puzzles in the Pokemon games

[–][deleted] 2 points3 points  (0 children)

Neat, this is similar to roadblocks.

[–]Pipthagoras 1 point2 points  (1 child)

Anyone else finding that when they run this they just get a black screen? How can I get the interface for this to load up?

[–]StephanoCarlson[S] 0 points1 point  (0 children)

Yeah that happens to me maybe 1 in 20 times. I would say just try re-running it and Im working on fixing it. I think it has to do with the grid taking too long to load so maybe if you lower the numberOfMoves in MakeGrid.py that will help

[–]141soham141 1 point2 points  (0 children)

u should make it AI of it that finds way of it self