public DeployArmyResponse DecideWhereToReinforce(DeployArmyRequest deployArmyRequest)
        {
            DeployArmyResponse response  = new DeployArmyResponse();
            var            myTerritories = GetMyTerritories(deployArmyRequest.Board);
            BoardTerritory smallPup      = new BoardTerritory();

            smallPup.Armies = 99999;
            foreach (BoardTerritory territory in myTerritories)
            {
                if (territory.Armies < smallPup.Armies)
                {
                    smallPup = territory;
                }
            }
            response.DesiredLocation = smallPup.Location;
            return(response);
        }
Ejemplo n.º 2
0
        private BeginAttackResponse createAttackResponse(BeginAttackRequest beginAttack)
        {
            var from    = new Location();
            var to      = new Location();
            var tempTer = new BoardTerritory();

            //This logic will not grab a neighbour of the territory.
            foreach (var ter in beginAttack.Board)
            {
                if (!(ter.OwnerName is null) && ter.OwnerName == "Emmanuel" && ter.Armies > 1)
                {
                    from = ter.Location;
                    for (int i = ter.Location.Column - 1; i <= ter.Location.Column + 1; i++)
                    {
                        if (i < 0)
                        {
                            continue;
                        }
                        for (int j = ter.Location.Row - 1; j <= ter.Location.Row + 1; j++)
                        {
                            if (j < 0)
                            {
                                continue;
                            }
                            to.Column = i;
                            to.Row    = j;
                            tempTer   = beginAttack.Board.FirstOrDefault(r => r.Location == to);
                            if (!(tempTer is null) && tempTer.OwnerName != "Emmanuel" && tempTer.Armies > 0)
                            {
                                to = tempTer.Location;
                                return(new BeginAttackResponse {
                                    From = from, To = to
                                });
                            }
                        }
                    }
                }
            }

            return(new BeginAttackResponse {
                From = from, To = to
            });
        }
        public void DecideBeginAttackAttacksFirstNeighbor()
        {
            var attackSource = new BoardTerritory {
                Armies = 1, OwnerName = gamePlayer.Player.Name, Location = new Location(0, 0)
            };
            var attackTarget = new BoardTerritory {
                Armies = 1, OwnerName = "Enemy", Location = new Location(0, 1)
            };

            Board.Add(attackSource);
            Board.Add(attackTarget);

            var beginAttackRequest = new BeginAttackRequest {
                Board = Board, Status = BeginAttackStatus.YourTurn
            };
            var beginAttackResponse = gamePlayer.DecideBeginAttack(beginAttackRequest);

            Assert.That(beginAttackResponse.From == attackSource.Location && beginAttackResponse.To == attackTarget.Location);
        }
        internal ContinueAttackResponse DecideToMakeNewAttack(ContinueAttackRequest continueAttackRequest)
        {
            ContinueAttackResponse       response      = new ContinueAttackResponse();
            IEnumerable <BoardTerritory> myTerritories = GetMyTerritories(continueAttackRequest.Board);
            BoardTerritory topDog = new BoardTerritory();

            topDog.Armies = 0;
            foreach (BoardTerritory territory in myTerritories)
            {
                if (territory.Armies > topDog.Armies)
                {
                    if (GetNumBadTerritories(territory, continueAttackRequest.Board) > 0)
                    {
                        topDog = territory;
                    }
                }
            }
            IEnumerable <BoardTerritory> tDogNeighbors = GetNeighbors(topDog, continueAttackRequest.Board);
            BoardTerritory smallPup = new BoardTerritory();

            smallPup.Armies = 99999;
            foreach (BoardTerritory t in tDogNeighbors)
            {
                if (!myTerritories.Contains(t) && t.Armies < smallPup.Armies)
                {
                    smallPup = t;
                }
            }

            if (topDog.Armies > (2 * smallPup.Armies))
            {
                response.ContinueAttacking = true;
            }
            else
            {
                response.ContinueAttacking = false;
            }
            return(response);
        }
