/* This team purports to play a defensive strategy. Unfortunately they are very lame at it. Essentially the idea is for each player on the team to "Tag" an opponent and stick to that opponent like glue. Ideally the player would stay on the east side of the opponent, blocking its progress to the goal. At this rudimentary stage, however, the players don't even necessarily track the right opponent all the time, and make no effort to stay to the east of them. Nevertheless, its a prototype for what could turn into a fairly interesting adaptive strategy. */ #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 UN(True) #define FALSE UN(FALSE) #define TagDist UN(TagDist) #define glue UN(glue) #define startup1 UN(startup1) #define startup2 UN(startup2) #define startup3 UN(startup3) #define startup4 UN(startup4) #define TRUE 1 #define FALSE 0 void InitializeGame () {}; void InitializePoint (); void WonPoint () {}; void LostPoint () {}; void GameOver () {}; int TagDist[5], glue; int startup1 = TRUE, startup2 = TRUE, startup3 = TRUE, startup4 = TRUE; void InitializePoint() { startup1 = TRUE; startup2 = TRUE; startup3 = TRUE; startup4 = TRUE; } int IsBallAdjacent() { int i; for (i = 0; i < 8; i++) { if (Surround[i] == BALL) { return TRUE; } } return FALSE; } char * NextToBall(int position) { 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 { return "KICK"; } } if (Surround[W]==BALL) { if ((OpponentDist(1) > 4)) return "W"; else { return "KICK"; } } if (Surround[NW]==BALL) { if ((OpponentDist(1) > 4) && (Surround[N]==EMPTY)) return "N"; else { return "KICK"; } } } char *Glue(int opp1, int opp1d) { if (opp1d==W) { if (opp1 > 4) return "W"; if ((BallDirection == N) || (BallDirection == NE)) return "NE"; if ((BallDirection == S) || (BallDirection == SE)) return "SE"; if (BallDirection == E) return "E"; if (BallDirection == NW) return "N"; if (BallDirection == SW) return "S"; return "W"; } if (opp1d==SW) { if (opp1 > 4) return "SW"; if ((BallDirection == N) || (BallDirection == NE)) return "NE"; if ((BallDirection == S) || (BallDirection == SE)) return "SE"; if (BallDirection == E) return "E"; if (BallDirection == NW) return "W"; if (BallDirection == SW) return "SW"; return "W"; } if (opp1d==NW) { if (opp1 > 4) return "NW"; if ((BallDirection == N) || (BallDirection == NE)) return "NE"; if ((BallDirection == S) || (BallDirection == SE)) return "SE"; if (BallDirection == E) return "E"; if (BallDirection == NW) return "NW"; if (BallDirection == SW) return "W"; return "W"; } if (opp1d==N) { if (opp1 > 4) return "N"; if ((BallDirection == N) || (BallDirection == NE)) return "NE"; if ((BallDirection == S) || (BallDirection == SE)) return "SE"; if (BallDirection == E) return "E"; if (BallDirection == NW) return "N"; if (BallDirection == SW) return "W"; return "W"; } if (opp1d == S) { if (opp1 > 4) return "S"; if ((BallDirection == N) || (BallDirection == NE)) return "NE"; if ((BallDirection == S) || (BallDirection == SE)) return "SE"; if (BallDirection == E) return "E"; if (BallDirection == NW) return "W"; if (BallDirection == SW) return "SW"; return "W"; } if (opp1d==E) { if (opp1 > 4) return "E"; if ((BallDirection == N) || (BallDirection == NE)) return "NE"; if ((BallDirection == S) || (BallDirection == SE)) return "SE"; if (BallDirection == E) return "E"; if (BallDirection == NW) return "NW"; if (BallDirection == SW) return "SW"; return "W"; } if (opp1d==SE) { if (opp1 > 4) return "SE"; if ((BallDirection == N) || (BallDirection == NE)) return "NE"; if ((BallDirection == S) || (BallDirection == SE)) return "SE"; if (BallDirection == E) return "E"; if (BallDirection == NW) return "NW"; if (BallDirection == SW) return "S"; return "W"; } if (opp1d==NE) { if (opp1 > 4) return "NE"; if ((BallDirection == N) || (BallDirection == NE)) return "NE"; if ((BallDirection == S) || (BallDirection == SE)) return "SE"; if (BallDirection == E) return "E"; if (BallDirection == NW) return "N"; if (BallDirection == SW) return "SW"; return "W"; } return OpponentDir(1); } void TagPlayer(int player) { // For now assume the player is on the same row, not necessarily true TagDist[player] = OpponentDist(1); } void TagInfo(int player) { int i = 1; // We know where he was last time, so he should be nearby // Hopefully he's the closest opponent if ((abs(TagDist[player] - OpponentDist(1)) <= 1)) { // At worst we're near him } else { // Someone else has moved in the way // Find someone who fits the bill for (i = 2; (i < 5) && (abs(TagDist[player] - OpponentDist(i)) > 1); i++) {} } if (i = 5) i = 1; TagDist[player] = OpponentDist(i); glue = i; } char *Player1 () { if (startup1) { startup1 = FALSE; TagPlayer(1); } GetInfo(); TagInfo(1); if (IsBallAdjacent()) return NextToBall(1); return OpponentDir(glue); } char *Player2 () { if (startup2) { startup2 = FALSE; TagPlayer(2); } GetInfo(); TagInfo(2); if (IsBallAdjacent()) return NextToBall(1); return OpponentDir(glue); } char *Player3 () { if (startup3) { startup3 = FALSE; TagPlayer(3); } GetInfo(); TagInfo(3); return OpponentDir(glue); } char *Player4 () { if (startup4) { startup4 = FALSE; TagPlayer(4); } GetInfo(); TagInfo(4); return OpponentDir(glue); }