Author Topic: Calling all Dk-playing programmers!  (Read 16146 times)

0 Members and 1 Guest are viewing this topic.

Offline hooch66

  • Senior Member
  • *
  • Posts: 139
    • Personal Blog
    • Awards
Re: Calling all Dk-playing programmers!
« Reply #15 on: April 15, 2013, 01:20:01 pm »
That is interesting Jeffw.

Do you have any links to examples of controlling a game in an editor with lua? I did find the lua manual:
http://www.lua.org/manual/5.1/



To write a DK AI you will almost definitely want to use lua scripting with the emulator mame-rr (or any other emulator that has similar scripting capabilities). Bascially, mame-rr allows you to write a lua script to execute alongside a game. This script can be programmed to do things such as executing code every frame, reading any value from RAM, sending controller input to use for a particular frame, etc. This avoids having to do any image/screen shot interpretation, ]which would be a total mess to implement, and instead allows you to read all information directly from RAM.

The only downside of this approach is that you might have to write your entire AI in lua. However, there are probably ways around this in which you could write the AI in any language you want. For example, you could write a program in any language and then make the lua script connect to this program and every frame it could send the entire contents of RAM to your program. The program would then use the AI logic to determine which inputs should be used on that frame and would send back the inputs, which the lua script would then use as input for that particular frame. Of course this requires a whole bunch of additional work over just writing the AI in lua.
Member for 11 Years Blogger

Offline Xermon54

  • Spring Jumper
  • *
  • Posts: 518
    • Awards
Re: Calling all Dk-playing programmers!
« Reply #16 on: April 15, 2013, 01:35:40 pm »
Quote
To write a DK AI you will almost definitely want to use lua scripting with the emulator mame-rr (or any other emulator that has similar scripting capabilities). Bascially, mame-rr allows you to write a lua script to execute alongside a game. This script can be programmed to do things such as executing code every frame, reading any value from RAM, sending controller input to use for a particular frame, etc. This avoids having to do any image/screen shot interpretation, ]which would be a total mess to implement, and instead allows you to read all information directly from RAM.

The only downside of this approach is that you might have to write your entire AI in lua. However, there are probably ways around this in which you could write the AI in any language you want. For example, you could write a program in any language and then make the lua script connect to this program and every frame it could send the entire contents of RAM to your program. The program would then use the AI logic to determine which inputs should be used on that frame and would send back the inputs, which the lua script would then use as input for that particular frame. Of course this requires a whole bunch of additional work over just writing the AI in lua.

I totally agree Jeff, I would've said the same thing!... lol.
1) World Record of the most insults received by a plastic surgeon - 3752

2:World Record of the most Check Man games played - 6 (tied with Hank Chien)
Member for 11 Years Blogger DK 1.1M Point Scorer DK 1M Point Scorer DK Killscreener Former DK Level 1-1 World Record Holder Twitch Streamer

Jeffw

  • Guest
Re: Calling all Dk-playing programmers!
« Reply #17 on: April 15, 2013, 03:02:33 pm »
That is interesting Jeffw.

Do you have any links to examples of controlling a game in an editor with lua? I did find the lua manual:
http://www.lua.org/manual/5.1/

I've attached an example lua script I wrote a while back that tests for bias in the random number generator (RAM value 0x6018). Specifically, it tests if even random numbers are as likely as odd random numbers, and also if the previous random number being even vs odd affects the probability that the next one is even vs odd. I never found any bias with this script. When running the script a test is started by pressing 1 and stopped by pressing 2, at which point it will display the statistics it computed. Keep in mind I know hardly anything about lua programming and was mainly concerned with writing something that worked rather than making sure I was following good practices.

For the case of a DK AI instead of recording statistics on the value of the RNG each frame like this script does you will want to set the input using the joypad.set() function. A complete list of functions provided by mame-rr can be found here: http://code.google.com/p/mame-rr/wiki/LuaScriptingFunctions

In order to make the AI move in response to what is happening on the board, you will need to read values from RAM. Here are some useful RAM values that could help get you started. All values are in hexadecimal.

0x6203 - Mario's X position
0x6205 - Mario's Y position

