AI opponent: turn based game with collisions (pool table)

0 favourites
  • 4 posts
From the Asset Store
Hand-animated Sprite Base for isometric game/animation development
  • Using a pool table game as an example. How can I implement a computer opponent? I would like to have the computer try hitting the cue ball (white ball) in each of 360 degrees at 20 different levels of force. Then score the result of each of those attempts to decide which angle and force will have the best result, which the computer player will ultimately shoot.

    If the computer runs through all of these scenarios using the same code as the manual player, in the same time it takes to make a shot, then it could take multiple minutes for the computer opponent to decide what shot to make. Considering there are 360 * 20 = 7200 scenarios to play out and score.

    Is there a way to have each of the scenarios process invisibly to the human player as fast as the computer can calculate it, while using the same events that are already used to move the ball, detect collisions, redirect the balls, etc. for the human player?

    ..or is there a better way to approach this?

    I have searched and searched, but my keywords have not found an article that addresses this. Please point me if this has been covered elsewhere.

  • Thinking about it further.. I am going to place all of the object movement and collision resolution code into a function and place that function within a loop that adjusts the input parameters. In theory I think this would move the computations of multiple ticks into one tick.

    It has been a while since I figured out the objects movements and I don't see any dt factors. I used vx, vy calculations that seem to be independent of frame rate. - did I just get lucky that the speed of the animation is good on all tested devices? I'm not sure. This stuff gets complicated

    I am still open to better approaches...

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • you could do it all with math and figure it out in 1 tick. By math I mean calculating trajectory and collision points etc...opposed to actual events rendering to the screen.

    Are you asking for math help? (because I'm afraid I can't help you!) but if you have the math, you can definitely do it in 1 tick.

  • If AI opponent takes 1-2 seconds to think, it should look ok.

    In fact, it's better than instant shot without any delay.

    You can play some "I'm thinking..." animation or move the cue from side to side while the AI is "planning the shot".

    And also, calculating 7200 scenarios should take far less time than you think.

    I would suggest using this plugin (click Preview link to see how it works):

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)