A.I. Learns to Play World's Hardest Game (QWOP)

The AI Guy · Beginner ·🤖 AI Agents & Automation ·6y ago

Key Takeaways

This video demonstrates how an AI agent uses a Genetic Algorithm to learn and play QWOP, a notoriously difficult online game, by evolving its skills over generations

Full Transcript

[Music] welcome to the video in today's video I'm gonna be showing you how I built an AI agent to learn play and end up winning the popular flash game QWOP my inspiration for this game was seeing google's deepmind and how it's AI agent learned to walk and run from point A to point B and I match this with my deep deep frustration with the game cloth that I've had over the years as I've tried to master it manually with out any luck whatsoever I am absolutely trash at the game so I decided to cheat my way by creating an AI agent to play the game for me we are going to create our AI agent using an evolutionary algorithm or in other terms a genetic algorithm and what this algorithm does is it pretty much it's based off of evolution itself and how humans evolved from monkeys and it uses the same concepts of evolution to help our runner advance and learn how to beat the game so let's go ahead and kick off our genetic algorithm and I'll go through as it runs and explain what is happening and the algorithm itself first off we are using selenium to automate our agent and to automate the key presses of the runner the q wo and P so for the purpose of this video we are going to refer to our runner as Alan don't ask me why I chose the name Alan just a random name that popped into my head the algorithm that Alan is using to learn as he goes through the game is as follows we start by creating an initial population which is made up of genes and chromosomes linked together our genes for Alan are all the different combinations of key presses that are possible within the game plot using Q wo and P and then one gene called SL which is just kind of a sleep or pause don't press any buttons we then add a random timestamp between one tenth of second and three seconds to go along with that key press and that makes up the gene and then we string ten random genes together in a row to form the chromosome Alan will then continuously loop over this chromosome going through the key presses and times for each key press until he either falls over or wins and that is one individual within a population and a population is ten of these random chromosome combinations in a row and we just keep looping through the population and as we loop through we compute the fitness for each individual within the population and our fitness for Alan is the distance he has walked or ran and made it in the game and we get this score off of the screen by constantly taking screenshots of the game screen itself and extracting the text at the top where it says how far Alan has traveled and using that to just as the score for the fitness so each run for Alan until he either follows over or wins the game is one individual within the population so that randomly generated DNA that makes up a chromosome on repeat until he falls over or wins and then once that happens to a size population size of ten so ten runs of Alan dying or winning is a population size of ten and then we do this pseudocode in the repeat section so selection occurs we take the top two fitness scores the top two runs that Alan did so the distance that Alan made it the farthest we take those DNA of key presses and time press for each key and then we perform crossover crossover chooses a point within the chromosome in which it will cross over and swap the DNA from both of the two top scores and then it now makes child or offspring of the population which has a mix of those top two scores and those will now be the new population ten new offspring that will then be runs for Alan to try and complete and see if he does better and if he does better they become those new top scores that will then populate and reproduce to keep creating the next generations and generations so each time we repeat this step it is a generation because the DNA swaps we also perform mutation within the algorithm which where is theirs I give it a ten percent chance of randomly altering the DNA when it does this reproduction and offspring step if we fast forward to generation ten we can see that Alan has become extremely stubborn stubborn stubborn and he has learned to actually just take a knee almost and barely barely a minute over this is part of to do with nice for itself because it's purely just how far Allen has ran or at this pot crawled almost it doesn't take into account the speed or how fast he is moving so allen has learned to just take a knee and practically inch forward so props to Allen for being a stubborn stubborn runner and now we're gonna have to adjust our fitness X our Fitness score Fitness function to now be the score divided by the time the time it takes so we're gonna have to go ahead and rerun our simulation using this new updated fitness board so I'll speed up the clip speed and let's watch Allen evolve over time we can see off the bat that Allen is extremely stupid and hasn't learned anything at all he's but he's slowly trying out different combinations of key presses that ended up him falling over but eventually he starts to move forward direction and not start to and not look like a total fool he starts to kneel and actually be able to start making forward progress and if we fast-forward to generation 8 we can see that Allen has learned enough to scoot rapidly forward on one knee and make it all the way to 39 meters before face-planting into the ground and on the very next run Allen makes a break for it and actually encounter something that I didn't even know was in the game because I've never made it close this far the mythical hurdle and fails at hurdle damn it Alan Alan has to get back to the drawing board so that he can surpass this hurdle the next time he faces it Alan continues to run through the individuals within populations and continues to evolve over time so he just keeps doing trial and error learning from his mistakes so that he can have a better score and better run on the following the following run and you'll see that he slowly becomes faster and slowly becomes more intelligent as an AI agent in general this is the genetic algorithm at play and constantly repeating that loop of selection of the fittest natural selection mutation and reproduction to continuously get better over time and we can see that Alan is indeed learning this time when Allen faces the hurdle he's learned and does not fall down right away he's actually able to tip it over and then continuously move forward while pushing it but you'll see that still Allen has not learned to overcome the mythical hurdle and will actually fall over fast forward to generation 14 of the genetic algorithm and this time around Allen has evolved enough to actually surpass and beat the hurdle finally Congrats Allen and he is actually now going to be able to actually get himself over the hurdle after toppling it over which is a pretty impressive feat and he's learned this through the algorithm evolving and he will be able to get over the hurdle and hopefully make a push for the finish line [Applause] so as Allen makes the home stretch down the final 20 meters I just want to say thanks everybody for watching this video I hope you enjoyed it if you enjoyed it please drop a like and subscribe to the channel to see more a I coverage and more AI videos in the future it would mean a lot to me not to mention it would mean a lot to Allen I know he's become very attached to you all as you've been tchard with him through his evolution journey also let me know down in the comments whether you want to see a second video where I cover all the code used in this video to control Allen and the algorithm behind it Allen is coming up to the finish line and completing QWOP we successfully created an AI agent that evolved to beat the game [Applause] [Music]

