import java.awt.*; public class attack extends Player { static int Surround[] = new int[9]; static int OppDir[] = new int[5]; static int OppDist[] = new int[5]; static int MyX; static int MyY; static int BallDirection; static int BallDistance; public void InitializeGame() { } public void InitializePoint () { // Set up routine start out with some estimate } public void WonPoint () {} public void LostPoint () {}; public void GameOver () {} private void GetInfo() // Convert all of the perceptions to variables for ease { int i; for (i = 0; i < 9; i++) Surround[i] = Look(i); for (i = 1; i < 5; i++) { OppDir[i] = GetOpponentDirection(i); OppDist[i] = GetOpponentDistance(i); } MyX = GetLocation().x; MyY = GetLocation().y; BallDirection = GetBallDirection(); BallDistance = GetBallDistance(); } // Crap! The ball is behind me. Cut it off. private int CutOff() { switch (BallDirection) { case NORTH: if (Surround[NORTHEAST] == EMPTY) return NORTHEAST; return NORTH; case NORTHEAST: if (Surround[NORTHEAST] == EMPTY) return NORTHEAST; return EAST; case NORTHWEST: if (Surround[NORTHEAST] == EMPTY) return NORTHEAST; return NORTH; case EAST: if (Surround[EAST] == EMPTY) return EAST; return NORTHEAST; case WEST: return WEST; case SOUTHEAST: if (Surround[SOUTHEAST] == EMPTY) return SOUTHEAST; return SOUTH; case SOUTHWEST: if (Surround[SOUTHEAST] == EMPTY) return SOUTHEAST; return SOUTH; case SOUTH: if (Surround[SOUTHEAST] == EMPTY) return SOUTHEAST; return EAST; } return BallDirection; } private int NextToBall(int playernum) { // What to do when next to ball boolean kickit = true; boolean pushit = true; // Check to see if kicking is a bad idea for (int i = 1; (i < 5) && (OppDist[i] < 10); i++) { if (OppDir[i] == BallDirection) { kickit = false; if (OppDist[i] < 3) pushit = false; } } // sideline check if ((BallDirection == NORTHWEST) && (MyY == 1)) { kickit = false; pushit = false; } else if ((BallDirection == SOUTHWEST) && (MyY == (FieldY() - 2))) { kickit = false; pushit = false; } if (Surround[NORTH]==BALL) { if (OppDist[1] > 4) {// set up for diagnonal attack if (Surround[NORTHEAST] == EMPTY) return NORTHEAST; return EAST; } // check for diagonal push if (((Surround[WEST] == OPPONENT) || (Surround[NORTHWEST] == OPPONENT)) && (Surround[NORTHEAST] != TEAMMATE)) { if (MyY > 3) { return KICK; } else return NORTHEAST; } if (Surround[NORTHEAST]==EMPTY) return NORTHEAST; else if (Surround[EAST]==EMPTY) return EAST; if (pushit) return NORTH; return NORTHEAST; } if (Surround[NORTHEAST]==BALL) { //if ((Surround[NORTH]==OPPONENT) && (MyX < 60) && (Surround[EAST]==EMPTY)) //return NORTHEAST; if (Surround[EAST]==EMPTY) return EAST; else if (Surround[NORTH] ==EMPTY) return NORTH; else return SOUTHEAST; } if (Surround[EAST] == BALL) { if (Surround[SOUTHEAST]==EMPTY) return SOUTHEAST; else if (Surround[NORTHEAST]==EMPTY) return NORTHEAST; else if (Surround[NORTH]==EMPTY) return NORTH; else if (Surround[SOUTH]==EMPTY) return SOUTH; else return WEST; } if (Surround[SOUTHEAST]==BALL) { if (Surround[EAST]==EMPTY) return EAST; else if (Surround[SOUTH]==EMPTY) return SOUTH; else if (Surround[NORTHEAST]==EMPTY) return NORTHEAST; else return SOUTHWEST; } if (Surround[SOUTH]==BALL) { if (OppDist[1] > 4) {// set up for diagnonal attack if (Surround[SOUTHEAST] == EMPTY) return SOUTHEAST; return EAST; } if (((Surround[WEST] == OPPONENT) || (Surround[SOUTHWEST] == OPPONENT)) && (Surround[SOUTHEAST] != TEAMMATE)) { // break up diagnonal push if (MyY < 28) { return KICK; } else return SOUTHEAST; } if (Surround[SOUTHEAST]==EMPTY) return SOUTHEAST; else if (Surround[EAST]==EMPTY) return EAST; else if (Surround[SOUTHWEST]==EMPTY) return SOUTHWEST; else return WEST; } if (Surround[SOUTHWEST]==BALL) { return KICK; } if (Surround[WEST]==BALL) { return KICK; } if (Surround[NORTHWEST]==BALL) { // similar to SOUTHWEST return KICK; } return BallDirection; } private int GoAfterBall(int playernum) { if (Surround[BallDirection] == EMPTY) return BallDirection; switch (BallDirection) { case NORTH: // Try Northeasterly approach first case NORTHEAST: case EAST: case SOUTHEAST: case SOUTH: return CutOff(); case SOUTHWEST: if (Surround[SOUTH] == EMPTY) return SOUTH; return WEST; case WEST: if (Surround[NORTHWEST] == EMPTY) return NORTHWEST; return SOUTHWEST; case NORTHWEST: if (Surround[NORTH] == EMPTY) return NORTH; return KICK; } // make java happy return BallDirection; } public int getAction() { GetInfo(); if (BallDistance == 1) return NextToBall(ID); else return GoAfterBall(ID); } }