Skip to content

Commit

Permalink
fix routing stuff !!
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAIBot committed Jul 9, 2021
1 parent 4cbd3a6 commit 22191dc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
18 changes: 6 additions & 12 deletions ChiselDebug/ChiselDebug/Routing/ScorePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,16 @@ public ScorePath(int travled, MoveDirs fromDir)
this.Data = (uint)travled | ((uint)fromDir << 24);
}

public ScorePath Move(MoveDirs revDir, bool onEnemyWire, bool onFriendWire, bool onWireCorner, bool isTurningOnEnemyWire)
public ScorePath Move(MoveDirs revDir, bool onEnemyWire, bool moveToEnemyWire, bool moveToFriendWire, bool moveToWireCorner, bool isTurning)
{
//If the direction we are moving in is not the
//opposite of the direction we came from,
//then we must be turning unless we started
//the path from this point. If we didn't come
//from any direction then we must've started
//the path from here.
bool isTurning = DirFrom != revDir && DirFrom != MoveDirs.None;
int turns = TravelDist;
turns += isTurning ? 5 : 0;
turns += onEnemyWire ? 5 : 0;
turns += onWireCorner && onEnemyWire ? 500 : 0;
turns += isTurningOnEnemyWire ? 50 : 0;
turns += moveToEnemyWire ? 5 : 0;
turns += moveToEnemyWire && moveToWireCorner ? 500 : 0;
turns += isTurning && onEnemyWire ? 50 : 0;
turns += moveToFriendWire ? 0 : 1;

return new ScorePath(turns + (onFriendWire ? 0 : 1), revDir);
return new ScorePath(turns, revDir);
}

public bool IsBetterScoreThan(ScorePath score)
Expand Down
11 changes: 6 additions & 5 deletions ChiselDebug/ChiselDebug/Routing/SimpleRouter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,6 @@ private WirePath PathLine(RouterBoard board, IOInfo start, IOInfo end, Rectangle
}

bool onEnemyWire = allowedMoves.HasFlag(MoveDirs.EnemyWire);
bool onFriendWire = allowedMoves.HasFlag(MoveDirs.FriendWire);
bool onWireCorner = allowedMoves.HasFlag(MoveDirs.WireCorner);
for (int i = 0; i < moves.Length; i++)
{
if (allowedMoves.HasFlag(moves[i].Dir))
Expand All @@ -240,10 +238,13 @@ private WirePath PathLine(RouterBoard board, IOInfo start, IOInfo end, Rectangle
int neighbordIndex = board.CellIndex(neighborPos);
ref ScorePath neighborScore = ref board.GetCellScorePath(neighbordIndex);

//Penalty for turning while on another wire
bool isTurningOnEnemyWire = onEnemyWire && currentScorePath.DirFrom != MoveDirs.None && moves[i].Dir != currentScorePath.DirFrom.Reverse();
MoveDirs neighborMoves = board.GetCellMoves(neighbordIndex);
bool moveToEnemyWire = neighborMoves.HasFlag(MoveDirs.EnemyWire);
bool moveToFriendWire = neighborMoves.HasFlag(MoveDirs.FriendWire);
bool moveToWireCorner = neighborMoves.HasFlag(MoveDirs.WireCorner);
bool isTurning = currentScorePath.DirFrom != MoveDirs.None && moves[i].RevDir != currentScorePath.DirFrom;

ScorePath neighborScoreFromCurrent = currentScorePath.Move(moves[i].RevDir, onEnemyWire, onFriendWire, onWireCorner, isTurningOnEnemyWire);
ScorePath neighborScoreFromCurrent = currentScorePath.Move(moves[i].RevDir, onEnemyWire, moveToEnemyWire, moveToFriendWire, moveToWireCorner, isTurning);
if (neighborScoreFromCurrent.IsBetterScoreThan(neighborScore))
{
Point diff = (neighborPos - relativeStart).Abs();
Expand Down

0 comments on commit 22191dc

Please sign in to comment.