Home > Tennis Women's News > Tennis Flash Game

Tennis Flash Game

Tennis Flash Game
how can i make table tennis/ ping pong games using visual basic/flash with artificial intelligence? pls help?

Since I don’t know VB or Flash, I can’t address that. Hopefully somebody else knows that.

Artificial Intelligence is what sparked my interest. Pong is not a game where decisions requiring artificial intelligence techniques are required. Instead, a little physics is required. The second law of thermodynamics states that matter can never be created or destroyed. Since all matter possesses energy, we can conclude that if matter is conserved, then so is energy. This is known as conservation of momentum (see link #1). Mathematically, this is:

p = mv

where p is the momentum, m is the mass of the object, and v is the velocity of the object. In the physics of pong, this is your most important law since you have a paddle colliding with a ball or a ball colliding with a net. Thus, if you can understand collisions, you can understand the game. Using frictionless pong tables in a room with no air drag (which is not that bad an assumption), all momentum is conserved, so the momentum before will equal the momentum afterwards:

p_before = p_after

So let’s work this out. Say you have a 0.1 kg ball and 1.0 kg paddle. The ball is heading 5.0 m/s toward the paddle and the player hits the ball with an impact velocity of 10 m/s. For our purposes suppose they stick for a moment and travel in tandem. So we get:

p_before = p_after
p_paddle + p_ball = p_tandem
m_p * v_p + m_b * v_b = (m_b + m_p) * v_t
1.0 * 10.0 + 0.1 * -5.0 = (0.1 + 1.0) * v_t
10.0 – 0.5 = 1.1 * v_t
1.1 * v_t = 9.5
v_t = 9.5 / 1.1
v_t = 8.6363…

One important thing to notice is that the velocity of the ball is negative since we said the ball and paddle are going in opposite directions. It doesn’t matter whether the ball’s or paddle’s velocity but ONE MUST HAVE AN OPPOSITE SIGN OF THE OTHER! Otherwise, the collision never takes place. :) Anyway, you can now use this new velocity to send the ball back to the other player.

This works only for one dimensional play. But we all know that play is done in three dimensions, so we must extend our last example a bit using vectors (link #3). In our case, we can think of a velocity vector v as v = , where v1 is the velocity in the x direction (east to west), v2 is the direction in the the y direction (south to north), and v3 is the velocity in the z direction (down to up). p and v in the previous equations are both vectors, so we can create a similar situation:

Suppose we have a 1.0 kg paddle that hits a ball with a velocity vector v_b = <-5.0, -1.5, -2.5> for the ball and v_p = <10.0, 1.0, 2.0>. Now can solve as before, except we do it three times, once for each direction:

For the x direction:
m_p * v_p + m_b * v_b = (m_b + m_p) * v_t
1.0 * 10.0 + 0.1 * -5.0 = (0.1 + 1.0) * v_t
10.0 – 0.5 = 1.1 * v_t
1.1 * v_t = 9.5
v_t = 9.5 / 1.1
v_t = 8.6363…

For the y direction:
m_p * v_p + m_b * v_b = (m_b + m_p) * v_t
1.0 * 1.0 + 0.1 * -1.5 = (0.1 + 1.0) * v_t
1.0 – 0.15 = 1.1 * v_t
1.1 * v_t = .85
v_t = .85 / 1.1
v_t = .77272…

For the z direction:
m_p * v_p + m_b * v_b = (m_b + m_p) * v_t
1.0 * 2.0 + 0.1 * -2.5 = (0.1 + 1.0) * v_t
2.0 – 0.25 = 1.1 * v_t
1.1 * v_t = 1.75
v_t = 1.75 / 1.1
v_t = 1.59090…

So, the ball will be traveling with a velocity of <8.6363, 0.77272, 1.59090> after the collision. All this math is tedious to do by hand, but easy for your program to do since computers are good at doing such repetitive operations.

The next consideration is whether the ball will hit the net. We can use equation 30 from link #4 to represent the line the ball travels along; we already have the v vector in equation 30 and we let x_0 be the point that the ball collided with the paddle at. We can define the net to be the yz-plane (a plane that runs south to north and faces east/west). Remember the yz-plane has a normal vector n = <1, 0, 0> and contains the point <0, 0, 0>. We can now use method 1 from link #5 to solve for when it “hits” the net using n = <1, 0, 0> p_1 = x_0 (the point we were hit at), p_2 = x_0 + v (an arbitrary point on the line we’re traveling on) and p_3 = <0, 0, 0>. So, using the equation from link #4:

<1, 0, 0> dot (<0, 0, 0> – )
———————————————————————————-
<1, 0, 0> dot ()

Wow! How ugly, the nice thing is cancellation does make things much nicer:

<1, 0, 0> dot <-x_01, -x_02, -x_03>
——————————————————–
<1, 0, 0> dot

And because of the zeros in the normal vector, we get more cancellation when we do the dot product:

u = -x_01 / v_1

Thus, our final point of intersection will be: . Again, another repetitive operation made easy by computers. This will tells us where we hit (or cross over) the net. From here, I would look at the z component of the vector and if it is lower than some net height a, then calculate a collision between the ball and the net and send the ball back. Otherwise, the computer opponent should use the line equation we derived earlier to predict where the ball will go next and move its paddle accordingly.

I went through everything in great detail so your program will be realistic and you’ll know exactly WHAT you’re programming! To summarize:

1) Pong is a matter of physics.
2) The ball will continue moving in the velocity its traveling in until it’s hit (Newton’s first law).
3) Vectors are used to extend a one dimensional game (boring) into a three dimensional game (exciting).
4) There are only two operations in pong: a collision or intersection. We do a collision when the ball hits a paddle or ball. We do an intersection to determine if the net was hit, where the computer opponent should put its paddle, or if the ball went out of bounds.

