A player cans now be controlled by the computer.
This is still a low level AI, as its only strategy is to reach hoops.
Altough a player can choose the robot to use, the AI automatically pick the one identified as "Thor" from the hashtable ( so be sure it does exist before using the AI ).
For the moment, the AI doesn't try to roquet, and neither to avoid sides of hoops or peg before the end.
Moreover, the robot currently moves straight to the position, without checking if it will collide other elements.
How to strike the ball
1. Angle of hit
The first step is to know which angle you'll hit the ball with. As you know position of your ball and hoop to reach, this is a trigonometric calcul as usual.
2. Find new position of robot
Then, you have to place the robot in the good position for your hit. As the ball rolls in the same direction wherever your hammer is, the objective is to place the hammer on the same position as the ball. So, as we know the relative angle and the relative distance of the hammer from the center of robot ( = center of circle), this can be done.
3. Control the robot
Basically, and for the moment, the control consists in 4 commands :
-Rotate the robot to look in the direction of the new position.
-Move the robot to this position.
-Rotate the robot to have the hammer on the ball.
-Hit the ball.
However, during the move, collisions will have to be checked, in order to recalculate a new path each time they actually occur.
4. Determine the initial Speed
The acceleration of the ball A is constant ( roll without slipping hypothesis ), and as you know the distance D between ball and hoop, you can calculate the initial speed thanks to fundamental principles of dynamics :
speed(0) = sqrt(- A * 2D )
Here, I've increased D enough so that the ball goes a bit more farther than the hoop.
---------
The AI actually works but the remaining bugs will have to be corrected before, I think, trying to think about a strongest AI than "hoops reaching" strategy.


No comments:
Post a Comment