Find Your Hat Challenge Project (JavaScript)

Hello!

I just finished this project. If someone wants to check it out: https://github.com/DonHagilito/find-your-hat
I added som custom features:

  • You can decide Field size and hole percentage as a player.
  • Maps are always solveable.

Would really appreciate any feedback.

BR,
Chris

1 Like

I think your project is great! I had a very similar one too. :blush: Very nice that you built an algorithm that returns only solveable maps!

1 Like

Hey Jarq @jarq86 ,

I tested your game and it worked great! I’m really impressed by the algorithm that could find the optimal path.

Here is some feedback after i went through the code:

  • A little bit confusing that you get your dimensions for the map with createRandomMap().
  • currentSpot = […myField.starting_pos]; … havent seen this syntax before. How does it work?
  • I noticed the game flashes a couple of times when im playing it. Don’t know where it comes from but it didn’t happen for me.
  • I think your optimal route algorithm is very similar to my algorithm that checks if a field is solveable. But I just can’t wrap my head around how you can be certain that the route is optimal xD

Anyway thats is. Good job!

Thank you @net7509906129 for the feedback! Always nice to get some.

  • You’re absolutely right about getting dimensions in createRandomMap(). :blush: I should do some refactor my code at some point, and this is definitely one target that has some work to do.
  • The currentSpot = [...myField.starting_pos] piece of code creates a ‘deep copy’ of the array. I don’t know if you’re familiar with the term, but basically it just creates an array with the same values the original array has. If I made this with syntax currentSpot = myField.starting_pos, that is without the […] thing, the values in currentSpot would’ve been only references to the original array. If something would change in currentSpot, it would also be changed in myField.starting_posand vice versa.
  • The optimal route algorithm is just a breath-first-algorithm, and it truly does find the shortest path to target. It works only if each step is weighed the same, like in this game: every step counts as 1. The wikipedia article is actually quite good explaining it: Breadth-first search - Wikipedia. You can google more using 'bfs-algorithm ’ as search word.
1 Like

i was wondering if this super interesting project could be made into a browser game and how. any suggestions?

So long as you have Node.js installed locally you should be able to run the code on your machine.