Skip to content

xccds/flappy_bird_ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Python游戏AI一锅炖:flappy bird游戏AI实现

Cover

用Python来编写一个经典游戏flappy bird,并且编写一个遗传算法作为AI引擎来驱动小鸟通过钢管丛林。这个有趣的小项目适合刚学习完Python语法的新手进阶。通过这个项目,可以同时学到如何用Python来开发小游戏,开发人工智能引擎,一举多得。本项目是配合 B站的视频 来学习。

  • resources目录中存放了资源文件。
  • flappy_bird.py文件是供人类玩家交互的代码。
  • flappy_ga.py文件是和AI(遗传算法)交互的代码。

代码的结构类图显示如下:(只包含部分重要的属性和函数)

classDiagram

    GATrainer *-- Game : Composition
    Game *-- Pipe :Composition
    Game *-- Bird : Composition
    Bird *-- Linear_Net : Composition

    class GATrainer {
        Game
        cross_mutate()
        reproduce()
        run_GA()
    }

    class Game {
        Bird_group
        Pipe_group
        loadImages()
        reset()
        handle_collision()
        pipe_update()
        birds_update()
        draw()
        play_step()

    }
    
    class Pipe {
        image
        rect
        update()
    }
    
    class Bird {
        model
        images
        rect
        get_action()
        get_state()
        animation()
        check_collision()
        update()
    }

    class Linear_Net {
        forward()
        get_weight()
        set_weight()
    }

Loading

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages