0
\$\begingroup\$

I want to make an ai for my game.

Currently my game controller uses onmousedown and onmouseup functions and some other factors?

My game is for two players on same screen but you don't always have someone to play game with so I wanna design Ai for that. How can I go about to design Ai for something like that?

\$\endgroup\$
1
  • 2
    \$\begingroup\$ Make a function containing your events and call them with onMouse for the player. You can then just call the function when needed in the AI script \$\endgroup\$ Sep 13 at 16:19
0
\$\begingroup\$

Do you find it difficult to translate AI strategies into user input? Or those methods are inaccessible for some reason?

If yes, then one way you can solve this is by not putting your game logic into onMouseDown and similar functions. If you keep the general logics separate, those input functions will just invoke the needed logics code (or maybe queue some actions, if you're going for a more robust approach). By itself it's not very different, you just have your code in another function now and have to call it. But on the other hand, your AI now does not need to create "input events" and can perform in-game actions directly (or, again, queue them).

Once you think about strategy for your AI from the point of implementation, you will see, that it needs to interact with your game world anyway. For example, even to press buttons, your AI needs to know what's going on in the game world. It needs access to your game state and it needs to be able to observe/read all the values that affect its actions. And if AI has all that, it can just as well affect that state, without producing mouse click events.

\$\endgroup\$
1
  • \$\begingroup\$ I think what you mean is the stuff that i am doing in onmousedown and onmouseup i should do it in different functions and just call them, I am gonna try this approach today. \$\endgroup\$
    – Nomi
    Sep 14 at 13:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.