Skip to content

Commit

Permalink
Merge 858adc0 into 0166762
Browse files Browse the repository at this point in the history
  • Loading branch information
samsmithnz committed Nov 20, 2021
2 parents 0166762 + 858adc0 commit 24b9b06
Show file tree
Hide file tree
Showing 53 changed files with 1,653 additions and 1,641 deletions.
3 changes: 1 addition & 2 deletions src/Battle.Logic/Characters/Character.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Battle.Logic.AbilitiesAndEffects;
using Battle.Logic.Game;
using Battle.Logic.Items;
using Battle.Logic.Map;
using Battle.Logic.Utility;
using System.Collections.Generic;
using System.Numerics;

Expand Down Expand Up @@ -76,6 +74,7 @@ public void SetLocationAndRange(string[,,] map, Vector3 characterLocation, int f
//Place the player in the new location on the map
map[(int)characterLocation.X, (int)characterLocation.Y, (int)characterLocation.Z] = "P";
UpdateCharacterFOV(map);
//Get targets
List<Character> targetCharacters = FieldOfView.GetCharactersInView(map, Location, ShootingRange, opponentCharacters);
TargetCharacters = new List<string>();
foreach (Character item in targetCharacters)
Expand Down
28 changes: 12 additions & 16 deletions src/Battle.Logic/Characters/CharacterAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,18 @@ public AIAction CalculateAIAction(string[,,] map, Character character, Team sour
break;
}
}
//Double check - if it's still not assigned, assign the last value
if (aiActionResult == null)
{
aiActionResult = aiValues[aiValues.Count - 1].Value;
}
////Double check - if it's still not assigned, assign the last value
//if (aiActionResult == null)
//{
// aiActionResult = aiValues[aiValues.Count - 1].Value;
//}
}

aiActionResult.MapString = CreateAIMap(map);
aiActionResult.Log = log;
if (aiActionResult != null)
{
aiActionResult.MapString = CreateAIMap(map);
aiActionResult.Log = log;
}
return aiActionResult;
}