Therefore, in writing your program, I would write generalized functions that can do intersections and collisions for arbitrary situations. If you can do this, you’re more than half way there.


NCAA Tailgate Ping Pong Table With Net


NCAA Tailgate Ping Pong Table With Net


$119.99


Just sitting in the parking lot waiting for the game to start? Pass the time in style with the Wild Sales® NCAA® tailgate table. It features a lightweight, sturdy aluminum construction and folds up for easy storage and transportation. The included net attaches to the sides, allowing you to get in a game of ping pong. The table is designed to look like a football field and is decorated with the t…

Kent Golden Flashes Suntime Mens Sports Watch w/ Leather Band - NCAA College Athletics


Kent Golden Flashes Suntime Mens Sports Watch w/ Leather Band – NCAA College Athletics


$41.95


A true sports person’s watch, the Sport features: a durable rotating timer/bezel, stainless steel finish, scratch resistant crystal, quartz accurate movement, color coordinated leather strap, date function and a big, bold California State (Northridge) Matadors team logo on the dial. Wear it to a game, while watching a game or just to show off your NCAA pride wherever you go!…

Kent Golden Flashes Suntime Mens Executive Watch - NCAA College Athletics


Kent Golden Flashes Suntime Mens Executive Watch – NCAA College Athletics


$139.95


For a more formal look. The Executive features a fluted gold toned bezel and two tone gold overlay and stainless steel link bracelet. Now with Date Calendar feature. Wear it to a game, while watching a game or just to show off your NCAA pride wherever you go!…

DREAMGEAR DGWII-1232 NINTENDO WII TABLE TENNIS PADDLE TWIN PACK


DREAMGEAR DGWII-1232 NINTENDO WII TABLE TENNIS PADDLE TWIN PACK



ADDS REALISM TO THE WII(TM) TABLE TENNIS GAMES; IR PASS-THROUGH PORT; INCLUDES 1 RED & 1 BLUE TABLE TENNIS PADDLE ATTACHMENTS; COMPATIBLE WITH WII MOTIONPLUS(TM) & WII REMOTE(TM) JACKET…


Be Sociable, Share!
  1. No comments yet.
  1. No trackbacks yet.