- Home /
Creating a bot to test my own game
HI everybody,
I always like to start by saying that I am an amateur and create games for fun and share them with my friends for fun and their feedback, so if my questions are very stupid, I apologize in advance. What I am wondering is how I would get a bot to synthesize button presses and screen touches. I don't know anything about bots, but it is essentially another kind of AI to use, and I would like to learn more about them. For my use, I would LOVE to be able to watch a bot try to play through my games as I watch and use it as a method of testing my games. I'm mostly curious how the bot can discover, and differentiate, one button from another.
I really appreciate any sample code or suggested tutorials that you might think would be helpful. Thank you so much!
Answer by jmgek · Dec 30, 2014 at 08:22 AM
What you are asking about is basic AI in a game system. It's relatively easy. You are looking at programming a million miles away, and need to understand the structure a little better about programming. First you need to think low level, you are thinking about something that could be handled by a simple "Button Presser" and this can be handled in 3 lines of code.
private bool button; //Create a true or false bool
if(!button) //if button is false
{
button = !button; //Switch button to opposite.
}
This is the lowest level of AI you can have, if a statement is either true or false and changes to the opposite of what it is, now you could apply that to anything you wanted.
so you can't just say "I want it to play my game" There is no "Play my game" function, you would have to make it play your game through code. So you have to make the AI have a goal
if(!button)
{
WalkToObject(oabjectToWalkTo);
}
WalkToObject(GameObject object)
{
bot.transform.position = object.transform.position;
}
you have to create the system from the ground up, or you can get a asset from the unity store that can controll AI, I think there are some that are free. But my suggestion keep learning.
Answer by tanoshimi · Dec 30, 2014 at 11:41 AM
If these are browser-based games, I'd recommend you look into Selenium -http://docs.seleniumhq.org - which makes it easy to record and playback mouse and keystrokes in a browser.
first, I really appreciate the response, and the help. I know a little about AI, primarily using if-then statements,and waypoints etc etc, but I just don't know how a bot can be automated to "discover" a button in apps because my games are only on my android and iPhone devices. For example, the first button in every video game in the entire history of video games is "START"as in "press the START button". $$anonymous$$y secondary part of the question is whether there is a way for the bot to differentiate one button from another when it pops on screen? Can I tell it to be aware of the text contained within the button? As in the previous example, search for "START"? This would be an example scenario: There is a START and a CANCEL button. How would I tell it to find, and click the button "START", not CANCEL?
Again, I apologize for the noobish quality of this question, and I really do appreciate the advice and the help. I had been working on one game for a while, and got distracted, and stopped, but I am now wanting to go over the game again.
Again, thanks for the help @tanoshimi and @jmgek
public GameObject bot;
private bool isBotBusy;
private bool is gamePaused;
if(isBotBusy && !gamePaused) //Place any conditions to mask AI
{
GoToButton(startGamebojectButton);
}
if else(isBotBusy && gamePaused)
{
GoToButton(cancleGameObjectButton);
}
GoToButton(GameObject Button)
{
bot.transform.position = button.transform.position;
}
thanks @jmgek! what you've written makes sense. Sorry, it's been a while since I wrote some code, but I can totally understand what you've written. I'm also just wondering how I can code so that it looks for specific buttons? For example, at the end of one of my games, you can either START OVER or CONTINU$$anonymous$$ How would I code so that it chooses START OVER?
Thank you for your continued help with this.
The same way just add to your if statments, or you could make a list or a dictonary to add more buttons. Or even hard code a switch statment. if else(isBotWantingToContinue && continueButton != null) { GoToButton(ContinueButton); }
Remember to vote up if I helped you :)
There's many different ways to approach this, depending on how tightly-coupled you want your bot to be to your game logic. You can create a bot that can play any game, without any knowledge of its internal workings, such as the $$anonymous$$ario AI championship: http://aigamedev.com/open/interviews/mario-ai/
Answer by username132323232 · Dec 31, 2014 at 12:08 AM
A few years ago I did some development on Palm OS. The emulator that I used had a nifty feature called "gremlins". Basically you could have 1000's of random input events testing your program. I don't think they had any AI, which is a good thing because given enough time they could catch very obscure bugs. Besides, you can't make many assumptions regarding who's gonna play your game )
If I was going to write test automation software, that's where I would start.
hey, @username132323232 which emulator were you using in those days? I guess, optimally, I would want to use an emulator to come in, day-to-day, and run through the game in some way. Click this button, don't click that button etc. I keep hearing about AutoIt or AutoHot$$anonymous$$ey, but I use a mac. If I am using my own app on my devices (or I suppose any app) how do I tell the bot to look for a specific button and click that? How does a bot know to look for the START button, or the CONTINUE button in its code? That's really all I have been asking, an I know its extremely basic, but I honestly don't know how to compel the bot to look for words within the app. I know about screen scraping etc but that seems extremely difficult and is definitely outside my knowledge currently. When handling buttons, am I supposed to locate it based on screen position, or by the words within the button.
I know this is a very basic question, but I am very new to this aspect of ga$$anonymous$$g and coding, and I do really appreciate all the help and guidance and sample code that has been given to me.
I think that was the standard emulator shipped with Palm SD$$anonymous$$. As I said, it was for Palm OS, so not applicable to Unity development. The reason why I mentioned it is that I liked the idea of a completely "dumb" approach to testing. Since the emulator could create thousands of input events in a very short time-frame, it would eventually hit the right buttons and navigate through the app. It would also try things that no intelligent tester would ever try :)
I'm not saying it's the best strategy, but something to consider in addition to other approaches. If you had something like that, you wouldn't need to customize it for obvious reasons. You could just leave it alone for a $$anonymous$$ute or overnight and see what kind of bugs it would uncover.
I'm not aware of anything like that available specifically for Unity, but I was not really looking for it yet.