Git Product home page Git Product logo

ai_learning_snake_game_linearqnet's Introduction

Snake AI with Linear QNet

Welcome to the Snake AI project! This project focuses on implementing an artificial intelligence system that gradually learns to play the classic Snake Game using a Linear QNet.

Overview

The Snake AI utilizes Reinforcement Learning techniques, specifically the Q-learning algorithm, to train an artificial agent to play the Snake Game. The QNet is implemented in a linear fashion to simplify the learning process.

Installation

To run the Snake AI project, follow these steps:

  1. Clone the repository:

    git clone https://github.com/anshumalivfx/AI_Learning_Snake_Game_LinearQNet.git
  2. Install the required dependencies:

    pip install -r requirements.txt
  3. Run the Snake AI program:

    python agent.py

Components

1. Linear QNet

The core of the learning mechanism lies in the Linear QNet. It is a simplified neural network that represents the Q-function, which maps state-action pairs to their respective Q-values. The mathematical representation is as follows:

$$ Q(s, a) = W \cdot X $$

where:

  • ( Q(s, a) ) is the Q-value for a given state-action pair.
  • ( W ) is the weight vector.
  • ( X ) is the feature vector representing the state-action pair.

2. Q-Learning Algorithm

The Q-learning algorithm is used to update the Q-values based on the rewards received by the agent. The update equation is given by:

$$ Q(s, a) = Q(s, a) + \alpha \cdot [R + \gamma \cdot \max(Q(s', a')) - Q(s, a)] $$

where:

  • ฮฑ is the learning rate.
  • ฮณ is the discount factor.
  • ( R ) is the immediate reward.
  • ( s ) and ( s' ) are the current and next states, respectively.
  • ( a ) and ( a' ) are the current and next actions, respectively.

Training

The Snake AI is trained by allowing the agent to play the Snake Game multiple times, and the Q-values are updated using the Q-learning algorithm. Over time, the agent learns a policy that maximizes its cumulative rewards.

Usage

Feel free to tweak the hyperparameters in the config.py file to experiment with different settings and improve the learning performance.

# Example hyperparameters in config.py
learning_rate = 0.001
gamma = 0
epsilon = 0

Contributions

Contributions are welcome! If you have any ideas for improvements or bug fixes, please open an issue or submit a pull request.

Happy coding! ๐Ÿ๐Ÿค–

ai_learning_snake_game_linearqnet's People

Contributors

anshumalivfx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.