Ejemplo n.º 5
0
        private BeginAttackResponse createAttackResponse(BeginAttackRequest beginAttackRequest)
        {
            BeginAttackResponse response = new BeginAttackResponse();
            var attackerLocation         = new Location();
            var defenderLocation         = new Location();
            var temp = new BoardTerritory();

            //from is the attacker to is the defender
            foreach (BoardTerritory space in beginAttackRequest.Board)
            {
                if (space.OwnerName == "Rusty" && space.Armies > 1)
                {
                    attackerLocation = space.Location;
                    //look at the next location to the right, left, up, down, up-right diagonal,
                    //down-right diagonal, up-left diagonal, down-left diagonal
                    for (int i = space.Location.Column - 1; i <= (space.Location.Column + 1); i++)
                    {
                        for (int j = space.Location.Row - 1; j <= (space.Location.Row + 1); j++)
                        {
                            if (j < 0)
                            {
                                continue;
                            }
                            defenderLocation.Column = i;
                            defenderLocation.Row    = j;
                            temp = beginAttackRequest.Board.FirstOrDefault(d => d.Location == defenderLocation);
                            if ((temp != null) && temp.OwnerName != "Rusty" && temp.Armies > 0)
                            {
                                return(new BeginAttackResponse {
                                    From = attackerLocation, To = defenderLocation
                                });
                            }
                        }
                    }
                }
            }
            throw new Exception("No valid attack");
        }
