Skip to content

Commit

Permalink
Добавлен учет бонусов
Browse files Browse the repository at this point in the history
  • Loading branch information
voidmain02 committed Aug 16, 2019
1 parent d2960d4 commit 2f55f08
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 4 deletions.
4 changes: 4 additions & 0 deletions MiniAiCup.Paperio.Core/GameParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ public static class GameParams
public const int NitroSpeed = 6;

public const int SlowDownSpeed = 3;

public const int MinBonusDuration = 10;

public const int MaxBonusDuration = 50;
}
}
43 changes: 40 additions & 3 deletions MiniAiCup.Paperio.Core/GameStateScorer.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
using System.Collections.Generic;
using System;
using MiniAiCup.Paperio.Core.Debug;

namespace MiniAiCup.Paperio.Core
{
public class GameStateScorer
{
private const int SlowdownInScores = -30;

private const int NitroInScores = 10;

private readonly BfsTerritoryCapturer _territoryCapturer;

public GameStateScorer(BfsTerritoryCapturer territoryCapturer)
Expand Down Expand Up @@ -56,8 +60,13 @@ public int Score(GameStateInternal state)

int potentialScore = CalcPotentialTerritoryCaptureScore(state);
int potentialScoreBonus = (int)(potentialScore*0.9);
int bonusScore = state.Me.NitroStepsLeft > state.Me.SlowdownStepsLeft
? NitroInScores
: state.Me.SlowdownStepsLeft > state.Me.NitroStepsLeft
? SlowdownInScores
: 0;

return (state.Me.Score + potentialScoreBonus)*scoresMultiplicator;
return (state.Me.Score + potentialScoreBonus + bonusScore)*scoresMultiplicator;
}

public int CalcPotentialTerritoryCaptureScore(GameStateInternal state)
Expand Down Expand Up @@ -95,7 +104,35 @@ public int CalcPotentialTerritoryCaptureScore(GameStateInternal state)
}
score += enemyTerritoryPoints*(Constants.EnemyTerritoryScore - Constants.NeutralTerritoryScore);

return score;
int nitroCount = 0;
int slowdownCount = 0;
foreach (var bonus in state.Bonuses)
{
if (capturedTerritory.Contains(bonus.Position))
{
switch (bonus.Type)
{
case BonusType.Nitro:
nitroCount++;
break;
case BonusType.Slowdown:
slowdownCount++;
break;
case BonusType.Saw:
break;
default:
throw new ArgumentOutOfRangeException();
}
}
}

int bonusScore = nitroCount > slowdownCount
? NitroInScores
: slowdownCount > nitroCount
? SlowdownInScores
: 0;

return score + bonusScore;
}
}
}
63 changes: 62 additions & 1 deletion MiniAiCup.Paperio.Core/SimpleGameSimulator.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using MiniAiCup.Paperio.Core.Debug;

Expand All @@ -20,7 +21,6 @@ public GameStateInternal Simulate(GameStateInternal state, int simulationTicks,

int timeToNextPos = GameParams.CellSize/state.Me.GetSpeed(0);
int nextTickNumber = state.TickNumber + timeToNextPos;
var nextBonuses = state.Bonuses;

var me = (PlayerInternal)state.Me.Clone();
if (me.NitroStepsLeft > 0)
Expand All @@ -45,6 +45,31 @@ public GameStateInternal Simulate(GameStateInternal state, int simulationTicks,
return null;
}

var nextBonuses = state.Bonuses;
foreach (var bonus in state.Bonuses)
{
if (bonus.Position == me.Position)
{
switch (bonus.Type)
{
case BonusType.Nitro:
me.NitroStepsLeft += GameParams.MinBonusDuration;
break;
case BonusType.Slowdown:
me.SlowdownStepsLeft += GameParams.MaxBonusDuration;
break;
case BonusType.Saw:
break;
default:
throw new ArgumentOutOfRangeException();
}

nextBonuses = state.Bonuses.Where(b => b != bonus).ToArray();

break;
}
}

var enemies = (PlayerInternal[])state.Enemies.Clone();

if (me.Territory.Contains(me.Position))
Expand Down Expand Up @@ -78,6 +103,42 @@ public GameStateInternal Simulate(GameStateInternal state, int simulationTicks,
me.Score += (srcCount - croppedCount)*(Constants.EnemyTerritoryScore - Constants.NeutralTerritoryScore);
}
}

bool gotBonus = false;
for (int i = 0; i < nextBonuses.Length; i++)
{
var bonus = nextBonuses[i];
if (capturedTerritory.Contains(bonus.Position))
{
switch (bonus.Type)
{
case BonusType.Nitro:
me.NitroStepsLeft += GameParams.MinBonusDuration;
break;
case BonusType.Slowdown:
me.SlowdownStepsLeft += GameParams.MaxBonusDuration;
break;
case BonusType.Saw:
break;
default:
throw new ArgumentOutOfRangeException();
}

gotBonus = true;

if (nextBonuses == state.Bonuses)
{
nextBonuses = (BonusInfo[])state.Bonuses.Clone();
}

nextBonuses[i] = null;
}
}

if (gotBonus)
{
nextBonuses = nextBonuses.Where(b => b != null).ToArray();
}
}
}
else
Expand Down

0 comments on commit 2f55f08

Please sign in to comment.