nl.bluering.ppracing
Class Player

java.lang.Object
  |
  +--nl.bluering.ppracing.Player

public class Player
extends java.lang.Object

This class implements both the data concerning each player, as well as functions for calculating the route for the computer players.


Field Summary
static int COM
          The type of the player: Computer, Human or Network-player
static int DOWN
          The directions to which a player can go
static int HUM
          The type of the player: Computer, Human or Network-player
static int LEFT
          The directions to which a player can go
static int NET
          The type of the player: Computer, Human or Network-player
static int RIGHT
          The directions to which a player can go
static int SAME
          The directions to which a player can go
static int UP
          The directions to which a player can go
 
Constructor Summary
Player(java.lang.String nm, int t, Ppracing p, int startx, int starty, java.awt.Color col)
          Constructs a new player
 
Method Summary
 double ai(int x, int y, int vx, int vy, int l)
          This method does a depth-first search for the longest arc-distance that can be made within the given number of moves (level).
 void ask()
          Is used to make the computer do a move
 void checkterrain()
          Checks if the car has hit the grass.
 void clicked(int x, int y)
          For user input from mouse
 Car getcar()
           
 java.lang.String getname()
           
 boolean isai()
           
 boolean isnet()
           
static void main(java.lang.String[] ps)
          Method for testing purposes....
 void move(int m)
          For actually moving the car
 void moveai()
          This function is called by ask() to move the computer player
 void movecar(int x, int y)
          Internal function for moving the car to the new position.
 void settype(int i)
           
 java.lang.String toString()
           
 int type()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LEFT

public static final int LEFT
The directions to which a player can go

RIGHT

public static final int RIGHT
The directions to which a player can go

UP

public static final int UP
The directions to which a player can go

DOWN

public static final int DOWN
The directions to which a player can go

SAME

public static final int SAME
The directions to which a player can go

COM

public static final int COM
The type of the player: Computer, Human or Network-player

HUM

public static final int HUM
The type of the player: Computer, Human or Network-player

NET

public static final int NET
The type of the player: Computer, Human or Network-player
Constructor Detail

Player

public Player(java.lang.String nm,
              int t,
              Ppracing p,
              int startx,
              int starty,
              java.awt.Color col)
Constructs a new player
Parameters:
nm - The name of the player
aip - Is the player a computer player?
p - Parental applet
startx - Horizontal start location
starty - Vertical start location
col - Color of the player
Method Detail

ask

public void ask()
Is used to make the computer do a move

isai

public boolean isai()
Returns:
True if the player is a computer player

isnet

public boolean isnet()
Returns:
True if the player is a network player

type

public int type()
Returns:
The type of this player: HUM, COM, or NET

settype

public void settype(int i)

clicked

public void clicked(int x,
                    int y)
For user input from mouse
Parameters:
x - Horizontal (circuit) location
x - Vertical (circuit) location

move

public void move(int m)
For actually moving the car
Parameters:
m - One of: LEFT, RIGHT, UP, DOWN, SAME

movecar

public void movecar(int x,
                    int y)
Internal function for moving the car to the new position.

checkterrain

public void checkterrain()
Checks if the car has hit the grass. If so, the speed is reduced to (0,0)

getname

public java.lang.String getname()
Returns:
The name of the player

getcar

public Car getcar()
Returns:
The car of the player

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

moveai

public void moveai()
This function is called by ask() to move the computer player

ai

public double ai(int x,
                 int y,
                 int vx,
                 int vy,
                 int l)
This method does a depth-first search for the longest arc-distance that can be made within the given number of moves (level). As soon as the required depth is reached, the method returns the distance of the trip. For each level, the longest trip is chosen, until the best direction is found. When all possibilities have been searched, the function returns the best move to make. To reduce the number of searches, the hit of grass will reduce the depthlevel by 2. If the car actually hits the grass, it will crash... :-) (Due to the algorithm) Probably the only way to solve this problem accurately, is by using a genetic alghorithm. Yet this routine is clean and simple :-)
Parameters:
x - Horizontal start location
y - Vertical start location
vx - Current horizontal speed
vy - Current vertical speed
l - Level of search (or number of moves to maximize)

main

public static void main(java.lang.String[] ps)
Method for testing purposes....