Original Description

Witness how an AI Agent Learns to Play the World's Most Frustrating and Addictive Game QWOP! Using a Genetic Algorithm to evolve and learn QWOP over time, the runner Allen gains knowledge and continuously gets better each and every generation. He begins off extremely awful at the game but by the end he has evolved enough skills to WIN! #artificialintelligence #QWOP #geneticalgorithm TRY QWOP YOURSELF: http://www.foddy.net/Athletics.html In this video I cover: 1. QWOP (the world's most frustration and addictive game) 2. Genetic Algorithm 3. Allen the runner's evolution to stardom 4. QWOP Victory! If you enjoyed the video, toss it a like! 👍 To Subscribe: https://www.youtube.com/channel/UCrydcKaojc44XnuXrfhlV8Q?sub_confirmation=1 Thanks so much for watching! - The AI Guy
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from The AI Guy · The AI Guy · 12 of 28

1 How to Setup a Machine Learning and AI Environment
How to Setup a Machine Learning and AI Environment
The AI Guy
2 Introduction to Machine Learning | | Learning ML with Scikit | Iris Dataset
Introduction to Machine Learning | | Learning ML with Scikit | Iris Dataset
The AI Guy
3 Introduction to Machine Learning | Learning ML with Scikit | Iris Dataset | Part 2
Introduction to Machine Learning | Learning ML with Scikit | Iris Dataset | Part 2
The AI Guy
4 How to Install OpenCV on Windows | OpenCV Python Tutorial | Setting up Computer Vision
How to Install OpenCV on Windows | OpenCV Python Tutorial | Setting up Computer Vision
The AI Guy
5 How to Build and Install OpenCV from Source | Using Visual Studio and CMake | Computer Vision
How to Build and Install OpenCV from Source | Using Visual Studio and CMake | Computer Vision
The AI Guy
6 YOLOv3 Object Detection with Darknet for Windows/Linux | Install and Run with GPU and OPENCV
YOLOv3 Object Detection with Darknet for Windows/Linux | Install and Run with GPU and OPENCV
The AI Guy
7 Creating a YOLOv3 Custom Dataset | Quick and Easy | 9,000,000+ Images
Creating a YOLOv3 Custom Dataset | Quick and Easy | 9,000,000+ Images
The AI Guy
8 Train YOLOv3 Custom Object Detector with Darknet | Aimbot and Security Camera | Fast and Easy
Train YOLOv3 Custom Object Detector with Darknet | Aimbot and Security Camera | Fast and Easy
The AI Guy
9 Create Labels and Annotations for Custom YOLOv3 Google Images Dataset | LabelImg Tutorial
Create Labels and Annotations for Custom YOLOv3 Google Images Dataset | LabelImg Tutorial
The AI Guy
10 How to Build an Object Detection Classifier with TensorFlow 2.0 on Windows/Linux
How to Build an Object Detection Classifier with TensorFlow 2.0 on Windows/Linux
The AI Guy
11 YOLOv3 in the CLOUD : Install and Train Custom Object Detector (FREE GPU)
YOLOv3 in the CLOUD : Install and Train Custom Object Detector (FREE GPU)
The AI Guy
A.I. Learns to Play World's Hardest Game (QWOP)
A.I. Learns to Play World's Hardest Game (QWOP)
The AI Guy
13 How to Build Object Detection APIs Using TensorFlow and Flask
How to Build Object Detection APIs Using TensorFlow and Flask
The AI Guy
14 Getting Started with Azure Machine Learning Studio
Getting Started with Azure Machine Learning Studio
The AI Guy
15 Real-time Yolov3 Object Detection for Webcam and Video (using Tensorflow)
Real-time Yolov3 Object Detection for Webcam and Video (using Tensorflow)
The AI Guy
16 How to Build an Object Tracker Using YOLOv3, Deep SORT and TensorFlow
How to Build an Object Tracker Using YOLOv3, Deep SORT and TensorFlow
The AI Guy
17 YOLOv4 in the CLOUD: Install and Run Object Detector (FREE GPU)
YOLOv4 in the CLOUD: Install and Run Object Detector (FREE GPU)
The AI Guy
18 YOLOv4 in the CLOUD: Build and Train Custom Object Detector (FREE GPU)
YOLOv4 in the CLOUD: Build and Train Custom Object Detector (FREE GPU)
The AI Guy
19 YOLOv4 Object Detection with TensorFlow, TensorFlow Lite and TensorRT Models (images, video, webcam)
YOLOv4 Object Detection with TensorFlow, TensorFlow Lite and TensorRT Models (images, video, webcam)
The AI Guy
20 How to Build a Custom YOLOv4 Object Detector using TensorFlow (License Plate Detector)
How to Build a Custom YOLOv4 Object Detector using TensorFlow (License Plate Detector)
The AI Guy
21 Counting Objects Using YOLOv4 Object Detection | Custom YOLOv4 Functions with TensorFlow
Counting Objects Using YOLOv4 Object Detection | Custom YOLOv4 Functions with TensorFlow
The AI Guy
22 Object Tracking Using YOLOv4, Deep SORT, and TensorFlow
Object Tracking Using YOLOv4, Deep SORT, and TensorFlow
The AI Guy
23 Crop and Save YOLOv4 Object Detections | Custom YOLOv4 Functions with TensorFlow
Crop and Save YOLOv4 Object Detections | Custom YOLOv4 Functions with TensorFlow
The AI Guy
24 License Plate Recognition Using YOLOv4 Object Detection, OpenCV, and Tesseract OCR
License Plate Recognition Using YOLOv4 Object Detection, OpenCV, and Tesseract OCR
The AI Guy
25 YOLOv4 in the CLOUD: Build Object Tracking Using DeepSORT in Google Colab (FREE GPU)
YOLOv4 in the CLOUD: Build Object Tracking Using DeepSORT in Google Colab (FREE GPU)
The AI Guy
26 How to Use Webcam In Google Colab for Images and Video (FACE DETECTION)
How to Use Webcam In Google Colab for Images and Video (FACE DETECTION)
The AI Guy
27 Real-time YOLOv4 Object Detection on Webcam in Google Colab | Images and Video
Real-time YOLOv4 Object Detection on Webcam in Google Colab | Images and Video
The AI Guy
28 Getting Started with Agent Development Kit Tools (MCP, Google Search, LangChain, etc.)
Getting Started with Agent Development Kit Tools (MCP, Google Search, LangChain, etc.)
The AI Guy

Related Reads

📰
How AI Employees Are Changing Companies
Learn how AI employees are revolutionizing companies by automating tasks like drafting, searching, and summarizing, and why this matters for the future of work
Medium · Machine Learning
📰
Kaiban Distributed, Evaluation
Learn about Kaiban Distributed, an actor-model multi-agent runtime, and its capabilities and roadmap
Medium · AI
📰
I built an AI agent that runs a local business's weekly marketing (Next.js + Gemini)
Learn how to build an AI marketing agent for local businesses using Next.js and Gemini, automating weekly marketing tasks
Dev.to AI
📰
Evaluation-Driven Development: Why QA Is About to Own the AI Stack
QA teams will play a crucial role in AI development as evaluation-driven development becomes key to differentiating AI models
Medium · AI
Up next
Building the future of agentic infrastructure
Claude
Watch →