Giter Site home page Giter Site logo

statute8234 / puzzle-ai-evolution-in-action Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 9 KB

Rating: (7/10) The Python program creates a puzzle game using the Pygame library, controlling enemies by collecting colored foods. It initializes the environment, creates classes, and implements the NEAT algorithm for neural network control.

Python 100.00%
math matplotlib neat os pygame pymunk random sprite sys

puzzle-ai-evolution-in-action's Introduction

Puzzle-AI-Evolution-in-Action

The code is a Python program using the Pygame library to create a puzzle game where enemies collect colored foods to gain points. It uses the NEAT algorithm to control the game's behavior. The code initializes the Pygame environment, sets up the game window, and defines classes for text, food, and enemy objects. It also implements the algorithm.

Table of Contents

About

This Python program uses the Pygame library to create a puzzle game where enemies collect colored foods, earning points based on their color. The game is controlled by a neural network trained using the NEAT algorithm. The code initializes the Pygame environment, sets up the game window, and defines colors and text rendering. It creates classes for text, food, and enemy objects, defines logic functions for adding food, handling collisions, and updating the game state. It also implements the NEAT algorithm for evolving neural networks and defines functions for evaluating genomes and running the NEAT algorithm.

Features

The Python program for a puzzle game includes initializing the environment, setting up the main display window, defining color and text rendering, class definitions, game logic functions, adding food, handling collisions, updating game state, and implementing the NeuroEvolution of Augmenting Topologies (NEAT) algorithm. The game uses the NEAT algorithm to evolve neural networks controlling enemies, and the game's performance is assessed through genome evaluation. The NEAT execution runs the algorithm to train and improve the neural networks based on their performance. This structure provides a solid foundation for the game, where the challenge comes from the evolving intelligence of enemy characters. The use of NEAT allows for dynamic learning and adaptation, potentially increasing the game's difficulty as the neural networks become more efficient at collecting food. This creative way to combine game development with machine learning is a creative way to combine game development with machine learning.

Imports

pygame, pygame.sprite, random, sys, pymunk, neat, os, math, matplotlib.pyplot

Rating

The code uses a simple neural network-based algorithm using the NEAT library to train and evolve agents to navigate a maze-like environment and collect food. It is easy to read and understand, with clear variable and function names. The code is moderately modular, with components like the Food and Enemies classes encapsulating their respective functionalities. Important sections of the code are commented for better understanding. However, the code has some cons, such as the extensive use of global variables, which could lead to issues with variable scope, readability, and maintainability. Refactoring to reduce reliance on global variables is recommended. The code could benefit from further organization and structuring, particularly by separating the main loop logic from the NEAT algorithm evaluation. Define constants for magic numbers, such as screen dimensions, food generation intervals, and enemy speeds, at the beginning of the code or in a separate configuration file for easier modification. To improve the code, refactor the code to minimize global variables, separate the NEAT algorithm evaluation logic from the main loop logic, define constants for magic numbers, and implement robust error handling mechanisms, such as try-except blocks, to handle potential errors during file I/O operations, library calls, or unexpected conditions.

puzzle-ai-evolution-in-action's People

Watchers

 avatar  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.