vooga.aiEngine.pongAI
Class PongAIMemory

java.lang.Object
  extended by vooga.aiEngine.pongAI.PongAIMemory

public class PongAIMemory
extends java.lang.Object

PongAIMemory.java

Author:
Cody Freeman The AIMemory class just keeps track of player actions, analyzes them, then dumps information as needed to conserve space and to keep the computer from dying.

Constructor Summary
PongAIMemory()
          A basic constructor that initializes everything so that the program doesn't throw nullpointerexceptions.
 
Method Summary
 void addtoMemory(Position a)
          Adds the new position of the tracked object into a list, and makes the list behave like a queue, while allowing for the computer to see elements at many different points along the queue without popping things out and in all the time.
 Position findbestPositionfrommemory()
          Just reads out the current running best position is from the average position of previous collisions.
 Position getCurrentvelocity()
          Draws from memory to calculate the current velocity.
 Position getPreviousvelocity()
          Draws from memory to calculate a velocity prior to the current calculated velocity.
 boolean memoryhasdata()
          A simple check to see whether or not the AI has gathered enough data to carry out operations like projection.
 Position project(Position aiPos, Position targetPos, Position currentvelocity, int boardwidth)
          Projects the position at which the ball will reach the ai by calculating the total distance the ball will move in the y-direction in proportion to its movement in the x-direction and then counts how many times the ball would bounce off either side of the board to determine the final y-position once it reaches the x-position of the ai's paddle.
 void remembercollision(Position b)
          Adds a new collision position to a running average.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PongAIMemory

public PongAIMemory()
A basic constructor that initializes everything so that the program doesn't throw nullpointerexceptions.

Method Detail

addtoMemory

public void addtoMemory(Position a)
Adds the new position of the tracked object into a list, and makes the list behave like a queue, while allowing for the computer to see elements at many different points along the queue without popping things out and in all the time.

Parameters:
a - - A new position to be registered.

remembercollision

public void remembercollision(Position b)
Adds a new collision position to a running average. The X-position never changes because this is Pong, but the Y-Position changes over time. The formula used to determine a new best average position is that X = X, and Y = ((previous Y * (total times this has been called - 1)) + new Y) / (total times this has been called) .

Parameters:
b - - A new collision position to be factored in to the running average.

memoryhasdata

public boolean memoryhasdata()
A simple check to see whether or not the AI has gathered enough data to carry out operations like projection. In this case, three is used, as at least three positions are needed to determine two velocities.

Returns:
- Whether or not there are at least three elements in the memory.

getPreviousvelocity

public Position getPreviousvelocity()
Draws from memory to calculate a velocity prior to the current calculated velocity.

Returns:
- Position representing previous velocity of the ball.

getCurrentvelocity

public Position getCurrentvelocity()
Draws from memory to calculate the current velocity.

Returns:
- Position representing current velocity of the ball.

project

public Position project(Position aiPos,
                        Position targetPos,
                        Position currentvelocity,
                        int boardwidth)
Projects the position at which the ball will reach the ai by calculating the total distance the ball will move in the y-direction in proportion to its movement in the x-direction and then counts how many times the ball would bounce off either side of the board to determine the final y-position once it reaches the x-position of the ai's paddle.

Parameters:
aiPos - - Current position of the ai
targetPos - - Current position of the ball
currentvelocity - - Most recent change in position of the ball
boardwidth - - The width of the board, for use in calculating the number of times the ball will bounce of the sides of the board.
Returns:
- The Position at which the ball will cross AIPaddle's xcoordinate.

findbestPositionfrommemory

public Position findbestPositionfrommemory()
Just reads out the current running best position is from the average position of previous collisions.

Returns:
- The running average best position.