Example #1
0
 public MoveData(MoveDirs dir)
 {
     this.Dir       = dir;
     this.RevDir    = dir.Reverse();
     this.DirVec    = Dir.MovePoint(Point.Zero);
     this.RevDirVec = RevDir.MovePoint(Point.Zero);
 }
Example #2
0
        private WirePath PathLine(RouterBoard board, IOInfo start, IOInfo end, Rectangle?startRect, Rectangle?endRect, List <WirePath> allPaths)
        {
            board.ReloadCheckpoint();

            Point relativeStart = board.GetRelativeBoardPos(start.DirIO.Position);
            Point relativeEnd   = board.GetRelativeBoardPos(end.DirIO.Position);

            //Start position may lie inside the component rectangle
            //and therefore the is no way to reach it.
            //This here makes a straight path out of the component
            //so it's possible to find a path.
            if (endRect.HasValue)
            {
                Rectangle endRectRelative = board.GetRelativeBoard(endRect.Value);
                Point     endGo           = relativeEnd;
                MoveDirs  allowedDir      = end.DirIO.InitialDir.Reverse();
                do
                {
                    board.SetCellAllowedMoves(endGo, allowedDir);
                    endGo = allowedDir.MovePoint(endGo);
                } while (endRectRelative.Within(endGo));
            }
            else
            {
                board.SetCellAllowedMoves(relativeEnd, end.DirIO.InitialDir.Reverse());
            }

            if (startRect.HasValue)
            {
                Rectangle startRectRelative = board.GetRelativeBoard(startRect.Value);
                Point     startGo           = relativeStart;
                MoveDirs  allowedDir        = start.DirIO.InitialDir.Reverse();
                do
                {
                    board.SetCellAllowedMoves(startGo, allowedDir);
                    startGo = allowedDir.Reverse().MovePoint(startGo);
                } while (startRectRelative.Within(startGo));
            }

            foreach (var path in allPaths)
            {
                MoveDirs wireType;
                if (path.StartIO.DirIO.Position == start.DirIO.Position ||
                    path.EndIO.DirIO.Position == end.DirIO.Position)
                {
                    wireType = MoveDirs.FriendWire;
                }
                else
                {
                    wireType = MoveDirs.EnemyWire;
                }

                path.PlaceOnBoard(board, wireType);
            }

            ref ScorePath startScore = ref board.GetCellScorePath(relativeEnd);