[DEV] ISFL Forums
*Decompiling the Sim: AutoHotkey - Printable Version

+- [DEV] ISFL Forums (http://dev.sim-football.com/forums)
+-- Forum: Community (http://dev.sim-football.com/forums/forumdisplay.php?fid=5)
+--- Forum: Media (http://dev.sim-football.com/forums/forumdisplay.php?fid=37)
+---- Forum: Graded Articles (http://dev.sim-football.com/forums/forumdisplay.php?fid=38)
+---- Thread: *Decompiling the Sim: AutoHotkey (/showthread.php?tid=24047)



*Decompiling the Sim: AutoHotkey - Yeenoghu - 07-22-2020

It's me again!

I'm not entirely sure this topic fits within the series as it’s not directly related to understanding the source code of Draft Day Sports: Pro Football 2016, but I’ve decided to include it because it can help us test various theories and build ideas (and because it’s the most interesting sim-related topic that I’ve been working on lately). The target audience for this post is users that already have a bit of experience in working with the sim--if you are brand new and just looking to start experimenting with the sim, there are probably better threads and guides out there for you to get started.

Before we start, I have to say that this post would not be possible without the help of my Royals teammates @abh89 and @Z-Whiz. They have been invaluable in providing critical feedback, helping me test this utility at different resolutions, and keeping me sane while fixing various bugs in the early stages of development. If you’re not familiar with our team, London went 2-6 through the first eight games of the DSFL schedule before going on a five-game winning streak to clinch a playoff spot. During that time, abh89, Z-Whiz, and fellow rookie @crow19 have become heavily involved in simulating a variety of different strategies (hundreds of repetitions per week? thousands?) for our team to give us the best chance of winning, so I’ve created a little script to make this process more efficient. As an aside, I really believe that we have implemented a great base in London for rookies to get involved and stay engaged, but enough doting on my team for now.

As a point of reference, let’s talk a little bit about the current unofficial process for simulating batches of games. After setting your depth chart or updating your strategy, what you are probably doing is using a program called ‘Auto Clicker’ / ‘AutoClickers.exe’ to click the Sim Game button, dismiss the results window, and repeat ad infinitum. Like this--

[Image: B9wgEfn.gif]

This is obviously far superior to manually running a large number of tests. You can just set the program to run for a few hundred trials, leave your PC, and come back to see the results of your test. That’s the classic appeal of an autoclicker, but there are a few limitations--
  • There is a single, global variable sleep timer between clicks. This means that your delay setting has to be set to the maximum value necessary, and it happens between every click.
  • The whole array of clicks must occur for every loop, meaning that the AutoClicker is only capable of completing the exact task and can’t do anything else.
  • Since the AutoClicker relies on mouse coordinates, a ‘one size fits all’ approach is not feasible due to different screen resolutions, multiple monitors, etc
To address some of these points and make the process even faster, I decided to learn AutoHotkey! If you haven’t heard of AutoHotkey, it’s a simple scripting language that uses mouse inputs, keyboard inputs, and other system variables to carry out any number of tasks--it’s basically designed for this kind of work. This is what I came up with--

[Image: dfdcc82f0dff0ad07f.gif]

So let’s talk about the additional functionality and what you’re seeing here.
  • The GIF starts on the configuration menu. This is to demonstrate that the ‘Enable Personalities’ box is unchecked.
  • When the user kicks off the script via a simple keystroke, a menu appears where the user is asked to enter the home and away teams as well as the desired number of games to simulate.
  • At this point, there’s no more user input required. Based on your inputs, the script takes care of running all of the trials. The number of sims is limited only by the game itself, but we’ve verified that it can handle up to 950 games without issue.
  • Once the simulations are complete, the script checks the ‘Enable Personalities’ box, saves the configuration settings, and then exports the .csv file for analysis.
How does this differ from the basic AutoClickers.exe functionality?
  • This script is entirely customizable if you know or want to learn how to write AutoHotkey scripts. This means that different delays can be set between different steps to optimize speed--in fact, the demonstration has actually been slowed down a bit for visual effect. If you really crank up the speed, you won’t even see the game window appear, but you won’t suffer any loss of data.
  • The user no longer has to remember to handle the pesky ‘Enable Personalities’ box. That’s all taken care of by the script. The user just needs to open the league file, set the strategy as desired, and kick off the script to get an export of several hundred files in just a couple of minutes.
  • The script does not use targeted mouse clicks! This has all been completed via keyboard shortcuts. Hopefully this will allow for a more global approach that does not require you to tinker with the settings before running the script.
If you want to try it out for yourself, you’ll need to download and install AutoHotkey and save a copy of the script (SimTestExport.ank.ahk). AutoHotkey itself has a pretty good tutorial for how to run scripts, but I can share more information about this step as needed. In essence, it’s as simple as launching the script file (you won’t really notice that anything has happened when you launch it, but it will appear in your taskbar) and kicking off the script by pressing Control + J. You’ll know it’s worked if the menu asking for inputs appears, and you can kill the process early by pressing Escape.

Disclaimer: For your first attempt, I’d only run it with 5 or so games in case anything weird happens. Part of the loop closes a game window by pressing Alt + F4, and I don’t want to be responsible for closing everything on your desktop if you somehow hit Alt + F4 a ton of times consecutively. As I said, we’ve tested this on runs of up to 1,000 without that occurring, but just try it out with small runs until you’re comfortable with how the script works. It's closer to a one size fits all approach, but I can't say we're 100% there yet. Maybe one size fits most.

Let me know what questions you have. ‘Til next time!

----------------------------

Also, I wanted to include my thoughts on the DSFL running back meta here. It’s currently buried in the Ultimus Week task--please check it out if you missed it!


*Decompiling the Sim: AutoHotkey - abh89 - 07-22-2020

Great work as always, Mag! You've been tremendously helpful this season. LON LON LON


*Decompiling the Sim: AutoHotkey - infinitempg - 07-22-2020

i feel like in every one of these articles i'm coming in saying "i've done this already" but uh, please don't take offense to that lol. this is all really good. that being said....

(07-22-2020, 09:02 PM)Maglubiyet Wrote:[*]At this point, there’s no more user input required. Based on your inputs, the script takes care of running all of the trials. The number of sims is limited only by the game itself, but we’ve verified that it can handle up to 950 games without issue.

i've never gotten AHK to do more than 400 without exploding on me. not sure what you guys are doing different.

(07-22-2020, 09:02 PM)Maglubiyet Wrote:[*]Once the simulations are complete, the script checks the ‘Enable Personalities’ box, saves the configuration settings, and then exports the .csv file for analysis.

...how many tabs did you use because i always tried to count and it kept changing smh


(07-22-2020, 09:02 PM)Maglubiyet Wrote:[*]This script is entirely customizable if you know or want to learn how to write AutoHotkey scripts. This means that different delays can be set between different steps to optimize speed--in fact, the demonstration has actually been slowed down a bit for visual effect. If you really crank up the speed, you won’t even see the game window appear, but you won’t suffer any loss of data.

i've found the opposite to be true. i've found autoclicker.exe to be much much faster - i only need a 50 ms sleep time between clicks for that while for AHK i've had to use over 200 ms for it to actually register. that might have to do with how we're doing the functions though - i use click and then enter so the mouse doesn't have to move. i will have to look at your script later.

(07-22-2020, 09:02 PM)Maglubiyet Wrote:[*]The script does not use targeted mouse clicks! This has all been completed via keyboard shortcuts. Hopefully this will allow for a more global approach that does not require you to tinker with the settings before running the script.

oh well there you go. weird that it's so much faster for you haha


anyways this is all super awesome work and i love that you're sharing this with the whole league. i was never comfortable with releasing my stuff (and i've got some super secret testing stuff) because it's still super buggy. i'm excited to see your AHK code!



*Decompiling the Sim: AutoHotkey - timeconsumer - 07-23-2020

I think the number of sims before crash depends on your available RAM.


*Decompiling the Sim: AutoHotkey - The_Kidd - 07-23-2020

possibly, I could run about 700-800 before the script acting up on me


*Decompiling the Sim: AutoHotkey - Yeenoghu - 07-23-2020

(07-22-2020, 09:08 PM)abh89 Wrote:Great work as always, Mag! You've been tremendously helpful this season.  LON  LON  LON
Thanks abh, we did it together!

We've already talked a good deal privately about the script by now, but for everyone's sake--
(07-22-2020, 09:37 PM)infinitempg Wrote:i've never gotten AHK to do more than 400 without exploding on me. not sure what you guys are doing different.



...how many tabs did you use because i always tried to count and it kept changing smh
I think it's set to 16 tabs but that Configuration menu is a little buggy when coming into focus, so I wouldn't be surprised if it's eating one or more tabs at random times. I tried to offset this via delay, and clicking in the active window, but you might have to tweak it if needed.
(07-22-2020, 09:37 PM)infinitempg Wrote:that might have to do with how we're doing the functions though - i use click and then enter so the mouse doesn't have to move. i will have to look at your script later.



oh well there you go. weird that it's so much faster for you haha
I didn't notice a difference in speed between using clicks and keyboard inputs, but the main reason I used keyboard inputs was because I wanted to distribute the script to the community at large. I started out with mouse clicks at first, but we ran into all kinds of all issues with resolution, multiple monitors, fullscreen vs. windowed mode, etc. when trying to establish mouse coordinates. Once abh figured out that Alt + F4 was an acceptable method to close the Game Details window, that was the final keystroke we needed to make it all keyboard-based. The only clicks in the script now are just to help with establishing the active window, so the position is largely irrelevant.
(07-22-2020, 09:37 PM)infinitempg Wrote:anyways this is all super awesome work and i love that you're sharing this with the whole league. i was never comfortable with releasing my stuff (and i've got some super secret testing stuff) because it's still super buggy. i'm excited to see your AHK code!
Thanks for the feedback infinite, it's always welcome. I'm sure plenty of people that try to take up using the script will find some strange bugs, but hopefully that will just serve to get them familiar with AutoHotkey and scripting in general! I'm excited to go down this route!

(07-23-2020, 12:26 AM)timeconsumer Wrote:I think the number of sims before crash depends on your available RAM.
(07-23-2020, 01:38 AM)The_Kidd Wrote:possibly, I could run about 700-800 before the script acting up on me
I definitely recommend starting with a relatively small number of runs and ramping your way up from there to test the limits. We couldn't ever get more than 1,000 to run, but who knows if it's performance-based.


*Decompiling the Sim: AutoHotkey - speculadora - 07-23-2020

wait I can set the auto clicker to 5ms sleep and it runs just fine for me. takes about 2 minutes to run 500 or so tests


*Decompiling the Sim: AutoHotkey - Z-Whiz - 07-23-2020

Quote:heavily involved in simulating a variety of different strategies (hundreds of repetitions per week? thousands?)

We are into tens of thousands by the end. Brain fully melted by the end. Great write up and it was a joy helping you tweak the script to perfection.