コード例 #1
0
        public BeginAttackResponse BeginAttack([FromBody] BeginAttackRequest beginAttackRequest)
        {
            BeginAttackResponse response = new BeginAttackResponse();

            response.From = new Location(ownedX, ownedY);
            if (attackTimes % 5 == 0)
            {
                response.To = new Location(ownedX, ownedY--);
                attackTimes++;
            }
            else if (attackTimes % 5 == 1)
            {
                response.To = new Location(ownedX--, ownedY--);
                attackTimes++;
            }
            else if (attackTimes % 5 == 2)
            {
                response.To = new Location(ownedX--, ownedY);
                attackTimes++;
            }
            else if (attackTimes % 5 == 3)
            {
                response.To = new Location(ownedX--, ownedY++);
                attackTimes++;
            }
            else
            {
                response.To = new Location(ownedX, ownedY++);
                attackTimes++;
            }


            return(response);
        }
コード例 #2
0
        public BeginAttackResponse DecideWhereToAttack(BeginAttackRequest attackRequest)
        {
            BeginAttackResponse          beginAttack   = new BeginAttackResponse();
            IEnumerable <BoardTerritory> myTerritories = GetMyTerritories(attackRequest.Board);
            BoardTerritory topDog = myTerritories.First();

            foreach (BoardTerritory t in myTerritories)
            {
                if (t.Armies >= topDog.Armies)
                {
                    topDog = t;
                }
            }
            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);
        }
コード例 #3
0
        public BeginAttackResponse BeginAttack([FromBody] BeginAttackRequest beginAttackRequest)
        {
            BeginAttackResponse response = new BeginAttackResponse();

            response.From = new Location(1, 1);
            response.To   = new Location(1, 2);
            return(response);
        }
コード例 #4
0
        public BeginAttackResponse DecideWhereToAttack(BeginAttackRequest attackRequest)
        {
            BeginAttackResponse beginAttack = new BeginAttackResponse();
            int max = 0;
            IEnumerable <BoardTerritory> neighbors = new List <BoardTerritory>();

            foreach (var territory in attackRequest.Board)
            {
                if (!(territory.OwnerName == null))
                {
                    if (territory.OwnerName == "Stuart")
                    {
                        if (territory.Armies > max)
                        {
                            max = territory.Armies;
                        }
                    }
                }
            }
            foreach (var territory in attackRequest.Board)
            {
                if (!(territory.OwnerName == null))
                {
                    if (territory.OwnerName == "Stuart" && territory.Armies == max)
                    {
                        beginAttack.From = territory.Location;
                        neighbors        = GetNeighbors(territory, attackRequest.Board);
                    }
                }
            }

            foreach (var neighbor in neighbors)
            {
                if (!(neighbor.OwnerName == null))
                {
                    if (neighbor.OwnerName != "Stuart")
                    {
                        beginAttack.To = neighbor.Location;
                    }
                    if (neighbor.OwnerName != "Stuart" && neighbor.Armies == 0)
                    {
                        beginAttack.To = neighbor.Location;
                        return(beginAttack);
                    }
                    else if (neighbor.OwnerName != "Stuart" && neighbor.Armies < max)
                    {
                        beginAttack.To = neighbor.Location;
                    }
                }
            }
            return(beginAttack);
        }
コード例 #5
0
        public BeginAttackResponse BeginAttack([FromBody] BeginAttackRequest beginAttackRequest)
        {
            BeginAttackResponse response = new BeginAttackResponse();

            foreach (var myTerritory in beginAttackRequest.Board.Where(t => t.OwnerName == config["PlayerName"]).OrderByDescending(t => t.Armies))
            {
                var myNeighbors = GetNeighbors(myTerritory, beginAttackRequest.Board);
                var destination = myNeighbors.Where(t => t.OwnerName != config["PlayerName"]).OrderBy(t => t.Armies).FirstOrDefault();
                if (destination != null)
                {
                    response.From = myTerritory.Location;
                    response.To   = destination.Location;
                    return(response);
                }
            }
            throw new Exception("No territory I can attack");
        }