Expand Down Expand Up @@ -171,7 +174,7 @@ public AIAction CalculateAIAction(string[,,] map, Character character, Team sour
moveThenShootScore = baseScore;

//Calculate chance to hit
List<Character> characters = FieldOfView.GetCharactersInView(fovMap, location, sourceCharacter.ShootingRange, opponentTeam.Characters);
List<Character> characters = FieldOfView.GetCharactersInView(fovMap, location, sourceCharacter.ShootingRange, opponentTeam.Characters);
if (characters.Count == 0)
{
//No characters in view, deduct some more points - this move achieves very little
Expand Down Expand Up @@ -276,14 +279,7 @@ public AIAction CalculateAIAction(string[,,] map, Character character, Team sour

private string CreateAIMap(string[,,] map)
{
if (aiValues == null)
{
return null;
}
else
{
return MapCore.GetMapStringWithAIValuesSecond(map, aiValues);
}
return MapCore.GetMapStringWithAIValuesSecond(map, aiValues);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/Battle.Logic/Characters/CharacterPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public static Character CreateJeffHero(string[,,] map, Vector3 startingLocation,
Speed = 12,
Intelligence = 75,
ActionPointsCurrent = 2,
ActionPointsMax= 2,
ActionPointsMax = 2,
MobilityRange = 8,
ShootingRange = 30,
WeaponEquipped = WeaponPool.CreateRifle(),
Expand Down
2 changes: 1 addition & 1 deletion src/Battle.Logic/Characters/CoverState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ public bool IsFlanked
public bool InEastHalfCover { get; set; }
public bool InSouthHalfCover { get; set; }
public bool InWestHalfCover { get; set; }

}
}
4 changes: 2 additions & 2 deletions src/Battle.Logic/Encounters/Encounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,9 @@ public static EncounterResult AttackCharacter(string[,,] map, Character sourceCh
isCriticalHit = tempResult.IsCriticalHit;
isHit = true;
log = tempResult.Log;
if (targetCharacter.HitpointsCurrent<=0)
if (targetCharacter.HitpointsCurrent <= 0)
{
affectedMap.Add(new KeyValuePair<Vector3, int>(targetCharacter.Location, 1));
affectedMap.Add(new KeyValuePair<Vector3, int>(targetCharacter.Location, 1));
}
}
else
Expand Down
1 change: 0 additions & 1 deletion src/Battle.Logic/Encounters/EncounterCore.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Battle.Logic.AbilitiesAndEffects;
using Battle.Logic.Characters;
using Battle.Logic.Items;
using System;
using System.Collections.Generic;
using System.Numerics;

Expand Down
4 changes: 1 addition & 3 deletions src/Battle.Logic/Encounters/MovementAction.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Numerics;
using System.Text;

namespace Battle.Logic.Encounters
{
Expand Down
1 change: 0 additions & 1 deletion src/Battle.Logic/Game/Team.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Battle.Logic.Characters;
using Battle.Logic.Utility;
using System.Collections.Generic;
using System.Numerics;

Expand Down
2 changes: 1 addition & 1 deletion src/Battle.Logic/Map/FieldOfView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ public static Team UpdateTeamFOV(string[,,] map, Team team)
{
team.FOVMap[(int)item.X, (int)item.Y, (int)item.Z] = FOV_CanSee;
}

}
return team;
}
Expand Down
7 changes: 5 additions & 2 deletions src/Battle.Logic/Map/MapCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,12 @@ public static string GetMapStringWithItemLayers(string[,,] map, List<Vector3> ba
public static string GetMapStringWithAIValuesSecond(string[,,] mapTemplate, List<KeyValuePair<Vector3, AIAction>> list)
{
string[,,] map = (string[,,])mapTemplate.Clone();
foreach (KeyValuePair<Vector3, AIAction> item in list)
if (list != null)
{
map[(int)item.Key.X, (int)item.Key.Y, (int)item.Key.Z] = item.Value.Score.ToString();
foreach (KeyValuePair<Vector3, AIAction> item in list)
{
map[(int)item.Key.X, (int)item.Key.Y, (int)item.Key.Z] = item.Value.Score.ToString();
}
}
return MapCore.GetMapString(map, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Battle.Logic/Map/MovementPossibileTiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class MovementPossibileTiles
{
//Find a path to this target location
PathFindingResult result = PathFinding.FindPath(map, sourceLocation, item);
//If we could find a path, the cost of the path is within the range, and we haven't already identified a route to this tile, add it
//If we could find a path, the cost of the path is within the range, and we haven't already identified a route to this tile, add it
if (result.Tiles.Count > 0 && result.Tiles[result.Tiles.Count - 1].TraversalCost <= range * i && !verifiedTiles.Contains(item))
{
//The current tile isn't tracked, add it as a verified tile
Expand Down
40 changes: 19 additions & 21 deletions src/Battle.Tests/Characters/CharacterAITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
using Battle.Logic.Game;
using Battle.Logic.Map;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Numerics;

namespace Battle.Tests.Characters
{
Expand All @@ -17,25 +15,25 @@ public class CharacterAITests
public void CharacterJethroAIMovesIntoFullCoverNoOpponentsTest()
{
//Arrange
Mission mission = new Mission
Mission mission = new()
{
Map = MapCore.InitializeMap(50, 1, 50)
};
mission.Map[20, 0, 20] = CoverType.FullCover;
mission.Map[18, 0, 18] = CoverType.HalfCover;
Team team1 = new Team(1)
Team team1 = new(1)
{
Name = "Good guys",
Characters = new List<Character>() { },
Characters = new() { },
Color = "Blue"
};
mission.Teams.Add(team1);
Character jethro = CharacterPool.CreateJethroBaddie(mission.Map, new Vector3(15, 0, 15));
Character jethro = CharacterPool.CreateJethroBaddie(mission.Map, new(15, 0, 15));
jethro.ActionPointsCurrent = 2;
Team team2 = new Team(0)
Team team2 = new(0)
{
Name = "Bad guys",
Characters = new List<Character>() { jethro },
Characters = new() { jethro },
Color = "Red"
};
mission.Teams.Add(team2);
Expand Down Expand Up @@ -89,17 +87,17 @@ public void CharacterJethroAIMovesIntoFullCoverNoOpponentsTest()
";
Assert.AreEqual(log1, actionResult1.LogString);
Assert.AreEqual(10, actionResult1.Score);
Assert.AreEqual(new Vector3(15, 0, 15), actionResult1.StartLocation);
Assert.AreEqual(new Vector3(20, 0, 21), actionResult1.EndLocation);
Assert.AreEqual(new(15, 0, 15), actionResult1.StartLocation);
Assert.AreEqual(new(20, 0, 21), actionResult1.EndLocation);
Assert.AreEqual(ActionTypeEnum.DoubleMove, actionResult1.ActionType);

string log2 = @"
Jethro is processing AI, with intelligence 25
Successful intelligence check: 25, (dice roll: 81)
";
Assert.AreEqual(log2, actionResult2.LogString);
Assert.AreEqual(new Vector3(15, 0, 15), actionResult2.StartLocation);
Assert.AreEqual(new Vector3(19, 0, 20), actionResult2.EndLocation);
Assert.AreEqual(new(15, 0, 15), actionResult2.StartLocation);
Assert.AreEqual(new(19, 0, 20), actionResult2.EndLocation);
Assert.AreEqual(ActionTypeEnum.DoubleMove, actionResult2.ActionType);
}

Expand All @@ -108,7 +106,7 @@ public void CharacterJethroAIMovesIntoFullCoverNoOpponentsTest()
public void CharacterJethroAIMovesIntoFullCoverWithOpponentTest()
{
//Arrange
Mission mission = new Mission
Mission mission = new()
{
Map = MapCore.InitializeMap(50, 1, 50)
};
Expand All @@ -123,19 +121,19 @@ public void CharacterJethroAIMovesIntoFullCoverWithOpponentTest()
mission.Map[14, 0, 12] = CoverType.FullCover;
mission.Map[14, 0, 13] = CoverType.FullCover;
mission.Map[14, 0, 14] = CoverType.FullCover;
Character fred = CharacterPool.CreateFredHero(mission.Map, new Vector3(5, 0, 5));
Team team1 = new Team(1)
Character fred = CharacterPool.CreateFredHero(mission.Map, new(5, 0, 5));
Team team1 = new(1)
{
Name = "Good guys",
Characters = new List<Character>() { fred }
Characters = new() { fred }
};
mission.Teams.Add(team1);
Character jethro = CharacterPool.CreateJethroBaddie(mission.Map, new Vector3(15, 0, 10));
Character jethro = CharacterPool.CreateJethroBaddie(mission.Map, new(15, 0, 10));
jethro.HitpointsCurrent = 5;
Team team2 = new Team(0)
Team team2 = new(0)
{
Name = "Bad guys",
Characters = new List<Character>() { jethro }
Characters = new() { jethro }
};
mission.Teams.Add(team2);
//Remove the 8, so that the 81 is primed and ready
Expand Down Expand Up @@ -181,8 +179,8 @@ public void CharacterJethroAIMovesIntoFullCoverWithOpponentTest()
Successful intelligence check: 25, (dice roll: 81)
";
Assert.AreEqual(log1, actionResult.LogString);
Assert.AreEqual(new Vector3(15, 0, 10), actionResult.StartLocation);
Assert.AreEqual(new Vector3(15, 0, 6), actionResult.EndLocation);
Assert.AreEqual(new(15, 0, 10), actionResult.StartLocation);
Assert.AreEqual(new(15, 0, 6), actionResult.EndLocation);
Assert.AreEqual(ActionTypeEnum.MoveThenAttack, actionResult.ActionType);
}

Expand Down
15 changes: 7 additions & 8 deletions src/Battle.Tests/Characters/CharacterActionTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Battle.Logic.Characters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
using System.Numerics;

namespace Battle.Tests.Characters
{
Expand All @@ -13,7 +12,7 @@ public class CharacterActionTests
public void StartOfTurnTest()
{
//Arrange
Character fred = CharacterPool.CreateFredHero(null, new Vector3(0, 0, 0));
Character fred = CharacterPool.CreateFredHero(null, new(0, 0, 0));
fred.TargetCharacters.Add("Bart");
fred.CoverState.InFullCover = true;

Expand All @@ -40,7 +39,7 @@ public void StartOfTurnTest()
public void NeedToReloadTest()
{
//Arrange
Character fred = CharacterPool.CreateFredHero(null, new Vector3(0, 0, 0));
Character fred = CharacterPool.CreateFredHero(null, new(0, 0, 0));
fred.WeaponEquipped.AmmoCurrent = 0;
fred.TargetCharacters.Add("Bart");
fred.CoverState.InFullCover = true;
Expand All @@ -66,7 +65,7 @@ public void NeedToReloadTest()
public void NoUtilityItemTest()
{
//Arrange
Character fred = CharacterPool.CreateFredHero(null, new Vector3(0, 0, 0));
Character fred = CharacterPool.CreateFredHero(null, new(0, 0, 0));
fred.UtilityWeaponEquipped = null;
fred.UtilityItemEquipped = null;
fred.TargetCharacters.Add("Bart");
Expand All @@ -91,7 +90,7 @@ public void NoUtilityItemTest()
public void MedKitConsumedTest()
{
//Arrange
Character fred = CharacterPool.CreateFredHero(null, new Vector3(0, 0, 0));
Character fred = CharacterPool.CreateFredHero(null, new(0, 0, 0));
fred.UtilityItemEquipped.ClipRemaining = 0;
fred.TargetCharacters.Add("Bart");
fred.CoverState.InFullCover = true;
Expand All @@ -117,7 +116,7 @@ public void MedKitConsumedTest()
public void NoActionsRemainingTest()
{
//Arrange
Character fred = CharacterPool.CreateFredHero(null, new Vector3(0, 0, 0));
Character fred = CharacterPool.CreateFredHero(null, new(0, 0, 0));
fred.ActionPointsCurrent = 0;

//Act
Expand All @@ -133,7 +132,7 @@ public void NoActionsRemainingTest()
public void NoTargetsTest()
{
//Arrange
Character fred = CharacterPool.CreateFredHero(null, new Vector3(0, 0, 0));
Character fred = CharacterPool.CreateFredHero(null, new(0, 0, 0));
fred.CoverState.InFullCover = true;

//Act
Expand All @@ -156,7 +155,7 @@ public void NoTargetsTest()
public void NoCoverTest()
{
//Arrange
Character fred = CharacterPool.CreateFredHero(null, new Vector3(0, 0, 0));
Character fred = CharacterPool.CreateFredHero(null, new(0, 0, 0));
fred.TargetCharacters.Add("Bart");

//Act
Expand Down
7 changes: 3 additions & 4 deletions src/Battle.Tests/Characters/CharacterEffectTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Battle.Logic.AbilitiesAndEffects;
using Battle.Logic.Characters;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Numerics;

namespace Battle.Tests.Characters
{
Expand All @@ -13,7 +12,7 @@ public class CharacterEffectTests
public void CharacterEffectDoesDamageTest()
{
//Arrange
Character fred = CharacterPool.CreateFredHero(null, new Vector3(0, 0, 0));
Character fred = CharacterPool.CreateFredHero(null, new(0, 0, 0));

//Act
fred.ProcessEffects(1);
Expand All @@ -26,7 +25,7 @@ public void CharacterEffectDoesDamageTest()
public void CharacterEffectExpiresDoesDamageTest()
{
//Arrange
Character fred = CharacterPool.CreateFredHero(null, new Vector3(0, 0, 0));
Character fred = CharacterPool.CreateFredHero(null, new(0, 0, 0));

//Act
fred.ProcessEffects(1);
Expand All @@ -41,7 +40,7 @@ public void CharacterEffectExpiresDoesDamageTest()
public void CharacterMultipleEffectExpiresDoesDamageTest()
{
//Arrange
Character fred = CharacterPool.CreateFredHero(null, new Vector3(0, 0, 0));
Character fred = CharacterPool.CreateFredHero(null, new(0, 0, 0));
fred.Effects.Add(new Effect()
{
Type = AbilityType.Unknown,
Expand Down
Loading

0 comments on commit 24b9b06

Please sign in to comment.