Exemplo n.º 1
0
        // return next server command based on the current game data (Evaluation function)
        public string getNextCommand(GridManager gridManager, PlayerManager playerManager, ItemManager itemManager)
        {
            this.grid = gridManager.GetGrid();
            Point playerLocation = new Point(playerManager.OwnPlayer.X, playerManager.OwnPlayer.Y);
            Cell playerCurrentCell = gridManager.GetGrid()[playerLocation.X, playerLocation.Y];

            // Fire when enemy tank is in line of sight
            if (!Global.IsPeaceful && playerManager.OwnPlayer.CurrentHealth > Global.CriticalHealth)
            {
                foreach (Player player in playerManager.GetAllPlayers())
                {
                    if (player is PlayerAllied)
                        continue;

                    Point enemyTarget = new Point(player.X, player.Y);
                    if (player.CurrentHealth > 0 && isCellInRegion(playerLocation, enemyTarget, Global.LineOfSight))
                    {
                        if (playerManager.OwnPlayer.PlayerDirection == Direction.North && enemyTarget.Y < playerLocation.Y && enemyTarget.X == playerLocation.X)
                            return "SHOOT#";
                        else if (playerManager.OwnPlayer.PlayerDirection == Direction.East && enemyTarget.X > playerLocation.X && enemyTarget.Y == playerLocation.Y)
                            return "SHOOT#";
                        else if (playerManager.OwnPlayer.PlayerDirection == Direction.South && enemyTarget.Y > playerLocation.Y && enemyTarget.X == playerLocation.X)
                            return "SHOOT#";
                        else if (playerManager.OwnPlayer.PlayerDirection == Direction.West && enemyTarget.X < playerLocation.X && enemyTarget.Y == playerLocation.Y)
                            return "SHOOT#";
                        else
                            continue;
                    }
                }

                // find for low health target
                if (Global.EnableKillSteal)
                {
                    foreach (Player player in playerManager.GetAllPlayers())
                    {
                        if (player is PlayerAllied)
                            continue;

                        Point enemyTarget = new Point(player.X, player.Y);
                        if (player.CurrentHealth > 0 && player.CurrentHealth <= Global.KillStealHealth && isCellInRegion(playerLocation, enemyTarget, Global.KillStealRange))
                        {
                            List<Cell> optimumPath = findPath(playerCurrentCell, gridManager.GetGrid()[enemyTarget.X, enemyTarget.Y]);
                            Point nextneighborCellLocation = new Point(optimumPath[optimumPath.Count - 1].X, optimumPath[optimumPath.Count - 1].Y);
                            return getMovementMessage(playerLocation, nextneighborCellLocation);
                        }
                    }
                }
            }

            // find and take coin piles and life packs when possible
            if (itemManager.GetCoinPiles().Count > 0 || itemManager.GetLifePacks().Count > 0)
            {
                for (int region = 0; region < Global.ScanRange; region++)
                {
                    if (playerManager.OwnPlayer.CurrentHealth > Global.CriticalHealth)
                    {
                        for (int i = 0; i < itemManager.GetCoinPiles().Count; i++)
                        {
                            Point tmpCoinLocation = new Point(itemManager.GetCoinPiles()[i].X, itemManager.GetCoinPiles()[i].Y);
                            if (isCellInRegion(playerLocation, tmpCoinLocation, region))
                            {
                                List<Cell> optimumPath = findPath(playerCurrentCell, gridManager.GetGrid()[tmpCoinLocation.X, tmpCoinLocation.Y]);
                                Point nextneighborCellLocation = new Point(optimumPath[optimumPath.Count - 1].X, optimumPath[optimumPath.Count - 1].Y);
                                return getMovementMessage(playerLocation, nextneighborCellLocation);
                            }
                        }
                    }

                    if (isTopPlace(playerManager) || playerManager.OwnPlayer.CurrentHealth < Global.MaxHealthTarget || itemManager.GetCoinPiles().Count == 0)
                    {
                        for (int i = 0; i < itemManager.GetLifePacks().Count; i++)
                        {
                            Point tmpLifeLocation = new Point(itemManager.GetLifePacks()[i].X, itemManager.GetLifePacks()[i].Y);
                            if (isCellInRegion(playerLocation, tmpLifeLocation, region))
                            {
                                List<Cell> optimumPath = findPath(playerCurrentCell, gridManager.GetGrid()[tmpLifeLocation.X, tmpLifeLocation.Y]);
                                Point nextneighborCellLocation = new Point(optimumPath[optimumPath.Count - 1].X, optimumPath[optimumPath.Count - 1].Y);
                                return getMovementMessage(playerLocation, nextneighborCellLocation);
                            }
                        }
                    }
                }

            }
            else
            {
                // search for enemy target and follow
                for (int region = 0; region < Global.ScanRange; region++)
                {
                    for (int i = 0; i < playerManager.GetAllPlayers().Length; i++)
                    {
                        if (playerManager.GetAllPlayers()[i] is PlayerAllied || playerManager.GetAllPlayers()[i].CurrentHealth <= 0)
                            continue;

                        Point tmpEnemyLocation = new Point(playerManager.GetAllPlayers()[i].X, playerManager.GetAllPlayers()[i].Y);
                        if (isCellInRegion(playerLocation, tmpEnemyLocation, region))
                        {
                            List<Cell> optimumPath = findPath(playerCurrentCell, gridManager.GetGrid()[tmpEnemyLocation.X, tmpEnemyLocation.Y]);
                            Point nextneighborCellLocation = new Point(optimumPath[optimumPath.Count - 1].X, optimumPath[optimumPath.Count - 1].Y);
                            return getMovementMessage(playerLocation, nextneighborCellLocation);
                        }
                    }
                }

            }

            return getMovementMessage(new Point(0, 0), new Point(0, 0));
        }