コード例 #6
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");
        }
コード例 #7
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);
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        public BeginAttackResponse WhenToAttack(BeginAttackRequest beginAttackRequest)
        {
            BeginAttackResponse          beginAttack   = new BeginAttackResponse();
            IEnumerable <BoardTerritory> neighbors     = new List <BoardTerritory>();
            IEnumerable <BoardTerritory> myTerritories = GetMyTerritories(beginAttackRequest.Board);

            do
            {
                foreach (var territory in myTerritories)
                {
                    var myNeighbors = GetNeighbors(territory, beginAttackRequest.Board);

                    foreach (var neighbor in myNeighbors)
                    {
                        if ((territory.Armies > 1000 || territory.Armies > neighbor.Armies * 2) && neighbor.OwnerName != "Wyatt" && territory.Armies > 1)
                        {
                            beginAttack.From = territory.Location;
                            beginAttack.To   = neighbor.Location;
                            return(beginAttack);
                        }
                        if (neighbor.Armies < 2 && territory.Armies > 3 && neighbor.OwnerName != "Wyatt")
                        {
                            beginAttack.To   = neighbor.Location;
                            beginAttack.From = territory.Location;
                            return(beginAttack);
                        }
                        if (neighbor.OwnerName != "Wyatt" && territory.Armies > 1)
                        {
                            beginAttack.To   = neighbor.Location;
                            beginAttack.From = territory.Location;
                        }
                    }
                }
            } while (beginAttack.To == null || beginAttack.From == null);

            return(beginAttack);
        }
コード例 #10
0
        public BeginAttackResponse DecideWhereToAttack(BeginAttackRequest attackRequest)
        {
            BeginAttackResponse          beginAttack   = new BeginAttackResponse();
            IEnumerable <BoardTerritory> neighbors     = new List <BoardTerritory>();
            IEnumerable <BoardTerritory> myTerritories = GetMyTerritories(attackRequest.Board);

            do
            {
                foreach (var territory in myTerritories)
                {
                    var myNeighbors = GetNeighbors(territory, attackRequest.Board);

                    foreach (var neighbor in myNeighbors)
                    {
                        if ((territory.Armies > 1000 || territory.Armies > neighbor.Armies * 2) && neighbor.OwnerName != "Stuart" && territory.Armies > 1)
                        {
                            beginAttack.From = territory.Location;
                            beginAttack.To   = neighbor.Location;
                            return(beginAttack);
                        }
                        if (neighbor.Armies < 2 && territory.Armies > 3 && neighbor.OwnerName != "Stuart")
                        {
                            beginAttack.To   = neighbor.Location;
                            beginAttack.From = territory.Location;
                            return(beginAttack);
                        }
                        if (neighbor.OwnerName != "Stuart" && territory.Armies > 1)
                        {
                            beginAttack.To   = neighbor.Location;
                            beginAttack.From = territory.Location;
                        }
                    }
                }
            } while (beginAttack.To == null || beginAttack.From == null);

            return(beginAttack);


            //foreach (var territory in myTerritories)
            //{

            //    if (territory.Armies == max)
            //    {
            //        beginAttack.From = territory.Location;
            //        neighbors = GetNeighbors(territory, attackRequest.Board);
            //    }

            //}

            //foreach (var neighbor in neighbors)
            //{
            //    if (!(neighbor.OwnerName == null))
            //    {
            //        if (neighbor.OwnerName != "Stuart")
            //            beginAttack.To = neighbor.Location;
            //        if (neighbor.OwnerName != "Stuart" && neighbor.Armies == 0)
            //        {
            //            beginAttack.To = neighbor.Location;
            //            return beginAttack;
            //        }
            //        else if (neighbor.OwnerName != "Stuart" && neighbor.Armies < max)
            //            beginAttack.To = neighbor.Location;
            //    }
            //}
        }