Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
kalina559 committed Jul 20, 2024
1 parent c600dff commit 836aa21
Showing 4 changed files with 12 additions and 13 deletions.
5 changes: 3 additions & 2 deletions Battleships.AI/Strategies/Heuristics/HitHeuristicStrategy.cs
Original file line number Diff line number Diff line change
@@ -8,8 +8,9 @@ namespace Battleships.AI.Strategies.Heuristics
/// </summary>
public class HitHeuristicStrategy : HeuristicStrategyBase
{
private readonly static int NEXT_TO_A_SINGLE_HIT_WEIGHT = 50;
private readonly static int IN_LINE_WITH_OTHER_HITS_WEIGHT = 100;
private readonly static int
NEXT_TO_A_SINGLE_HIT_WEIGHT = 50,
IN_LINE_WITH_OTHER_HITS_WEIGHT = 100;

public override int[] GenerateProbabilityMap(List<Shot> previousShots, List<Ship> opponentShips, bool shipsCanTouch)
{
Original file line number Diff line number Diff line change
@@ -10,9 +10,10 @@ namespace Battleships.AI.Strategies.Heuristics
/// </summary>
public class LocationAndHitHeuristicDynamicStrategy : HeuristicStrategyBase
{
private readonly static int POSSIBLE_SHIP_LOCATION_WEIGHT = 1;
private readonly static int NEXT_TO_A_SINGLE_HIT_WEIGHT = 50;
private readonly static int IN_LINE_WITH_OTHER_HITS_WEIGHT = 100;
private readonly static int
POSSIBLE_SHIP_LOCATION_WEIGHT = 1,
NEXT_TO_A_SINGLE_HIT_WEIGHT = 50,
IN_LINE_WITH_OTHER_HITS_WEIGHT = 100;

public override int[] GenerateProbabilityMap(List<Shot> previousShots, List<Ship> opponentShips, bool shipsCanTouch)
{
Original file line number Diff line number Diff line change
@@ -9,9 +9,10 @@ namespace Battleships.AI.Strategies.Heuristics
/// </summary>
public class LocationAndHitHeuristicStrategy : HeuristicStrategyBase
{
private readonly static int POSSIBLE_SHIP_LOCATION_WEIGHT = 1;
private readonly static int NEXT_TO_A_SINGLE_HIT_WEIGHT = 50;
private readonly static int IN_LINE_WITH_OTHER_HITS_WEIGHT = 100;
private readonly static int
POSSIBLE_SHIP_LOCATION_WEIGHT = 1,
NEXT_TO_A_SINGLE_HIT_WEIGHT = 50,
IN_LINE_WITH_OTHER_HITS_WEIGHT = 100;

public override int[] GenerateProbabilityMap(List<Shot> previousShots, List<Ship> opponentShips, bool shipsCanTouch)
{
6 changes: 1 addition & 5 deletions Battleships.Core/Services/GameStateService.cs
Original file line number Diff line number Diff line change
@@ -95,6 +95,7 @@ private void SaveGameSessionToDb(GameState gameState, bool playerWon, bool testM
GameStateJson = JsonConvert.SerializeObject(gameState),
SessionId = httpContextAccessor.HttpContext.Request.Headers["X-Session-Id"].ToString(),
DateCreated = DateTime.UtcNow,
PlayerAiType = (int?)gameState.PlayerAiType,
OpponentAiType = (int)gameState.OpponentAiType,
ShipsCanTouch = gameState.ShipsCanTouch,
OpponentShipsSunk = gameState.OpponentShips.Where(x => x.IsSunk).Count(),
@@ -104,11 +105,6 @@ private void SaveGameSessionToDb(GameState gameState, bool playerWon, bool testM
PlayerWon = playerWon
};

if (testMode)
{
gameSession.PlayerAiType = (int?)gameState.PlayerAiType;
}

cosmosDbService.AddGameSessionAsync(gameSession, testMode);
}
}

0 comments on commit 836aa21

Please sign in to comment.