Skip to content

Commit 0f626ed

Browse files
committed
Убраны лишние инстанцирования состояния в случае моей смерти
1 parent 73a7f74 commit 0f626ed

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

MiniAiCup.Paperio.Core/BestTrajectoryFinder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public GameStateInternal FindBestState(GameStateInternal initialState)
4242
foreach (var move in EnumValues.GetAll<Move>())
4343
{
4444
var nextState = _simulator.Simulate(currentState, currentDepth, move);
45-
if (nextState.Me == null)
45+
if (nextState == null)
4646
{
4747
continue;
4848
}

MiniAiCup.Paperio.Core/SimpleGameSimulator.cs

+4-6
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public GameStateInternal Simulate(GameStateInternal state, int currentDepth, Mov
3232
if (!Game.Params.MapLogicSize.ContainsPoint(me.Position) || // Выехал за пределы карты
3333
me.Tail.Contains(me.Position)) // Наехал сам себе на хвост
3434
{
35-
return GetDeadState();
35+
return null;
3636
}
3737

3838
var enemies = (PlayerInternal[])state.Enemies.Clone();
@@ -44,7 +44,7 @@ public GameStateInternal Simulate(GameStateInternal state, int currentDepth, Mov
4444
if (enemies.Any(enemy => (enemy.DistanceMap[state.Me.Position.X, state.Me.Position.Y] <= currentDepth + 1 ||
4545
enemy.DistanceMap[me.Position.X, me.Position.Y] <= currentDepth + 1) && enemy.Tail.Length <= me.Tail.Length)) // Лобовое столкновение с противником с меньшим хвостом
4646
{
47-
return GetDeadState();
47+
return null;
4848
}
4949

5050
var capturedTerritory = _territoryCapturer.Capture(me.Territory, me.Tail);
@@ -72,11 +72,11 @@ public GameStateInternal Simulate(GameStateInternal state, int currentDepth, Mov
7272
me.Tail = me.Tail.Append(me.Position);
7373
if (me.PathToHome == null) // Зашел в тупик
7474
{
75-
return GetDeadState();
75+
return null;
7676
}
7777
if (me.Tail.Any(p => state.DangerousMap[p.X, p.Y] <= currentDepth + me.PathToHome.Length)) // Потенциально могут наехать на мой хвост
7878
{
79-
return GetDeadState();
79+
return null;
8080
}
8181
}
8282

@@ -96,8 +96,6 @@ public GameStateInternal Simulate(GameStateInternal state, int currentDepth, Mov
9696
enemies = hasLosers ? enemies.Where(e => e != null).ToArray() : enemies;
9797

9898
return new GameStateInternal(nextTickNumber, me, enemies, nextBonuses, state, hasLosers ? null : state.DangerousMap);
99-
100-
GameStateInternal GetDeadState() => new GameStateInternal(nextTickNumber, null, state.Enemies, state.Bonuses, state, state.DangerousMap);
10199
}
102100
}
103101
}

0 commit comments

Comments
 (0)