How to Use SlitherinAI: Research Environment for the Game of Snake

Category :

Welcome to the world of SlitherinAI, a playful yet powerful research environment for exploring the classic game of Snake through AI written in Python 2.7. This blog will guide you through setting up and utilizing SlitherinAI effectively, enriching your programming experience while honing your skills in algorithms and artificial intelligence.

Table of Contents

Usage

  1. Clone the repo.
  2. Go to the project’s root folder.
  3. Install required packages using the command:
    pip install -r requirements.txt
  4. Launch SlitherinAI. We recommend starting with the help mode to see all available modes:
    python slitherin.py --help

Rules

  • Snake must move either forward, left, or right.
  • Snake dies upon hitting a wall or itself.
  • For every eaten fruit, the snake’s length increases by 1, and a new fruit is generated at a random unoccupied location.

Modes

SlitherinAI incorporates various algorithms under two main categories: Domain specific and General purpose. Each algorithm runs on a benchmark of a 12×12 grid, and current scores are displayed with each mode. Let’s explore these modes:

Domain Specific

Domain-specific algorithms utilize data such as the snake’s position, direction, and neighbors:

Shortest Path BFS

python slitherin.py --shortest_path_bfs

This algorithm generates the shortest path from the snake’s head to the fruit using the BFS method. It performs optimally in the early game; however, as the snake grows, it becomes increasingly obtrusive.

Shortest Path DFS

python slitherin.py --shortest_path_dfs

This one employs the DFS algorithm, which may perform worse than BFS due to the cyclic nature of the graph.

Longest Path

python slitherin.py --longest_path

By first generating a shortest path, this algorithm then attempts to extend the distance by exploring available actions, albeit at the risk of the snake dying if it occupies its own path.

Hamilton

python slitherin.py --hamilton

This mode constructs a Hamiltonian path that typically covers the entire environment, aiming for a perfect score.

DNN (Deep Neural Network)

python slitherin.py --deep_neural_net

This employs a deep neural network that learns from gameplay to make decisions based on surrounding factors. However, performance may deteriorate as the snake grows due to limited awareness of its environment.

DNN Monte Carlo

python slitherin.py --deep_neural_net_monte_carlo

By generating gameplay for each action and selecting the highest score, this approach is inefficient at the start but effective in later game stages.

General Purpose

Unlike domain-specific algorithms, these do not utilize specific game data:

Human

python slitherin.py --human

This mode allows for debugging, development, and fun.

Random

python slitherin.py --random

It serves as a benchmark against randomness, although it has low performance.

Monte Carlo

python slitherin.py --monte_carlo

This mode conducts a series of simulations to choose the best initial action.

DNN Genetic Evolution

python slitherin.py --deep_neural_net_genetic_evolution

The initial population uses random weights, and through genetic algorithms, it repeatedly optimizes the performance, achieving satisfactory results.

Work in Progress

A multiplayer (multi-agent) version of SlitherinAI is currently being developed. Keep an eye out for updates!

Troubleshooting

If you encounter any issues while setting up or running SlitherinAI, consider the following:

  • Ensure that your Python version is 2.7, as this is a requirement for the project.
  • Double-check your installation of the required packages; you may try reinstalling them.
  • If you have trouble launching the application, recheck the command syntax or consult the help option for guidance using
    python slitherin.py --help

    .

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox

Latest Insights

© 2024 All Rights Reserved

×