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); }
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); }
public BeginAttackResponse BeginAttack([FromBody] BeginAttackRequest beginAttackRequest) { BeginAttackResponse response = new BeginAttackResponse(); response.From = new Location(1, 1); response.To = new Location(1, 2); return(response); }
private async Task <BeginAttackResponse> askForAttackLocationAsync(ApiPlayer player, BeginAttackStatus beginAttackStatus) { var beginAttackRequest = new BeginAttackRequest { Board = game.Board.SerializableTerritories, Status = beginAttackStatus }; return(await(await player.HttpClient.PostAsJsonAsync("/beginAttack", beginAttackRequest)) .EnsureSuccessStatusCode() .Content.ReadFromJsonAsync <BeginAttackResponse>()); }
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); }
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"); }
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); }
public BeginAttackResponse DecideBeginAttack(BeginAttackRequest beginAttackRequest) { var ownedTerritories = beginAttackRequest.Board.Where(t => t.OwnerName == Player.Name); var enemyTerritories = beginAttackRequest.Board.Where(t => t.OwnerName != null && t.OwnerName != Player.Name); foreach (var ownedTerritory in ownedTerritories) { foreach (var enemyTerritory in enemyTerritories) { if (areAdjacent(ownedTerritory, enemyTerritory)) { return(new BeginAttackResponse { From = ownedTerritory.Location, To = enemyTerritory.Location }); } } } throw new Exception("Cannot attack"); }
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); }
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"); }
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 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); }
public BeginAttackResponse BeginAttack([FromBody] BeginAttackRequest beginAttackRequest) { return(gamePlayer.DecideBeginAttack(beginAttackRequest)); }
public BeginAttackResponse BeginAttack([FromBody] BeginAttackRequest beginAttackRequest) { return(gameStrategy.DecideWhereToAttack(beginAttackRequest)); }
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; // } //} }
public BeginAttackResponse BeginAttack([FromBody] BeginAttackRequest beginAttackRequest) { return(createAttackResponse(beginAttackRequest)); }