I am developing a javascript game. It has a pretty complex UI requiring lot of user interaction to be able to make a move. I am now developing the AI for the game so that it can be played against a computer. I was thinking of programatically raising events using the dispatchEvent method to drive the UI when the computer is playing the game, but I run into a problem what if the user also starts interacting with the UI - that will completely mess up the game. So is there a pattern followed by people developing javascript games to take care of this problem?
Let's say I have a set of event handlers - onmousedown, onmousemove, onmouseup
etc. Both human player and computer use these handlers to make a move. But human player relies on manually interacting with the app, whereas the computer invokes these handlers via the dispatchEvent method. When its the computer's turn, I need a way to tell js: look I don't want you to invoke these handlers on manual UI interaction. only invoke them in response to a dispatchEvent