We all know the classic game "Snake".
You are given a 10x10 field of cells. You control a snake and your task is to eat 5 cherries which are randomly placed on the field. The snake starts the game 5 units long and grows by one unit for each cherry it eats. In order to survive long enough to eat the cherries, the snake must not hit a tree, the edge of the field, or its own body. Doing so would trigger a game over. The snake does not sit still and is constantly moving. It can go in one of 3 directions: Forward “F”, Left “L” and Right “R”. Left and right are defined by the current position and trajectory of the snakes head. The map of field is presented as list of strings, where:
"." - Empty cell "T" - Tree "C" - Cherry "0" - Snake head "1..9" - Numbered Segments of the Snake Body
This is a multi-call task and your function will be called repeatedly until the game is complete. During each function call, you can return a character or a string that contains a sequence of actions (example: “FRFLF.”) Once the snake eats a cherry the remaining actions are dropped, a new cherry appears and the game continues. Once 5 cherries are eaten the game is over and you win. This version of snake has an interesting twist: you must eat the 5 cherries in 250 steps or less or face a game over.
At first the snake will move its tail then it will move its head. You can try to have your snake chase its tail this way. Be careful if you use breadth first search -- it can take a long time if you select a bad state representation.
Input: The map of field as a list of strings.
Output: One or more actions as a string.
checkio([ ".T.....T..", ".C........", ".....T....", "..T....T..", "..........", ".0...T....", ".1........", ".2.T...T..", ".3...T....", ".4........" ])
How it is used: With this game you prove that you can write a simple artificial intelligence. Here you should figure out pathfinding and planning. These are useful skills for many spheres of the real life. ;-)
|field| == 10 x 10
New cherries can't appear in the outer cells (ex. [0,0], [9, 9]), but the start cherry can be in outer cells.