Пример #1
0
        internal WirePath GetPath(Point start, Point end, IOInfo startIO, IOInfo endIO, bool pathToWire)
        {
            List <Point> pathAsTurns   = new List <Point>();
            List <int>   allBoardPoses = new List <int>();
            List <int>   boardPosTurns = new List <int>();

            MoveDirs prevDir   = MoveDirs.None;
            Point    boardPos  = end;
            Point    actualPos = end * CellSize;

            while (boardPos != start)
            {
                allBoardPoses.Add(CellIndex(boardPos));

                ScorePath path = GetCellScorePath(boardPos);
                if (path.DirFrom != prevDir)
                {
                    pathAsTurns.Add(actualPos);
                    if (prevDir != MoveDirs.None)
                    {
                        boardPosTurns.Add(CellIndex(boardPos));
                    }
                }
                prevDir   = path.DirFrom;
                boardPos  = path.DirFrom.MovePoint(boardPos);
                actualPos = actualPos + path.DirFrom.MovePoint(Point.Zero) * CellSize;
            }

            allBoardPoses.Add(CellIndex(start));
            pathAsTurns.Add(actualPos);
            pathAsTurns.Reverse();
            boardPosTurns.Reverse();

            return(new WirePath(startIO, endIO, pathAsTurns, allBoardPoses, boardPosTurns, pathToWire));
        }
Пример #2
0
        internal string BoardStateToString(Point start, Point end)
        {
            StringBuilder sBuilder = new StringBuilder();

            for (int y = 0; y < CellsHigh; y++)
            {
                for (int x = 0; x < CellsWide; x++)
                {
                    Point     pos         = new Point(x, y);
                    ScorePath scorePath   = GetCellScorePath(pos);
                    MoveDirs  allowedDirs = GetCellMoves(pos);
                    if (pos == start)
                    {
                        sBuilder.Append('S');
                    }
                    else if (pos == end)
                    {
                        sBuilder.Append('E');
                    }
                    else if (allowedDirs.HasFlag(MoveDirs.FriendWire))
                    {
                        sBuilder.Append('%');
                    }
                    else if (scorePath.DirFrom == MoveDirs.Up)
                    {
                        sBuilder.Append("↑");
                    }
                    else if (scorePath.DirFrom == MoveDirs.Down)
                    {
                        sBuilder.Append("↓");
                    }
                    else if (scorePath.DirFrom == MoveDirs.Left)
                    {
                        sBuilder.Append("←");
                    }
                    else if (scorePath.DirFrom == MoveDirs.Right)
                    {
                        sBuilder.Append("→");
                    }
                    else if (scorePath.DirFrom == MoveDirs.None)
                    {
                        sBuilder.Append(' ');
                    }
                }
                sBuilder.AppendLine();
            }

            return(sBuilder.ToString());
        }
Пример #3
0
        internal void PrepareBoard(List <Rectangle> usedSpace)
        {
            //Start with all moves are legal
            MoveDirs allDirs = MoveDirs.All;

            Array.Fill(CellAllowedDirs, allDirs);
            Array.Fill(CellScoreAndPath, ScorePath.NotReachedYet());

            //Moves that go outside the board are not allowed
            for (int x = 0; x < CellsWide; x++)
            {
                CellAllowedDirs[CellIndex(x, 0)]             &= MoveDirs.None;
                CellAllowedDirs[CellIndex(x, CellsHigh - 1)] &= MoveDirs.None;
            }
            for (int y = 0; y < CellsHigh; y++)
            {
                CellAllowedDirs[CellIndex(0, y)]             &= MoveDirs.None;
                CellAllowedDirs[CellIndex(CellsWide - 1, y)] &= MoveDirs.None;
            }

            //Moves that go into used space are not allowed.
            //Moves inside used space are not removed because
            //they shouldn't be reachable.
            for (int i = 0; i < usedSpace.Count; i++)
            {
                Rectangle spaceRel = GetRelativeBoard(usedSpace[i]);
                for (int x = spaceRel.LeftX + 1; x < spaceRel.RightX; x++)
                {
                    CellAllowedDirs[CellIndex(x, spaceRel.TopY)]    &= MoveDirs.ExceptDown;
                    CellAllowedDirs[CellIndex(x, spaceRel.BottomY)] &= MoveDirs.ExceptUp;
                }
                for (int y = spaceRel.TopY + 1; y < spaceRel.BottomY; y++)
                {
                    CellAllowedDirs[CellIndex(spaceRel.LeftX, y)]  &= MoveDirs.ExceptRight;
                    CellAllowedDirs[CellIndex(spaceRel.RightX, y)] &= MoveDirs.ExceptLeft;
                }
            }
        }