473,657 Members | 2,436 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python based artificial intelligence for a flash game

kudos
127 Recognized Expert New Member
"dogfight 2" is a flash based biplane game at rock solid arcade.

http://www.rocksolidarcade.com/games/dogfight2/

Wouldn't it be cool to make a python program, an Artificial intelligence (AI), that could play the dogfight game for us?

Aware that making an efficient AI for playing such a game is a very difficult task, I settle for creating a simple framework that starts the game and looping the plane until it crashes into the ground.

First, some words about the environment. I have used a Ubuntu vmware image, with google chrome installed.

The first thing I do start the chrome browser with the address :

http://www.rocksolidarcade.com/games/dogfight2/

We want to make a program that clicks on the dogfight game with the left mouse button to gain focus, then wait for a second or so. To figure out what the coordinates for the dogfight game is, we use the xdotool from a terminal window (See image below)




You might have to install xdotool, as it might not come with your linux distribution by default, to do this, type:

sudo apt-get install xdotool

Once it is installed, move your mouse over the dogfight game. Don't click! In fact don't move the mouse at all!

Type the following on your keyboard in the terminal window which still should have focus.

xdotool getmouselocatio n

Dogfight tell us to start the game by pressing "fire". On your computer, "fire" would be "space", but you will not be pressing fire yourself, the python progam should do that for you.

Conceptually the program would be simple: First your program would click on the Dogfight game to gain focus, then it would press space to start the game, then it would wait for a second before it would press the up key to lead the plane into a loop. The last part would be an infinite loop

Below is an example python program that does just that

Expand|Select|Wrap|Line Numbers
  1. import subprocess
  2. import time
  3.  
  4. # get focus and click
  5. subprocess.call(["xdotool","mousemove","440","661"]) # use subprocess to call xdotool from python
  6. subprocess.call(["xdotool","click","1"])
  7. time.sleep(3)
  8.  
  9. # press fire (space) to start the program
  10. subprocess.call(["xdotool","keydown","space"])
  11. time.sleep(1)
  12. subprocess.call(["xdotool","keyup","space"]) 
  13.  
  14.  
  15. # key pushing the up key to make the plane roll
  16. while(True):
  17.  # each second press the up cursor key
  18.  subprocess.call(["xdotool","keydown","Up"])
  19.  time.sleep(1)
  20.  subprocess.call(["xdotool","keyup","Up"])
  21.  
  22. # runs until you press Ctrl-Z
  23.  
That's it! It doesn't do anything more than looping for maybe two times, before it crashes into the ground. It could be extended, for instance we could figure out the position of the plane, make it fire all the time, etc, etc.
Attached Images
File Type: jpg point1b.jpg (43.4 KB, 1778 views)
May 19 '13 #1
0 4563

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2302
by: Arthur T. Murray | last post by:
http://www.scn.org/~mentifex/jsaimind.html is a free, public-domain AI in JavaScript that may be copied to your Web site with your own changes. Freshly updated and modified from the AI Mind-1.1 appearing in http://isbn.nu/0595654371 -- AI4U textbook of artificial intelligence -- the new AI Mind forgets its oldest unused memories in order to make room for memories of fresh experience, and is therefore immortal. Interested parties may...
4
3890
by: Tolga | last post by:
Hi, Is there anybody here interested in artificial intelligence (AI)? Yes, perhaps this thread would be more suitable for an AI usenet group and I have also posted my question there, but I want to know Python community's opinion. Could you recommend me please a good AI book to start with? I don't want to see Lisp code, if possible ;-D Thanx in advance
0
1819
by: tommak | last post by:
It's a dream of human beings to build machines that can think and behave like human beings. The most important part of of such a machine is an artificial mind that can emulate the cognitive processing of human mind. This book, "Next Generation Artificial Intelligence, Artificial Mind - Part One - Basic Architecture and Cognitive Structure" introduces a basic artificial mind architecture and computational model for cognitive...
0
1801
by: indhu | last post by:
Hi all, I have doubt regarding this. How to Convert c++ game to Flash game. what r the advantages and disadvantages. can anyone help me in this. thanks in advance
2
2174
by: rajeshkumarvm | last post by:
I am the new born baby for flash scripting.I have to make one flash game.I explained the game details below. Actually, this is bulding a engine game.In scene 1 i have 8 layers, in the layer one, a outline of the engine is drawn and in other layers the parts of the engine are just kept which is seperated into 7 parts. so, the game is to arrange the parts with layer one. Suppose, if the object in the layer2 is dragged to the layer one to that...
1
1641
by: kadavakooti | last post by:
Hi!, I have just completed my MS in Artificial intelligence in UK with excellent grade. Can some one tell, which are the companies that would be interested in hiring in this field in UAE?
7
2386
by: sarika | last post by:
Is the artificial intelligence possible in PHP ?? If yes plz help me to learn this. or Please send me the websites for learning artificial intelligence in php
0
8395
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8310
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8826
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8605
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6166
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5632
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1615
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.