private void Initialize() { #region Initializing variables gameEngine = new GameEngine(); connection = new Connection(); parser = new Parser(); ai = new AI(); mode = GameMode.AUTO; state = GameState.IDLE; message = ServerMessage.NO_ISSUES; error = GameError.NO_ERROR; #endregion /* * For collecting all the object discarded ** invoked garbage collector to improve the performance after the game start */ System.GC.Collect(); }
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"); } } } }