Coding Challenge #3 – An AI to solve a maze (ruby only)

Words
404
Reading
2 min
Listen
Play
9y

Welcome to the third Coding Challenge.

Here I will post a coding challenge every few days that you can solve. There will be easy ones and hard ones, pretty mixed.

How does it work?

  • Try to solve the challenge in ruby, you learn a bit if you have not heard of the language
  • Post a comment with a link to your code (use https://repl.it) and some info on how the code works or what is remarkable
  • Optional: Create a post with the tag #coding-solution
    • In that post walk other users through the process of solving your challenge. That way they can learn and try it out on the next one
  • Optional: Read and review other peoples code, try to find bugs, give feedback and learn

Why even bother?

  • Training is everything, the more you train your mind to think in code, the better you are prepared
  • You may learn a few new tricks from reading other solutions
  • I will send tips for really good solutions (and use the liquid rewards of this post for it too)
  • You may get recruited if someone likes your code (f.e. I am looking for talents)

Challenge #3 – An AI to solve a maze

This challenge will be a bit more complicated and hands on. See the starting code here: https://repl.it/KWPT/1

Implement an AI class that solves a maze:

  • the repl.it link gives you a starting point and implements the game.
    • Only use what repl.it can execute
    • All code that you need is documented to ensure nothing is unclear, please ping me if you have any more question.
  • You fill in the step method and everything else you need to get out of the maze.
    • Each step you get the current maze and possible directions and you return the direction you want to walk in.
    • You will probably have to remember where you are. A visual representation of the board is given, but that is not easy to parse to encourage you to remember the board yourself.
??????+--+--+--+
??????|   AI   |
??????+--+--+  +
?????????      |
?????????+--+--+
  • The game code should not be edited (everything under DO NOT EDIT DOWN HERE!)

Remarks:

  • As a sample implementation you can try out, a random walker is already implemented.
  • Try solving a maze with the smallest amount of steps possible.
  • Try exploring the whole map before you leave the maze.
  • Bonus points for:
    • good coding practices and modularity
    • beautiful (readable, self-documenting) code

Please keep the #coding-challenge tag clean of solutions.

Coding Challenge #3 – An AI to solve a maze (ruby only) | Ecency