public void CalculateMove() { treeDepth = 10; gameEngine = GameManager.Instance.GameEngine; map = gameEngine.Map; ownedTank = gameEngine.Tanks[gameEngine.PlayerNumber]; calculateArray(ownedTank.PositionX,ownedTank.PositionY); if (ownedTank.Health < 30 && gameEngine.LifePacks.Count>0) { //go for a health pile int minx = -1; int miny = -1; int minCount = Int16.MaxValue; for (int i = 0; i < gameEngine.LifePacks.Count;i++ ) { int x = gameEngine.LifePacks[i].PositionX; int y = gameEngine.LifePacks[i].PositionY; if(cells[x,y].moves.Count<gameEngine.LifePacks[i].TimeLeft){ if (minCount > cells[x, y].moves.Count) { minCount = cells[x, y].moves.Count; minx = x; miny = y; } } } if(minCount!=Int16.MaxValue){ //target is in minx , miny makeExcatMove(cells[minx,miny].moves[0]); } else if (canShoot()) { makeExcatMove("SHOOT"); } } else if(gameEngine.CoinPiles.Count>0){ //go for a coin pile int minx = -1; int miny = -1; int minCount = Int16.MaxValue; for (int i = 0; i < gameEngine.CoinPiles.Count; i++) { int x = gameEngine.CoinPiles[i].PositionX; int y = gameEngine.CoinPiles[i].PositionY; if (cells[x, y].moves.Count < gameEngine.CoinPiles[i].TimeLeft) { if (minCount > cells[x, y].moves.Count) { minCount = cells[x, y].moves.Count; minx = x; miny = y; } } } if (minCount != Int16.MaxValue) { //target is in minx , miny makeExcatMove(cells[minx, miny].moves[0]); } if (canShoot()) { makeExcatMove("SHOOT"); } }else{ if (canShootLongDistance()) { makeExcatMove("SHOOT"); } else { int minx = -1; int miny = -1; int minCount = Int16.MaxValue; for (int i = 0; i < gameEngine.Tanks.Count; i++) { int x = gameEngine.Tanks[i].PositionX; int y = gameEngine.Tanks[i].PositionY; if (minCount > cells[x, y].moves.Count) { minCount = cells[x, y].moves.Count; minx = x; miny = y; } } if (minCount != Int16.MaxValue) { //target is in minx , miny makeExcatMove(cells[minx, miny].moves[0]); } if (canShoot()) { makeExcatMove("SHOOT"); } } } }
/* * Handling the game startup message */ private void ParseStartUpMessage(string[] tokens) { // Placing the client's tank on the map foreach (string s in tokens) { string[] playerData = s.Split(';'); string[] location = playerData[1].Split(','); Tank tank = new Tank(int.Parse(playerData[0].Substring(1)), int.Parse(location[0]), int.Parse(location[1]), direction[int.Parse(playerData[2])]); GameManager.Instance.GameEngine.AddTank(tank); } }
public void AddTank(Tank tank) { map[tank.PositionX, tank.PositionY] = tank; tanks.Add(tank); }