$USD
  • EUR€
  • £GBP
  • $USD
PROJECTS AI

NewYear-Snake, Artificial Intelligence and Arduino.

DFRobot Jan 06 2013 471

Author: LukeSkypewalker

 "Thinking is a Computing"
Aristotle, Hobbs, Boole, Turing..

Dear DFRobot !
According to announcement: "DFRobot will publish and send the winning project as postcards to DFRobot’s customers all over the world" and considering that the Chinese New Year will be the year of Snake, I think this very intelligent snake will look great on the postcard, won't it?
 

Snake was my first computer game. And I have always been exited about Artificial Intelligence, so Snake-AI has become my first serious programming project. Originally it was written on Pascal and implemented only one algorithm - finding the shortest path by back-way wave tracing. It worked, but used to fail in very simple situations. I liked this Snake, and sometimes I came back and add new features and heuristics. Snake was rewritten on C and C++.

7 days ago this "logic" part of Snake had 4000+ strings of code. It had about 10 different heuristics and 2 types of game trees for brute force. Its best result of tail length was 39 on a 64-cell field. I was satisfied - it was nearly what I wanted. I didn't try to solve all the situations, I just wanted to avoid stupid traps, rise the high scores up to 40 and improve the readability of code ported to Arduino before submitting it to this contest.

In Russia  we have a tradition: the way you will meet New Year is the way how you'll spend it. So, after a New Year party I went programming, and then I finished another new trap-avoiding heuristic - it was the first time when the snake occupied all the field! It was awesome =D
But, even more important, it also showed me the way how I should do it! I started refactoring and removing excess code piece after piece... I threw away all my game trees, all my complicated heuristics.. Now the whole program is only 500 lines and it rocks!

 Snake on YouTube

  

I have ported the code to Arduino and Processing. All the code is open source - You can use it.
But if You are really interested with this brain-teaser - won't spoil the fun - try to reinvent your own wheel =)
I would like to discuss the ways of solving the problem or even challenge your snake AI on one field.
You can write me work37  (@)  gmail.com

Thanks for Your attention!
REVIEW