I really love game challenges and everytime I get a new game I think about how can I solve it via code or represent the game idea.
The Gridlock Game
The game is from Lorenzo, my 4 years old my son. I really love the simplicity of the game and I start thinking about representing the game in an algorithm.
começando a implementar o joguinho da cilada em #ruby pic.twitter.com/liMPSIByam
— Jônatas Paganini (@jonatasdp) July 12, 2016
Current implementation
My idea was code the board, but after code it, I tried to start building a solver for it. It was pretty hard for me. My current implementation was a “go horse” with no sense and no concerns. Just a implementation that:
- pick a random piece from a valid set
- navigates on the board from top to down, from right to left with the piece
- rotating the piece and trying to fit in each position of the board
- when fit get another piece
So, it was an old version and as you see it does not accomplish the mission.
The current solver problems
So, Ruby is one of my favorite languages and I put it down in a little time but when I start coding the solver, I really understand how much functional paradigms is missing in my mind. And how my horse approach is broken.
It really does not work yet. It never finishes a board with success. Some little changes should be considered to start being more flexible:
- block to put pieces that enclosure a stone
- improve rotation and stone validation
- skip stones with pieces
The challenge
The challenge is to solve the board. Feel free to fork it and implement your own strategy!
I extended the challenge to Floripa On Rails meetup and we’ll join tomorrow to implement it together \o/
Feel free to join us and help us to implement a better solver ;)
First post in English
So, it was my first post in English \o/
I recently joined to the Toptal LLC core team.
Now I’m part of a global company! It’s time to be global and start blogging in English too :)