473,505 Members | 13,805 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 getmouselocation

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, 1771 views)
May 19 '13 #1
0 4548

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

Similar topics

5
2281
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...
4
3879
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...
0
1804
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...
0
1787
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
2158
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,...
1
1631
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
2371
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
7213
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,...
0
7098
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...
0
7298
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,...
1
7017
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...
1
5026
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...
0
4698
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...
0
3187
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...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
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...

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.