0x6700 is the start of the barrel array. Each barrel has a 0x20 byte range in which information for that barrel is stored. So for example barrel 1 info is in 6700 to 671F, barrel 2 info is in 6720 to 673F, etc. Here are some offsets from a barrel's range starting point that contain some useful info:
offset 00 - barrel status indicator (value 00 means inactive, 01 means active, 02 means it's being deployed)
offset 01 - wild barrel indicator (value 00 for normal and 01 for wild barrel)
offset 03 - barrel x position
offset 05 - barrel y position

0x6400 is that start of the fire array. Like the barrel array each fireball/firefox has a 0x20 byte range. Here are some useful offsets:
offset 00 - fire status (value 00 means inactive, 01 means active)
offset 03 - fire x position
offset 05 - fire y position

If you guys want, I can see if I can release a full RAM map with the meaning of a whole bunch of other RAM values. You can always try to find out what other RAM values, such as other offsets in the fire/barrel array, do by observing their values using RAM watch as you play.

Offline ebinsugewa

  • Elite Member
  • *
  • Posts: 253
    • Awards
Re: Calling all Dk-playing programmers!
« Reply #18 on: April 15, 2013, 03:44:55 pm »
Interesting idea.  I'll have a very quick shot tonight at writing something.   As far as I know all you would need is a program that is capable of sending keystrokes which is easy, capturing the screen is easy enough too but as for writing the code that interprets what is on the screen and then having jumpman act accordingly would be a hell of a job.

There are several programming competitions run, one is a competition where programmers pit their programming efforts against each other in Texas Hold'em.   That is a massive thing to try and do and I'd be guessing that teaching a computer to play DK would be an even harder thing to do.

To do it successfully you'd need to be a very capable DK player (which I am not), so you'd need someone like Hank, Vincent or Dean (or any number of you guys on here) to play a game and then put into pseudo code (plain English) exactly what the thought process is as you play a level - given that the best players are analyzing lots of stuff at the same time and changing their decisions on the fly it would be a very difficult thing to do.

Capturing the screen is entirely unnecessary as the screen output is only there so humans know what they're supposed to do. You can ignore this and instead read everything from memory. Playing hold 'em well is exponentially harder than an undertaking like this, since it has to react to another player as well as act on imperfect information while also determining the proper adherence or divergence from game theoretic optimal play.

The last paragraph shows a fundamental misunderstanding of the initial problem - you don't need to copy a good player's inputs nor to actually attempt to copy all the things that a top-level player simultaneously thinks about, to do so would be impossible. Instead the program should focus on maximizing something like points, or even easier - bonus score. The best application of this type of program would be in a speedrun format where it just plays as fast as possible to get to a killscreen.
we're in the yellow pages under 'spatulas'
Member for 11 Years Twitch Streamer Blogger IGBY 2014 DKF Team Member

Offline ebinsugewa

  • Elite Member
  • *
  • Posts: 253
    • Awards
Re: Calling all Dk-playing programmers!
« Reply #19 on: April 15, 2013, 03:47:39 pm »
Do you have any links to examples of controlling a game in an editor with lua? I did find the lua manual:
http://www.lua.org/manual/5.1/

http://forums.shoryuken.com/discussion/133401/trust is an example of controlling some aspects of Super Street Fighter II Turbo.
we're in the yellow pages under 'spatulas'
Member for 11 Years Twitch Streamer Blogger IGBY 2014 DKF Team Member

Offline John73

  • Senior Member
  • *
  • Posts: 128
    • Awards
Re: Calling all Dk-playing programmers!
« Reply #20 on: April 15, 2013, 04:31:16 pm »

The last paragraph shows a fundamental misunderstanding of the initial problem - you don't need to copy a good player's inputs nor to actually attempt to copy all the things that a top-level player simultaneously thinks about, to do so would be impossible. Instead the program should focus on maximizing something like points, or even easier - bonus score. The best application of this type of program would be in a speedrun format where it just plays as fast as possible to get to a killscreen.

We'll have to agree to disagree.  I know some of my fundamental  problems when playing DK which is why my best score is only mid 200's and no matter how hard a practice, I can not get my brain to think several steps ahead (i.e. Barrel screens).  I still see stuff done when watching events like the Wildcard event that I new even knew existed in the game which is why I think you would need a high level of expertise/input to make this work.

I do agree that a speed run would be the best approach, but given that you could even get the speed run to work, then it would be a matter of building up the rule base to increase score, point press.   

Anyway, I'll have a bit more of a look around at some of the links guys have posted.   Not saying I can or could do this, but I find the idea interesting.

Also agree over the screen capture, but then it really just comes down to you want to solve the problem.  I guess you would have two very different types of programs, one which uses data (which is not how a human player plays - well they convert the visual image into data for their brain I guess) and the other would be using capturing visual information and interpreting what to do, which is what a human does when playing.
DK Mame 266K Level 8-6
CK Mame 559K Killscreen
Member for 11 Years CK Killscreener Twitch Streamer

Offline hooch66

  • Senior Member
  • *
  • Posts: 139
    • Personal Blog
    • Awards
Re: Calling all Dk-playing programmers!
« Reply #21 on: April 16, 2013, 05:21:42 am »
Thanks for this. I'm excited to dig in and see what I can tinker with.

Paul

That is interesting Jeffw.

Do you have any links to examples of controlling a game in an editor with lua? I did find the lua manual:
http://www.lua.org/manual/5.1/

I've attached an example lua script I wrote a while back that tests for bias in the random number generator (RAM value 0x6018). Specifically, it tests if even random numbers are as likely as odd random numbers, and also if the previous random number being even vs odd affects the probability that the next one is even vs odd. I never found any bias with this script. When running the script a test is started by pressing 1 and stopped by pressing 2, at which point it will display the statistics it computed. Keep in mind I know hardly anything about lua programming and was mainly concerned with writing something that worked rather than making sure I was following good practices.

For the case of a DK AI instead of recording statistics on the value of the RNG each frame like this script does you will want to set the input using the joypad.set() function. A complete list of functions provided by mame-rr can be found here: http://code.google.com/p/mame-rr/wiki/LuaScriptingFunctions

In order to make the AI move in response to what is happening on the board, you will need to read values from RAM. Here are some useful RAM values that could help get you started. All values are in hexadecimal.

0x6203 - Mario's X position
0x6205 - Mario's Y position

0x6700 is the start of the barrel array. Each barrel has a 0x20 byte range in which information for that barrel is stored. So for example barrel 1 info is in 6700 to 671F, barrel 2 info is in 6720 to 673F, etc. Here are some offsets from a barrel's range starting point that contain some useful info:
offset 00 - barrel status indicator (value 00 means inactive, 01 means active, 02 means it's being deployed)
offset 01 - wild barrel indicator (value 00 for normal and 01 for wild barrel)
offset 03 - barrel x position
offset 05 - barrel y position

0x6400 is that start of the fire array. Like the barrel array each fireball/firefox has a 0x20 byte range. Here are some useful offsets:
offset 00 - fire status (value 00 means inactive, 01 means active)
offset 03 - fire x position
offset 05 - fire y position

If you guys want, I can see if I can release a full RAM map with the meaning of a whole bunch of other RAM values. You can always try to find out what other RAM values, such as other offsets in the fire/barrel array, do by observing their values using RAM watch as you play.
Member for 11 Years Blogger

Offline marinomitch13

  • Spring Jumper
  • *
  • Posts: 1806
    • How to Play DK
    • Awards
Re: Calling all Dk-playing programmers!
« Reply #22 on: April 16, 2013, 06:11:27 am »
I agree! I can't promise it will be fast work, but I'll try to get caught up on Lua when I have free time as well. It'll be cool to see what we can put together. Make sure to provide good notes for anything you guys code in case we need to share stuff with one another or ask for help on certain things.
"Thou hast made us for Thyself, and our heart is restless until it finds its rest in Thee." -Augustine, Confessions.
Member for 11 Years IGBY 2015 DKF Team Member DK Killscreener Blogger Twitch Streamer

Offline hooch66

  • Senior Member
  • *
  • Posts: 139
    • Personal Blog
    • Awards
Re: Calling all Dk-playing programmers!
« Reply #23 on: April 23, 2013, 07:18:38 am »
Kicking the tires on this thread, bumping it up.

Anybody make any progress on this yet? I have had a head cold for the past few weeks, effectively laying dormant the analytic part of my brain.
Member for 11 Years Blogger