Beispiel #1
0
        public override Action GetAction(MapUpdated mapUpdated)
        {
            _mapUtils = new MapUtils(mapUpdated.Map);

            var myCharacter     = _mapUtils.GetCharacterInfoFor(mapUpdated.ReceivingPlayerId);
            var myCoordinate    = _mapUtils.GetCoordinateFrom(myCharacter.Position);
            var myColouredTiles = _mapUtils.GetCoordinatesFrom(myCharacter.ColouredPositions);


            if (myCharacter.CarryingPowerUp)
            {
                return(Action.Explode);
            }

            var coordinateLeft = myCoordinate.MoveIn(Action.Left);

            if (!myColouredTiles.Contains(coordinateLeft) &&
                _mapUtils.CanPlayerPerformAction(myCharacter.Id, Action.Left))
            {
                return(Action.Left);
            }

            var coordinateRight = myCoordinate.MoveIn(Action.Right);

            if (!myColouredTiles.Contains(coordinateRight) &&
                _mapUtils.CanPlayerPerformAction(myCharacter.Id, Action.Right))
            {
                return(Action.Right);
            }

            var coordinateUp = myCoordinate.MoveIn(Action.Up);

            if (!myColouredTiles.Contains(coordinateUp) &&
                _mapUtils.CanPlayerPerformAction(myCharacter.Id, Action.Up))
            {
                return(Action.Up);
            }

            var coordinateDown = myCoordinate.MoveIn(Action.Down);

            if (!myColouredTiles.Contains(coordinateDown) &&
                _mapUtils.CanPlayerPerformAction(myCharacter.Id, Action.Down))
            {
                return(Action.Down);
            }

            return(Action.Stay);
        }
