Sign in to follow this  
Followers 0
Xenthalon

A couple of questions to improve script speed

4 posts in this topic

So I have been using AutoIt since a few years now, but never started any bigger projects than some small automations.

Recently I stumbled upon a nice Tetris variant and decided to write a AutoIt script for it that basically plays the game for me. After a couple of hours of work I got a good base, reading out the current field with Pixeldetection, detecting the next stone thats gonna come up, some game menu navigation and all that. Even a very basic AI which was able to play the game, but honestly was at the intellectual level of an infant.

This AI went rather smooth, it only set the stones a little slower when it was in the higher rows of tetris, but it wasn't that bad.

So I searched the internet for a better AI and found excellent C++ code and rewrote it to work in AutoIt. It works and gives no errors, but that is basically it.

What that AI does is the following:

It takes a copy of the current known field and the stone it has to set at this very moment. Then it sets the stone at all possible positions in all angles, and rates the resulting field and eventually sets the real stone in the real field at the best position.

However this takes a huge amount of time, by the time the AI is done calculating the best spot the stone is already 3/4 down the field. This is not as intended and now I am searching for ways to improve that.

Now to my questions:

1. Is it possible to use something similiar to pointers in AutoIt? At the moment I just copy the field in a second array again and again which surely takes some performance.

2. Can my user defined functions return more than one parameter? My current way is rather sloppy and it involves using StringSplit after calling the function which I am not very fond of.

3. This may sound really noobish now, but I am running in troubles with arrays now and then which I can't really understand. Now is $array[column][row] or [row][column]? Or in the mathematical context, is it x y or y x? It all works nicely but I got moments of doubt...

I hope you can help me. Thanks in advance.

Share this post


Link to post
Share on other sites



Now to my questions:

1. Is it possible to use something similiar to pointers in AutoIt? At the moment I just copy the field in a second array again and again which surely takes some performance.

2. Can my user defined functions return more than one parameter? My current way is rather sloppy and it involves using StringSplit after calling the function which I am not very fond of.

3. This may sound really noobish now, but I am running in troubles with arrays now and then which I can't really understand. Now is $array[column][row] or [row][column]? Or in the mathematical context, is it x y or y x? It all works nicely but I got moments of doubt...

I hope you can help me. Thanks in advance.

1) for pointers is DllSctruct... functions but for your copu of array it's not usable

2) in your UDF use params with ByRef

3) $array[column][row] or [row][column] it x y or y x? - depends on how you fill/use values into/from your array - both may be correct but I think in most cases is first one implicit.

Share this post


Link to post
Share on other sites

Arrays are not arranged in an x, y, z, etc pattern. They are rank 0, rank 1, rank 2, etc.

If I could see the C++ code you have, I may be able to help.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Also, those codes were probably written in a C-type language for the reason that C has a knack for making programs written in it run fast.

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0