예제 #1
0
        private Cell currentDirLastCell()
        {
            Vector angleDir = Vector.sincos(car.Angle);

            TileDir[] dirsByPriority = null;

            if (Math.Abs(angleDir.X) > Math.Abs(angleDir.Y))
            {
                dirsByPriority = new TileDir[4] {
                    new TileDir(Math.Sign(angleDir.X), 0),
                    new TileDir(0, Math.Sign(angleDir.Y)),
                    new TileDir(0, -Math.Sign(angleDir.Y)),
                    new TileDir(-Math.Sign(angleDir.X), 0)
                };
            }
            else
            {
                dirsByPriority = new TileDir[4] {
                    new TileDir(0, Math.Sign(angleDir.Y)),
                    new TileDir(Math.Sign(angleDir.X), 0),
                    new TileDir(-Math.Sign(angleDir.X), 0),
                    new TileDir(0, -Math.Sign(angleDir.Y))
                };
            }

            Cell resultCell = new Cell();

            TilePos currentPos = new TilePos(car.X, car.Y);

            for (int i = 0; i < 4; i++)
            {
                if (gmap.Dirs(currentPos).Contains(dirsByPriority[i].Negative()))
                {
                    resultCell.DirOut = dirsByPriority[i];
                    break;
                }
            }

            resultCell.DirOuts = new TileDir[] { resultCell.DirOut };
            resultCell.Pos     = currentPos - resultCell.DirOut;

            for (int i = 3; i >= 0; i--)
            {
                if (gmap.Dirs(resultCell.Pos).Contains(dirsByPriority[i]))
                {
                    resultCell.DirIn = dirsByPriority[i].Negative();
                    break;
                }
            }

            return(resultCell);
        }
예제 #2
0
        public Cell FirstCellWithTransitions(int maxDepth)
        {
            TilePos currentCarTilePos = new TilePos(car.X, car.Y);

            if (null == lastCarTilePos || !lastCarTilePos.Equals(currentCarTilePos))
            {
                mapCache.Clear();
                lastCarTilePos = currentCarTilePos;
            }

            Cell result = new Cell(currentCarTilePos, gmap.Dirs(currentCarTilePos));

            fillCell(result, 0, maxDepth);

            HashSet <Cell> visited = new HashSet <Cell>();

            Logger.instance.Assert(MaxDepth(result, visited) >= 3, "Can't create full path (first cell with trasitions)");

            return(result);
        }