Ejemplo n.º 6
0
        private BeginAttackResponse createAttackResponse(BeginAttackRequest beginAttackRequest)
        {
            BeginAttackResponse response = new BeginAttackResponse();
            var attackerLocation         = new Location();
            var neighbour = new BoardTerritory();

            //from is the attacker to is the defender
            foreach (BoardTerritory space in beginAttackRequest.Board)
            {
                if (space.OwnerName == "HectoritoBonito")
                {
                    attackerLocation = new Location(space.Location.Row, space.Location.Column);


                    for (int i = space.Location.Column - 1; i <= (space.Location.Column + 1); i++)
                    {
                        for (int j = space.Location.Row - 1; j <= (space.Location.Row + 1); j++)
                        {
                            if (j < 0)
                            {
                                continue;
                            }


                            neighbour = beginAttackRequest.Board.FirstOrDefault(t => t.Location == new Location(i, j));

                            if (neighbour != null && neighbour.OwnerName != "HectoritoBonito" && neighbour.Armies >= 1)
                            {
                                response.From = attackerLocation;
                                response.To   = neighbour.Location;
                                return(response);
                            }
                        }
                    }
                }
            }
            return(null);
        }
        public BeginAttackResponse DecideWhereToAttack(BeginAttackRequest attackRequest)
        {
            IEnumerable <BoardTerritory> board         = attackRequest.Board.Reverse();
            BeginAttackResponse          beginAttack   = new BeginAttackResponse();
            IEnumerable <BoardTerritory> myTerritories = GetMyTerritories(attackRequest.Board).Reverse();
            BoardTerritory topDog = new BoardTerritory();

            topDog.Armies = 0;
            //int maxNumBadTerritories = 8;

            foreach (BoardTerritory t in myTerritories)
            {
                if (t.Armies > topDog.Armies)
                {
                    if (GetNumBadTerritories(t, board) > 0)
                    {
                        topDog = t;
                        //maxNumBadTerritories = GetNumBadTerritories(t, board);
                    }
                }
            }
            beginAttack.From = topDog.Location;

            IEnumerable <BoardTerritory> tDogNeighbors = GetNeighbors(topDog, attackRequest.Board);
            BoardTerritory smallPup = new BoardTerritory();

            smallPup.Armies = 99999;
            foreach (BoardTerritory t in tDogNeighbors)
            {
                if (!myTerritories.Contains(t) && t.Armies < smallPup.Armies)
                {
                    smallPup = t;
                }
            }
            beginAttack.To = smallPup.Location;

            return(beginAttack);
        }
        internal ManeuverResponse DecideWhereToManeuver(ManeuverRequest maneuverRequest)
        {
            ManeuverResponse             response      = new ManeuverResponse();
            IEnumerable <BoardTerritory> myTerritories = GetMyTerritories(maneuverRequest.Board);
            BoardTerritory fromTerritory = new BoardTerritory();

            fromTerritory.Armies = 0;
            foreach (BoardTerritory territory in myTerritories)
            {
                if (GetNumBadTerritories(territory, maneuverRequest.Board) == 0 && territory.Armies > fromTerritory.Armies)
                {
                    fromTerritory = territory;
                }
            }
            if (fromTerritory.Armies == 0)
            {
                response.Decide = false;
            }
            else
            {
                response.Decide = true;
                response.From   = fromTerritory.Location;
                BoardTerritory toTerritory = new BoardTerritory();
                int            toScore     = 999999;
                foreach (BoardTerritory territory in GetNeighbors(fromTerritory, maneuverRequest.Board))
                {
                    if (territory.Location.Column + territory.Location.Row < toScore)
                    {
                        toScore     = territory.Location.Column + territory.Location.Row;
                        toTerritory = territory;
                    }
                }
                response.To = toTerritory.Location;
            }

            return(response);
        }
        public DeployArmyResponse DecideArmyWhereToPlacement(DeployArmyRequest deployRequest)
        {
            DeployArmyResponse           deployResponse = new DeployArmyResponse();
            IEnumerable <BoardTerritory> myTerritories  = GetMyTerritories(deployRequest.Board);
            int maxRow     = 0;
            int maxCollumn = 0;

            foreach (BoardTerritory bt in deployRequest.Board)
            {
                if (bt.Location.Row > maxRow)
                {
                    maxRow = bt.Location.Row;
                }
                if (bt.Location.Column > maxCollumn)
                {
                    maxCollumn = bt.Location.Column;
                }
            }
            List <Location> cornerLocations = new List <Location>();

            cornerLocations.Add(new Location(0, 0));
            cornerLocations.Add(new Location(0, maxCollumn));
            cornerLocations.Add(new Location(maxRow, 0));
            cornerLocations.Add(new Location(maxRow, maxCollumn));

            IEnumerable <BoardTerritory> corners = deployRequest.Board.Where(t => cornerLocations.Contains(t.Location));

            corners = corners.Reverse();

            if (myTerritories.Count() == 0)
            {
                foreach (BoardTerritory t in corners)
                {
                    if (t.OwnerName == null)
                    {
                        deployResponse.DesiredLocation = t.Location;
                        startTerritory = t;
                        return(deployResponse);
                    }
                }
                foreach (BoardTerritory t in deployRequest.Board.Reverse())
                {
                    if (t.OwnerName == null)
                    {
                        deployResponse.DesiredLocation = t.Location;
                        startTerritory = t;
                        return(deployResponse);
                    }
                }
            }
            else
            {
                IEnumerable <BoardTerritory> neighborsOfCorner = GetNeighbors(startTerritory, deployRequest.Board);
                foreach (BoardTerritory t in neighborsOfCorner)
                {
                    if (t.OwnerName != null && !myTerritories.Contains(t))
                    {
                        deployResponse.DesiredLocation = startTerritory.Location;
                    }
                    if (t.OwnerName == null)
                    {
                        deployResponse.DesiredLocation = t.Location;
                        return(deployResponse);
                    }
                }
                foreach (BoardTerritory t in neighborsOfCorner)
                {
                    IEnumerable <BoardTerritory> friendlyNeighborsOfCorner = neighborsOfCorner.Where(ter => myTerritories.Contains(ter));
                    BoardTerritory smallPup = new BoardTerritory();
                    smallPup.Armies = 9999;
                    foreach (BoardTerritory bt in friendlyNeighborsOfCorner)
                    {
                        if (bt.Armies < smallPup.Armies)
                        {
                            smallPup = bt;
                        }
                    }
                    deployResponse.DesiredLocation = smallPup.Location;
                    return(deployResponse);
                }
            }

            return(deployResponse);
        }