/* This team attempts to use a fairly fluid strategy of having two players attack the ball constantly, another player playing forward of the ball in an effort to creat breakaways, and the fourth player hanging back of the ball playing a kind of goalie. Depending on the game situation different players can take different rules. This team is at a decent level of play, but could use MANY improvements. In particular the goalie isn't very effective. Nevertheless it contains lots of ideas for use in other agents. */ #include "../interface.c" #include "routines.h" /* Standard Functions already defined as unique in interface.c (These are here for reference, you don't have to redefine them */ /* #define InitializeGame UN(InitializeGame) #define InitializePoint UN(InitializePoint) #define WonPoint UN(WonPoint) #define LostPoint UN(LostPoint) #define GameOver UN(GameOver) #define Player1 UN(Player1) #define Player2 UN(Player2) #define Player3 UN(Player3) #define Player4 UN(Player4) */ #define TRUE 1 #define FALSE 0 #define NextToBall UN(NextToBall) #define IsBallAdjacent UN(IsBallAdjacent) #define ballx UN(ballx) #define bally UN(bally) #define kicked UN(kicked) #define startpoint UN(startpoint) #define recent3x UN(recent3x) #define recent3y UN(recent3y) #define position1 UN(position1) #define position2 UN(position2) #define position3 UN(position3) #define position4 UN(position4) #define Goalie UN(goalie) #define Attack1 UN(attack1) #define Attack2 UN(attack2) #define Forward UN(forward) int ballx = 39; int bally = 16; int kicked = FALSE; int startpoint = TRUE; int recent3x = 39; int recent3y = 19; int recentx = 39; int recenty = 16; int position1; int position2; int position3; int position4; void InitializeGame () {}; void InitializePoint () { // Set up routine start out with some estimate kicked = FALSE; ballx = 39; bally = 16; startpoint = TRUE; } void WonPoint () {}; void LostPoint () {}; void GameOver () {}; int IsBallAdjacent() { // Am I next to the ball? int i; for (i = 0; i < 8; i++) { if (Surround[i] == BALL) { return TRUE; } } return FALSE; } char * NextToBall(int position) { // What to do when next to ball if (Surround[N]==BALL) { if (Surround[NE]==EMPTY) return "NE"; else if (Surround[E]==EMPTY) return "E"; else return "N"; } if (Surround[NE]==BALL) { if (Surround[E]==EMPTY) return "E"; else if (Surround[N] ==EMPTY) return "N"; else return "SE"; } if (Surround[E] == BALL) { if (Surround[SE]==EMPTY) return "SE"; else if (Surround[NE]==EMPTY) return "NE"; else if (Surround[N]==EMPTY) return "N"; else if (Surround[S]==EMPTY) return "S"; else return "W"; } if (Surround[SE]==BALL) { if (Surround[E]==EMPTY) return "E"; else if (Surround[S]==EMPTY) return "S"; else if (Surround[NE]==EMPTY) return "NE"; else return "SW"; } if (Surround[S]==BALL) { if (Surround[SE]==EMPTY) return "SE"; else if (Surround[E]==EMPTY) return "E"; else if (Surround[SW]==EMPTY) return "SW"; else return "W"; } if (Surround[SW]==BALL) { if ((OpponentDist(1) > 4) && (Surround[S]== EMPTY)) return "S"; else { kicked = TRUE; return "KICK"; } } if (Surround[W]==BALL) { if ((OpponentDist(1) > 4)) return "W"; else { kicked = TRUE; return "KICK"; } } if (Surround[NW]==BALL) { if ((OpponentDist(1) > 4) && (Surround[N]==EMPTY)) return "N"; else { kicked = TRUE; return "KICK"; } } } char *Attack1() { // Basically run to the ball and kick it recentx = MyX(); recenty = MyY(); if (IsBallAdjacent()) return NextToBall(1); kicked = FALSE; if (Surround[BallDirection]==EMPTY) return BallDir(); return "E"; } char *Attack2() { // Ditto recent3x = MyX(); recent3y = MyY(); if (IsBallAdjacent()) return NextToBall(2); kicked = FALSE; return BallDir(); } char *Forward() { // Keep forward of the ball unless its close int x, y; if (IsBallAdjacent()) return NextToBall(3); if (BallDirection == W) return "W"; else if (BallDirection == SW) return "SW"; else if (BallDirection == NW) return "NW"; x = MyX(); y = MyY(); if (BallDirection == N) if ((x > 10) && Surround[N]==EMPTY) return "N"; else if (Surround[NW] == EMPTY) return "NW"; if (BallDirection == S) if ((x > 10) && (Surround[S]==EMPTY)) return "S"; else if (Surround[SW]==EMPTY) return "SW"; // Ball is either east, NE, SW if ((BallDist() > 15) && Surround[BallDirection]==EMPTY) return BallDir(); if ((BallDist() < 4) && Surround[BallDirection]==EMPTY) return BallDir(); if (y > ((recenty + recent3y)/2)) return "N"; else return "S"; kicked = FALSE; return BallDir(); } char *Goalie() { // Keep back of the ball unless its close int x,y; if (IsBallAdjacent()) return NextToBall(4); if (BallDirection == E) if (Surround[E]==EMPTY) return "E"; else if (Surround[NE]==EMPTY) return "NE"; else return "SE"; if (BallDirection == SE) if (Surround[SE]==EMPTY) return "SE"; else if (Surround[E]==EMPTY) return "E"; else return "S"; if (BallDirection == NE) if (Surround[NE]==EMPTY) return "NE"; else return "E"; x = MyX(); y = MyY(); if (BallDirection == N) if (x > 75) return "N"; else return "NE"; if (BallDirection == S) if (x > 75) return "S"; else return "SE"; // Never move onto east half of field if (x < XSize() / 2) { Surround[W] = BALL; Surround[NW]= BALL; Surround[SW] = BALL; } // Ball is either west, sw, or nw if ((BallDist() > 20) && Surround[BallDirection]==EMPTY) return BallDir(); if ((BallDist() < 7) && Surround[BallDirection]==EMPTY) return BallDir(); if (y > ((recenty + recent3y)/2)) return "N"; else return "S"; } char *Player1 () { GetInfo(); if (startpoint == TRUE) { // This is the first guy to go, start assessing the situation Debug("Player 1 is first"); startpoint = FALSE; if (BallDist() < ((YSize() / 2) - MyY())) { Debug("Ball is on my half of the field. Attacking"); position1 = 1; position2 = 2; position3 = 3; position4 = 4; } else { Debug("Ball is on bottom."); position1 = 4; position2 = 3; position3 = 2; position4 = 1; } } switch (position1) { // Play whatever role is specified case 1: return Attack1(); case 2: return Attack2(); case 3: return Forward(); case 4: return Goalie(); } } char *Player2 () { GetInfo(); if (startpoint == TRUE) { // This is the first guy to go, start assessing the situation Debug("Player 2 is first"); startpoint = FALSE; if (BallDirection == N) { Debug("Ball is on north half of the field."); position1 = 1; position2 = 2; position3 = 3; position4 = 4; } else if (BallDirection == S) { Debug("Ball is on south of the field. "); position1 = 4; position2 = 3; position3 = 2; position4 = 1; } else { Debug("Ball is in front of me."); position1 = 3; position2 = 1; position3 = 2; position4 = 4; } } switch (position2) { case 1: return Attack1(); case 2: return Attack2(); case 3: return Forward(); case 4: return Goalie(); } } char *Player3 () { GetInfo(); if (startpoint == TRUE) { // This is the first guy to go, start assessing the situation Debug("Player 3 is first"); startpoint = FALSE; if (BallDirection == N) { Debug("Ball is on north half of the field."); position1 = 1; position2 = 2; position3 = 3; position4 = 4; } else if (BallDirection = S) { Debug("Ball is on south of the field. "); position1 = 4; position2 = 3; position3 = 2; position4 = 1; } else { Debug("Ball is in front of me."); position1 = 4; position2 = 2; position3 = 1; position4 = 3; } } switch (position3) { case 1: return Attack1(); case 2: return Attack2(); case 3: return Forward(); case 4: return Goalie(); } } char *Player4 () { GetInfo(); if (startpoint == TRUE) { // This is the first guy to go, start assessing the situation Debug("Player 4 is first"); startpoint = FALSE; if (BallDist() < ((YSize() / 2))) { Debug("Ball is on my half of the field. Attacking"); position1 = 4; position2 = 3; position3 = 2; position4 = 1; } else { Debug("Ball is on top half of the field. Defending"); position1 = 1; position2 = 2; position3 = 3; position4 = 4; } } switch (position4) { case 1: return Attack1(); case 2: return Attack2(); case 3: return Forward(); case 4: return Goalie(); } }