Beispiel #2
0
        public override Action GetAction(MapUpdated mapUpdated)
        {
            _mapUtils = new MapUtils(mapUpdated.Map); // Keep this

            // Implement your bot here!

            //1. Find Closest powerup
            //2. move to closest powerup
            //3. Move three more steps.
            //



            // The following is a simple example bot. It tries to
            // 1. Explode PowerUp
            // 2. Move to a tile that it is not currently owning
            // 3. Move in the direction where it can move for the longest time.

            var directions = new List <Action> {
                Action.Down, Action.Right, Action.Left, Action.Up
            };
            var playerInfos     = mapUpdated.Map.CharacterInfos;
            var myCharacter     = _mapUtils.GetCharacterInfoFor(mapUpdated.ReceivingPlayerId);
            var myCoordinate    = _mapUtils.GetCoordinateFrom(myCharacter.Position);
            var myColouredTiles = _mapUtils.GetCoordinatesFrom(myCharacter.ColouredPositions);
            var Pits            = _mapUtils.GetObstacleCoordinates();

            var powerUpCoordinates       = _mapUtils.GetPowerUpCoordinates();
            var prevDistancePow          = 999999;
            var distanceToClosestPowerUp = 999;

            var validActionsThatPaintsNotOwnedTile = directions.Where(dir =>
                                                                      !myColouredTiles.Contains(myCoordinate.MoveIn(dir)) && _mapUtils.IsMovementPossibleTo(myCoordinate.MoveIn(dir))).ToList();


            var distanceToClosestPlayerWithPowerUp    = 999;
            var closestPlayerWithoutPowerUp           = new MapCoordinate(999, 999);
            var closestPlayerWithPowerUp              = GetClosestPlayerWithPowerUp(myCoordinate, myCharacter, playerInfos);
            var distanceToclosestPlayerWithoutPowerUp = myCoordinate.GetManhattanDistanceTo(closestPlayerWithoutPowerUp);

            distanceToClosestPlayerWithPowerUp = myCoordinate.GetManhattanDistanceTo(closestPlayerWithPowerUp);

            var closestPowerUp = new MapCoordinate(999, 999);



            if (distanceToClosestPlayerWithPowerUp < 6 || distanceToclosestPlayerWithoutPowerUp < 2)
            {
                // Debug.WriteLine("Danger:" + distanceToClosestPlayerWithPowerUp);
                var BestAction             = Action.Up;
                var previousActionDistance = distanceToClosestPlayerWithPowerUp;

                validActionsThatPaintsNotOwnedTile = directions.Where(dir =>
                                                                      !Pits.Contains(myCoordinate.MoveIn(dir)) && _mapUtils.IsMovementPossibleTo(myCoordinate.MoveIn(dir))).ToList();

                foreach (var Action in validActionsThatPaintsNotOwnedTile)
                {
                    var TestCord       = myCoordinate.MoveIn(Action);
                    var ActionDistance = TestCord.GetManhattanDistanceTo(closestPlayerWithPowerUp);
                    if (_mapUtils.GetTileAt(TestCord) == Tile.Obstacle || _mapUtils.GetTileAt(TestCord) == Tile.Character)
                    {
                        if (Action == Action.Up)
                        {
                            return(BestAction = Action.Down);
                        }
                        if (Action == Action.Down)
                        {
                            return(BestAction = Action.Up);
                        }
                        if (Action == Action.Left)
                        {
                            return(BestAction = Action.Right);
                        }
                        if (Action == Action.Right)
                        {
                            return(BestAction = Action.Left);
                        }
                        continue;
                    }

                    if (ActionDistance > 5)
                    {
                        if (ActionDistance > previousActionDistance)
                        {
                            previousActionDistance = TestCord.GetManhattanDistanceTo(closestPlayerWithPowerUp);
                            BestAction             = Action;
                        }
                    }
                }
                // Debug.WriteLine("Safe:" + distanceToClosestPlayerWithPowerUp);
                return(BestAction);
            }


            if (myCharacter.CarryingPowerUp)
            {
                var closestPlayer = GetClosestPlayerWithoutPowerUp(myCoordinate, myCharacter, playerInfos);
                var distanceToClosestPlayerNoPowerUp = myCoordinate.GetManhattanDistanceTo(closestPlayer);

                closestPowerUp           = getClosestPowerUp(myCoordinate);
                distanceToClosestPowerUp = myCoordinate.GetManhattanDistanceTo(closestPowerUp);


                if (distanceToClosestPowerUp < 5 || distanceToClosestPlayerNoPowerUp < 5)
                {
                    return(Action.Explode);
                }
                else
                {
                    var BestActionPlayer = Action.Down;


                    validActionsThatPaintsNotOwnedTile = directions.Where(dir =>
                                                                          !Pits.Contains(myCoordinate.MoveIn(dir)) && _mapUtils.IsMovementPossibleTo(myCoordinate.MoveIn(dir))).ToList();


                    var previousActionDistancePlayer = 9999;

                    foreach (var Action in validActionsThatPaintsNotOwnedTile)
                    {
                        var TestCord = myCoordinate.MoveIn(Action);
                        if (_mapUtils.GetTileAt(TestCord) == Tile.Obstacle || _mapUtils.GetTileAt(TestCord) == Tile.Character)
                        {
                            continue;
                        }
                        var distanceToPlayer = TestCord.GetManhattanDistanceTo(closestPlayerWithoutPowerUp);

                        if (distanceToClosestPlayerNoPowerUp <= distanceToClosestPowerUp)
                        {
                            if (TestCord.GetManhattanDistanceTo(closestPlayer) < distanceToClosestPlayerNoPowerUp)
                            {
                                if (TestCord.GetManhattanDistanceTo(closestPlayer) < previousActionDistancePlayer)
                                {
                                    previousActionDistancePlayer = TestCord.GetManhattanDistanceTo(closestPlayer);
                                    BestActionPlayer             = Action;
                                }
                            }
                        }
                        else
                        {
                            if (TestCord.GetManhattanDistanceTo(closestPowerUp) < distanceToClosestPowerUp)
                            {
                                if (TestCord.GetManhattanDistanceTo(closestPowerUp) < previousActionDistancePlayer)
                                {
                                    previousActionDistancePlayer = TestCord.GetManhattanDistanceTo(closestPowerUp);
                                    BestActionPlayer             = Action;
                                }
                            }
                        }
                    }
                    return(BestActionPlayer);
                }
            }
            else
            {
                closestPowerUp           = getClosestPowerUp(myCoordinate);
                distanceToClosestPowerUp = myCoordinate.GetManhattanDistanceTo(closestPowerUp);

                if (powerUpCoordinates.Length > 0 || distanceToClosestPowerUp < 30)
                {
                    var ClosestPit           = GetClosestPit(myCoordinate, Pits);
                    var distanceToClosestPit = myCoordinate.GetManhattanDistanceTo(ClosestPit);
                    validActionsThatPaintsNotOwnedTile = directions.Where(dir =>
                                                                          !Pits.Contains(myCoordinate.MoveIn(dir)) && _mapUtils.IsMovementPossibleTo(myCoordinate.MoveIn(dir))).ToList();

                    if (distanceToClosestPit < 1)
                    {
                        validActionsThatPaintsNotOwnedTile = directions.Where(dir =>
                                                                              !Pits.Contains(myCoordinate.MoveIn(dir)) && !myColouredTiles.Contains(myCoordinate.MoveIn(dir)) && _mapUtils.IsMovementPossibleTo(myCoordinate.MoveIn(dir))).ToList();
                    }


                    var BestAction             = Action.Right;
                    var previousActionDistance = 9999;
                    foreach (var Action in validActionsThatPaintsNotOwnedTile)
                    {
                        var TestCord = myCoordinate.MoveIn(Action);


                        var TestDistance = TestCord.GetManhattanDistanceTo(closestPowerUp);

                        if (TestDistance < previousActionDistance)
                        {
                            previousActionDistance = TestDistance;
                            Debug.WriteLine(previousActionDistance);
                            BestAction = Action;
                        }
                    }
                    if (distanceToclosestPlayerWithoutPowerUp <= 2 && distanceToClosestPowerUp < 2)
                    {
                        if (BestAction == Action.Up)
                        {
                            return(Action.Down);
                        }
                        if (BestAction == Action.Down)
                        {
                            return(Action.Up);
                        }
                        if (BestAction == Action.Left)
                        {
                            return(Action.Right);
                        }
                        if (BestAction == Action.Right)
                        {
                            return(Action.Left);
                        }
                    }
                    if (_mapUtils.GetTileAt(myCoordinate.MoveIn(BestAction)) == Tile.Obstacle /* || _mapUtils.GetTileAt(TestCord) == Tile.Character*/)
                    {
                        if (BestAction == Action.Up)
                        {
                            return(Action.Right);
                        }
                        if (BestAction == Action.Down)
                        {
                            return(Action.Left);
                        }
                        if (BestAction == Action.Left)
                        {
                            return(Action.Up);
                        }
                        if (BestAction == Action.Right)
                        {
                            return(Action.Down);
                        }
                    }

                    return(BestAction);
                }
                else
                {
                    validActionsThatPaintsNotOwnedTile = directions.Where(dir =>
                                                                          !myColouredTiles.Contains(myCoordinate.MoveIn(dir)) && !Pits.Contains(myCoordinate.MoveIn(dir)) && _mapUtils.IsMovementPossibleTo(myCoordinate.MoveIn(dir))).ToList();


                    var BestAction       = Action.Left;
                    var distanceToCenter = 9999;
                    foreach (var Action in validActionsThatPaintsNotOwnedTile)
                    {
                        var TestCord = myCoordinate.MoveIn(Action);

                        //if (_mapUtils.GetTileAt(TestCord) == Tile.Obstacle || _mapUtils.GetTileAt(TestCord) == Tile.Character)
                        //{
                        //    if (Action == Action.Up)
                        //    {
                        //        return BestAction = Action.Down;
                        //    }
                        //    if (Action == Action.Down)
                        //    {
                        //        return BestAction = Action.Up;
                        //    }
                        //    if (Action == Action.Left)
                        //    {
                        //        return BestAction = Action.Right;
                        //    }
                        //    if (Action == Action.Right)
                        //    {
                        //        return BestAction = Action.Left;
                        //    }
                        //    continue;
                        //}
                        var TestDistance = TestCord.GetManhattanDistanceTo(new MapCoordinate(mapUpdated.Map.Width / 2, mapUpdated.Map.Height / 2));
                        if (TestDistance <= 3)
                        {
                            if (validActionsThatPaintsNotOwnedTile.Any())
                            {
                                return(validActionsThatPaintsNotOwnedTile.First());
                            }
                        }
                        if (TestDistance < distanceToCenter)
                        {
                            if (TestDistance < distanceToCenter)
                            {
                                distanceToCenter = TestDistance;

                                BestAction = Action;
                            }
                        }
                    }
                    return(BestAction);
                }
            }
        }
        public override Action GetAction(MapUpdated mapUpdated)
        {
            _mapUtils = new MapUtils(mapUpdated.Map); // Keep this

            // Implement your bot here!

            // The following is a simple example bot. It tries to
            // 1. Explode PowerUp
            // 2. Move to a tile that it is not currently owning
            // 3. Move in the direction where it can move for the longest time.

            var directions = new List <Action> {
                Action.Down, Action.Right, Action.Left, Action.Up
            };

            var myCharacter     = _mapUtils.GetCharacterInfoFor(mapUpdated.ReceivingPlayerId);
            var myCoordinate    = _mapUtils.GetCoordinateFrom(myCharacter.Position);
            var myColouredTiles = _mapUtils.GetCoordinatesFrom(myCharacter.ColouredPositions);

            if (myCharacter.CarryingPowerUp)
            {
                return(Action.Explode);
            }

            var validActionsThatPaintsNotOwnedTile = directions.Where(dir =>
                                                                      !myColouredTiles.Contains(myCoordinate.MoveIn(dir)) && _mapUtils.IsMovementPossibleTo(myCoordinate.MoveIn(dir))).ToList();

            if (validActionsThatPaintsNotOwnedTile.Any())
            {
                return(validActionsThatPaintsNotOwnedTile.First());
            }

            var possibleLeftMoves  = 0;
            var possibleRightMoves = 0;
            var possibleUpMoves    = 0;
            var possibleDownMoves  = 0;

            var testCoordinate = _mapUtils.GetCoordinateFrom(myCharacter.Position).MoveIn(Action.Left);

            while (_mapUtils.IsMovementPossibleTo(testCoordinate))
            {
                possibleLeftMoves++;
                testCoordinate = testCoordinate.MoveIn(Action.Left);
            }

            testCoordinate = _mapUtils.GetCoordinateFrom(myCharacter.Position).MoveIn(Action.Right);
            while (_mapUtils.IsMovementPossibleTo(testCoordinate))
            {
                possibleRightMoves++;
                testCoordinate = testCoordinate.MoveIn(Action.Right);
            }

            testCoordinate = _mapUtils.GetCoordinateFrom(myCharacter.Position).MoveIn(Action.Up);
            while (_mapUtils.IsMovementPossibleTo(testCoordinate))
            {
                possibleUpMoves++;
                testCoordinate = testCoordinate.MoveIn(Action.Up);
            }

            testCoordinate = _mapUtils.GetCoordinateFrom(myCharacter.Position).MoveIn(Action.Down);
            while (_mapUtils.IsMovementPossibleTo(testCoordinate))
            {
                possibleDownMoves++;
                testCoordinate = testCoordinate.MoveIn(Action.Down);
            }

            var list = new List <(Action, int)>
            {
                (Action.Left, possibleLeftMoves),
                (Action.Right, possibleRightMoves),
                (Action.Up, possibleUpMoves),
                (Action.Down, possibleDownMoves)
            };

            list.Sort((first, second) => first.Item2.CompareTo(second.Item2));
            list.Reverse();

            return(list.FirstOrDefault(l => l.Item2 > 0).Item1);
        }