Skip to content

Commit

Permalink
Another fear fix №2
Browse files Browse the repository at this point in the history
  • Loading branch information
madddmax committed Aug 11, 2019
1 parent f30c0a9 commit cb77ef1
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions Domain/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ public static Player GetNext(Player my, string direction, int depth)
{
foreach (var l in myNext.Lines)
{
int moves = Math.Abs(l.X - e.Position.X) / World.Width + Math.Abs(l.Y - e.Position.Y) / World.Width;
moves -= DirectionExtension.IsOpposite(e.Direction, myNext.Direction) ? 1 : 0;
if (moves <= depth)
int moves = GetMoves(e.Position, e.Direction, l);
if (moves <= depth + 1)
{
// страх пересечения шлейфа
myNext.Score -= 500;
Expand All @@ -130,9 +129,8 @@ public static Player GetNext(Player my, string direction, int depth)

if (!onMyTerritory)
{
int moves = Math.Abs(myNext.Position.X - e.Position.X) / World.Width + Math.Abs(myNext.Position.Y - e.Position.Y) / World.Width;
moves -= DirectionExtension.IsOpposite(e.Direction, myNext.Direction) ? 1 : 0;
if (moves <= depth)
int moves = GetMoves(e.Position, e.Direction, myNext.Position);
if (moves <= depth + 1)
{
// страх столкновения с головой
myNext.Score -= 500;
Expand Down Expand Up @@ -204,6 +202,25 @@ public static Player GetNext(Player my, string direction, int depth)
}

myNext.Score += captureScore;

foreach (var bonus in Bonuses)
{
if (bonus.Position.Equals(p))
{
if (bonus.Type == Bonus.Nitro)
{
myNext.Score += 10;
}
else if (bonus.Type == Bonus.Slow)
{
myNext.Score -= 10;
}
else if (bonus.Type == Bonus.Saw)
{
myNext.Score += 25;
}
}
}
}

myNext.Lines = new HashSet<Point>();
Expand All @@ -212,5 +229,38 @@ public static Player GetNext(Player my, string direction, int depth)

return myNext;
}

public static int GetMoves(Point start, string direction, Point end)
{
int moves = 0;
int deltaX = end.X - start.X;
int deltaY = end.Y - start.Y;

// движение направо
if (deltaX > 0)
{
moves += direction == Direction.Left ? deltaX / World.Width + 1 : deltaX / World.Width;
}

// движение налево
if (deltaX < 0)
{
moves += direction == Direction.Right ? -deltaX / World.Width + 1 : -deltaX / World.Width;
}

// движение вверх
if (deltaY > 0)
{
moves += direction == Direction.Down ? deltaY / World.Width + 1 : deltaY / World.Width;
}

// движение вниз
if (deltaY < 0)
{
moves += direction == Direction.Up ? -deltaY / World.Width + 1 : -deltaY / World.Width;
}

return moves;
}
}
}

0 comments on commit cb77ef1

Please sign in to comment.