static WallPosition[] Fillpoints(Wall[] walls, WallPosition[] points) { int pointCount = 0; for (int j = 0; j < walls.Length; j++) { for (int i = 0; i < walls[j].length; i++) { points[pointCount] = new WallPosition(); if (walls[j].dir == 0) { int x = walls[j].startx + i; int y = walls[j].starty; points[pointCount].SetInfo(x, y); } if (walls[j].dir == 1) { int x = walls[j].startx; int y = walls[j].starty + i; points[pointCount].SetInfo(x, y); } pointCount++; } } return(points); }
//function spawns individual enemies one by one. (This Method is not used, and is held for reference). void SpawnTilFull() { Transform freePosition = NextFreePosition(); if (freePosition) { if (Random.Range(0, 1f) < 0.7f) { Debug.Log("WallPrefab is spawning"); GameObject wall = Instantiate(wallPrefab, freePosition.position, Quaternion.identity) as GameObject; wall.transform.parent = freePosition; } else { Debug.Log("The wallPrefab should not spawn"); GameObject wall = Instantiate(emptySpace, freePosition.position, Quaternion.identity) as GameObject; wall.transform.parent = freePosition; WallPosition position = freePosition.GetComponent <WallPosition>(); position.ClearEmptyWalls(); } } if (NextFreePosition()) { Invoke("SpawnTilFull", spawnDelay); } }
/// <summary> /// Travel from one visited square to a neighbor square (through an open wall). /// </summary> /// <param name="sq1">first (previously visited) square</param> /// <param name="sq2">next (neighbor) square</param> /// <param name="forward">true if the neighbor square was not visited previously</param> protected override void StepI(out MazeSquare sq1, out MazeSquare sq2, out bool forward) { if (maze.IsSolved) { throw new Exception("Maze is already solved."); } // Get the current square. sq1 = stack.Peek(); // Possible choices of open walls (not visited). List <WallPosition> openWalls = OpenWalls(sq1, true); if (openWalls.Count > 0) { // Select one of the neighbor squares. WallPosition wp = SelectDirection(sq1, openWalls); sq2 = sq1.NeighborSquare(wp); forward = true; // Push the next square onto the stack. stack.Push(sq2); sq2.isVisited = true; } else { // Pop the current square from the stack. stack.Pop(); sq2 = stack.Peek(); forward = false; } }
void OnTriggerEnter(Collider collider) //При входе в триггер { Fruit fruit = collider.gameObject.GetComponent <Fruit>(); //Получаем компонент Fruit объекта Segment seg = collider.gameObject.GetComponent <Segment>(); //Получаем компонент Segment объекта WallPosition wall = collider.gameObject.GetComponent <WallPosition>(); //Получаем компонент WallPosition объекта if ((fruit != null) && (time >= epsilon)) //Если компонент Fruit существует и прошло достаточно времени { time = 0; //Обнуляем счётчик fruit.MakeEaten(); //Съедаем фрукт _grow = true; //Оставляем сигнал о том, что нужно вырасти return; //Прерываем } if (seg != null) //Если компонент Segment существует { if (Mathf.Abs(Number - seg.Number) > 1) //Если сегменты не соседи { _end = true; //Конец } } if (wall != null) //Если компонент WallPosition существует { _end = true; //Конец } }
public Wall(double x, double y, double length, WallPosition position) { X = x; Y = y; Length = length; WallPosition = position; }
public void DestroyWall(MazeSlot other) { WallPosition position = WallPosition.None; if (X > other.X) { position = WallPosition.Left; } else if (X < other.X) { position = WallPosition.Rigth; } else if (Y > other.Y) { position = WallPosition.Down; } else if (Y < other.Y) { position = WallPosition.Up; } if (position != WallPosition.None) { DestroyedWalls.Add(position); } }
/// <summary> /// Returns a list of directions leading from the given square to neighbors through open walls. /// Neighbors that have been identified as dead ends are excluded (efficient solvers only). /// </summary> /// <param name="sq"></param> /// <param name="notVisitedOnly"> /// When true: Exclude neighbors that have already been visited. /// </param> /// <returns></returns> protected List <WallPosition> OpenWalls(MazeSquare sq, bool notVisitedOnly) { List <WallPosition> result = new List <WallPosition>((int)WallPosition.WP_NUM); for (WallPosition wp = WallPosition.WP_MIN; wp <= WallPosition.WP_MAX; wp++) { if (sq[wp] == WallState.WS_OPEN) { MazeSquare sq2 = sq.NeighborSquare(wp); if (notVisitedOnly) { // Exclude squares that have already been visited. if (sq2.isVisited) { continue; } } // Exclude squares that need not be visited because they are dead ends. if (this.deadEndChecker != null && deadEndChecker.IsDead(sq2)) { continue; } result.Add(wp); } } return(result); }
// -------------------------------------------------------------------------------- // Constructors // By default, any wall can be opened up to an adjacent cell. public Wall(Cell parentCell, WallPosition position) { this.IsClosed = true; this.CanBeOpened = true; this.ParentCell = parentCell; this.Position = position; }
public void ShouldSetCorrectWallOnDestroyWall(int anotherX, int anotherY, WallPosition expectedPosition) { MazeSlot slot = new MazeSlot(1, 1); MazeSlot anotherSlot = new MazeSlot(anotherX, anotherY); slot.DestroyWall(anotherSlot); Assert.Single(slot.DestroyedWalls); Assert.Contains(expectedPosition, slot.DestroyedWalls); }
public override bool[] PreferredDirections(MazeSquare sq) { bool[] result = new bool[4]; for (WallPosition wp = WallPosition.WP_MIN; wp <= WallPosition.WP_MAX; wp++) { result[(int)wp] = (sq.walls[(int)MazeSquare.OppositeWall(wp)] != WallState.WS_OPEN); } return(result); }
/// <summary> /// Constructor. /// </summary> public MazeSquare(int xPos, int yPos) { this.xPos = xPos; this.yPos = yPos; this.mazeId = PrimaryMazeId; for (WallPosition wp = WallPosition.WP_MIN; wp <= WallPosition.WP_MAX; wp++) { this.walls[(int)wp] = WallState.WS_MAYBE; } }
/// <summary> /// Turn the currentDirection one quarter to the right (clockwise) /// </summary> protected void TurnRight() { if (currentDirection == WallPosition.WP_MIN) { currentDirection = WallPosition.WP_MAX; } else { --currentDirection; } }
/// <summary> /// Turn the currentDirection one quarter to the left (counterclockwise) /// </summary> protected void TurnLeft() { if (currentDirection == WallPosition.WP_MAX) { currentDirection = WallPosition.WP_MIN; } else { ++currentDirection; } }
public void BuildWallArray() { for (int i = 0; i < CameraBoundaries.x; i++) { wallPositions.Add(new List <WallPosition>()); for (int j = 0; j < CameraBoundaries.y; j++) { WallPosition temp = Instantiate(wallPosition, new Vector2(i, j), Quaternion.identity, transform); wallPositions[i].Add(temp); wallPositions[i][j].SetPosition(new Vector2(i, j)); } } }
public void ShouldReturnCorrectNeighbors(int x, int y, WallPosition expectedWall) { MazeSlot[,] maze = BuildMaze(3, 3); MazeSolver solver = new MazeSolver(maze); MazeSlot slot = new MazeSlot(1, 1); slot.DestroyWall(maze[x, y]); List <MazeSlot> moves = solver.NextMoves(slot); Assert.Single(moves); Assert.Contains(expectedWall, slot.DestroyedWalls); }
private static int CountClosedWalls(MazeSquare sq) { int result = 0; for (WallPosition wp = WallPosition.WP_MIN; wp <= WallPosition.WP_MAX; wp++) { if (sq.walls[(int)wp] == WallState.WS_CLOSED) { ++result; } } return(result); }
private static void DrawHorizontal(MazeSlot[,] maze, int y, int x, WallPosition wall) { string[] corners = wall == WallPosition.Up ? TOP_CORNERS : BOTTON_CORNERS; if (!maze[x, y].DestroyedWalls.Contains(wall)) { if (!maze[x, y].DestroyedWalls.Contains(WallPosition.Left)) { Console.Write(corners[0]); } else { Console.Write("═"); } Console.Write("═══"); if (!maze[x, y].DestroyedWalls.Contains(WallPosition.Rigth)) { Console.Write(corners[1]); } else { Console.Write("═"); } } else { if (!maze[x, y].DestroyedWalls.Contains(WallPosition.Left)) { Console.Write("║"); } else { Console.Write(corners[2]); } Console.Write(" "); if (!maze[x, y].DestroyedWalls.Contains(WallPosition.Rigth)) { Console.Write("║"); } else { Console.Write(corners[3]); } } }
/// <summary> /// Returns the WallPosition on the opposite side of a square. /// </summary> /// <param name="p"></param> /// <returns></returns> public static WallPosition OppositeWall(WallPosition p) { switch (p) { case WallPosition.WP_E: return(WallPosition.WP_W); case WallPosition.WP_N: return(WallPosition.WP_S); case WallPosition.WP_W: return(WallPosition.WP_E); case WallPosition.WP_S: return(WallPosition.WP_N); default: throw new ArgumentOutOfRangeException("p"); } }
public static void GetCamPositionRotationForWall(WallPosition wallPosition, float offset, float fov, ref Vector3 position, ref Quaternion rotation) { float f = fov * 0.5f; float angle = 180.0f - (f + 90.0f); float sinAngle = Mathf.Sin(Mathf.Deg2Rad * angle); float upOverSinF = (LevelController.Instance.worldSettings.worldExtent * 2.0f + 1) / Mathf.Sin(Mathf.Deg2Rad * f); float length = sinAngle * upOverSinF; Assert.IsTrue(Mathf.Approximately(upOverSinF, (length / sinAngle))); float p = length; switch (wallPosition) { case WallPosition.Front: position = new Vector3(0.0f, 0.0f, p); rotation = Quaternion.Euler(0.0f, 180.0f, 0.0f); break; case WallPosition.Back: position = new Vector3(0.0f, 0.0f, -p); rotation = Quaternion.Euler(0.0f, 0.0f, 0.0f); break; case WallPosition.Up: position = new Vector3(0.0f, p, 0.0f); rotation = Quaternion.Euler(90.0f, 0.0f, 0.0f); break; case WallPosition.Down: position = new Vector3(0.0f, -p, 0.0f); rotation = Quaternion.Euler(-90.0f, 0.0f, 0.0f); break; case WallPosition.Left: position = new Vector3(-p, 0.0f, 0.0f); rotation = Quaternion.Euler(0.0f, 90.0f, 0.0f); break; case WallPosition.Right: position = new Vector3(p, 0.0f, 0.0f); rotation = Quaternion.Euler(0.0f, -90.0f, 0.0f); break; } }
/// <summary> /// Travel from one visited square to a neighbor square (through an open wall). /// </summary> /// <param name="sq1">first (previously visited) square</param> /// <param name="sq2">next (neighbor) square</param> /// <param name="forward">true if the neighbor square was not visited previously</param> protected override void StepI(out MazeSquare sq1, out MazeSquare sq2, out bool forward) { if (maze.IsSolved) { throw new Exception("Maze is already solved."); } List <WallPosition> openWalls; while (true) { // Get a current square but leave it in the queue. int p = SelectPathIdx(); sq1 = list[p]; // Possible choices of open walls (not visited). openWalls = OpenWalls(sq1, true); if (openWalls.Count == 0) { list.RemoveAt(p); MarkDeadBranch(sq1); } else { // If this was the last open wall of sq1, it can be removed from the list. if (openWalls.Count == 1) { list.RemoveAt(p); } break; } } // Select one (any) of the neighbor squares. WallPosition wp = SelectDirection(sq1, openWalls); sq2 = sq1.NeighborSquare(wp); forward = true; // Add the next square to the list. list.Add(sq2); sq2.isVisited = true; }
private static void TestDecodeIdentity(string testObject, int version) { SWA_Ariadne_Model_MazeDimensionsAccessor dimensionsObj = SWA_Ariadne_Model_MazeDimensionsAccessor.Instance(version); SWA_Ariadne_Model_MazeCodeAccessor codeObj = SWA_Ariadne_Model_MazeCodeAccessor.Instance(version); Random r = new Random(); for (int nTests = 0; nTests < 100; nTests++) { int xSize = r.Next(dimensionsObj.MinSize, dimensionsObj.MaxXSize + 1); int ySize = r.Next(dimensionsObj.MinSize, dimensionsObj.MaxYSize + 1); Maze maze = new Maze(xSize, ySize, version); maze.CreateMaze(); SWA_Ariadne_Model_MazeAccessor accessor = new SWA_Ariadne_Model_MazeAccessor(maze); int seed = accessor.seed; WallPosition direction = accessor.direction; int xStart = accessor.xStart; int yStart = accessor.yStart; int xEnd = accessor.xEnd; int yEnd = accessor.yEnd; string code = maze.Code; int seedActual, xSizeActual, ySizeActual; codeObj.Decode(code , out seedActual , out xSizeActual, out ySizeActual ); bool ok = true; ok &= (seed == seedActual); ok &= (xSize == xSizeActual); ok &= (ySize == ySizeActual); if (!ok) { ok = false; } Assert.AreEqual(seed, seedActual, testObject + ": seed was not set correctly."); Assert.AreEqual(xSize, xSizeActual, testObject + ": xSize was not set correctly."); Assert.AreEqual(ySize, ySizeActual, testObject + ": ySize was not set correctly."); } }
/// <summary> /// Reset to the initial state (before the maze is solved). /// Subclasses should call their base class' method first. /// </summary> public override void Reset() { base.Reset(); // Move to the start square. currentSquare = maze.StartSquare; currentSquare.isVisited = true; // Start in an arbitrary direction (with a wall in the back). for (currentDirection = WallPosition.WP_MIN; currentDirection < WallPosition.WP_MAX; currentDirection++) { if (currentSquare[currentDirection] == WallState.WS_CLOSED) { currentDirection = MazeSquare.OppositeWall(currentDirection); break; } } }
/// <summary> /// Returns the value of a given currently open path. /// This value should be minimized. /// </summary> /// <param name="i"></param> /// <returns></returns> protected override double PathValue(int i) { MazeSquare sq1 = list[i]; List <WallPosition> openWalls = OpenWalls(sq1, true); if (openWalls.Count == 0) { // Immediately report any dead branch. Otherwise they would never be detected. return(double.MinValue); } WallPosition wp = SelectDirection(sq1, openWalls); MazeSquare sq2 = sq1.NeighborSquare(wp); double d1 = Maze.Distance(referenceSquare, sq1); double d2 = Maze.Distance(referenceSquare, sq2); double distanceGain = distanceSign * ((d2 - d1) / d1); return(distanceGain); }
/// <summary> /// Function that should be called by the ball. /// </summary> /// <param name="wallPosition">The position of the wall</param> public void PointScored(WallPosition wallPosition) { int scoringPlayer; switch (wallPosition) { case WallPosition.RightWall: scoringPlayer = 1; scorePlayer01++; player01ScoreText.text = $"Score: {scorePlayer01}"; break; case WallPosition.LeftWall: scoringPlayer = 2; scorePlayer02++; player02ScoreText.text = $"Score: {scorePlayer02}"; break; default: return; } ballControl.SetActive(false); if (scorePlayer01 == winScore || scorePlayer02 == winScore) { // if the game is won, then stop it and show an appropiate message EndGame(); messageBox.TimedMessage($"Player {scoringPlayer} Wins!", 60, 3); playing = false; } else { // if the game is to be continued, show appropiate message, start the countdown timer and start another turn messageBox.TimedMessage($"Player {scoringPlayer} Scored!", 60, 1, () => { // start the turn at the end of the 3 second countdown of the countdown timer countdownTimer.CountdownFinishedOnce += (object sender, EventArgs e) => StartTurn(); countdownTimer.StartCountdown(3, 1); }); } }
public Cell GetNeighbour(WallPosition wall) { Debug.Assert(Enum.IsDefined(typeof(WallPosition), wall)); switch (wall) { case WallPosition.West: Debug.Assert(X > 0); return _maze.Cells[Y, X - 1]; case WallPosition.North: Debug.Assert(Y > 0); return _maze.Cells[Y - 1, X]; case WallPosition.East: Debug.Assert(X < _maze.Width - 1); return _maze.Cells[Y, X + 1]; case WallPosition.South: Debug.Assert(Y < _maze.Height - 1); return _maze.Cells[Y + 1, X]; default: throw new Exception("Invalid wall position"); } }
/// <summary> /// Initialize all squares in the mazeExtension (everything but trajectoryDistance). /// </summary> /// <param name="maze"></param> private void InitializeMazeExtension(Maze maze) { for (int i = 0; i < maze.XSize; i++) { for (int j = 0; j < maze.YSize; j++) { MazeSquare sq = maze[i, j]; MazeSquareExtension sqe = mazeExtension[i, j]; // extendedSquare: sqe.extendedSquare = sq; if (sq.isReserved) { // isDeadEnd: sqe.isDeadEnd = true; sqe.trajectoryDistance = -1; } else { // neighbors: sqe.neighbors = new List <MazeSquareExtension>(4); for (WallPosition wp = WallPosition.WP_MIN; wp <= WallPosition.WP_MAX; wp++) { MazeSquare sq2 = sq.NeighborSquare(wp); if (sq2 != null && !sq2.isReserved) { sqe.neighbors.Add(mazeExtension[sq2.XPos, sq2.YPos]); } } // Negative values mean: not initialized sqe.trajectoryDistance = int.MinValue; } } } }
/// <summary> /// Create a copy of this maze. /// </summary> /// <returns></returns> public Maze Clone() { Maze clone = new Maze(xSize, ySize); clone.xStart = this.xStart; clone.yStart = this.yStart; clone.xEnd = this.xEnd; clone.yEnd = this.yEnd; clone.direction = this.direction; clone.seed = this.seed; clone.reservedAreas = this.reservedAreas; clone.reservedAreaShapes = this.reservedAreaShapes; clone.embeddedMazeShapes = this.embeddedMazeShapes; clone.embeddedMazes = new List <EmbeddedMaze>(embeddedMazes.Count); foreach (EmbeddedMaze em in embeddedMazes) { #if false // Currently not required because the Clone() method is only used by the MasterSolver to get the solution path. // TODO: em.Clone(clone) clone.embeddedMazes.Add((EmbeddedMaze)em.Clone()); #endif } clone.CreateSquares(); for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { for (WallPosition wp = WallPosition.WP_MIN; wp <= WallPosition.WP_MAX; wp++) { clone[x, y][wp] = this[x, y][wp]; } } } return(clone); }
public void EraseWall(WallPosition wall) { Debug.Assert(Enum.IsDefined(typeof(WallPosition), wall)); Debug.Assert(!IsMazeBorder(wall)); switch (wall) { case WallPosition.West: _hasWestWall = false; break; case WallPosition.North: _hasNorthWall = false; break; case WallPosition.East: // Never called from rightmost cells. _maze.Cells[Y, X+1]._hasWestWall = false; break; case WallPosition.South: // Never called from lowermost cells. _maze.Cells[Y + 1, X]._hasNorthWall = false; break; default: throw new Exception("Invalid wall position"); } }
public void SB_OpenWallsTest_01() { string testObject = "SWA.Ariadne.Logic.SolverBase.OpenWalls"; MazeSquare sq = new MazeSquare(0, 0); for (WallPosition wp = WallPosition.WP_MIN; wp <= WallPosition.WP_MAX; wp++) { sq[wp] = WallState.WS_CLOSED; } Maze maze = new Maze(0, 0); maze.CreateMaze(); IMazeSolver target = SolverFactory.CreateDefaultSolver(maze, null); SWA_Ariadne_Logic_SolverBaseAccessor accessor = new SWA_Ariadne_Logic_SolverBaseAccessor(target); bool notVisitedOnly = false; List <WallPosition> actual; actual = accessor.OpenWalls(sq, notVisitedOnly); Assert.AreEqual(0, actual.Count, testObject + " did not return the expected value."); }
public TeethElement(WallPosition position) : base(position) { }
private static List <MazeSquare> Move(DeadEndChecker target, ref MazeSquare sq, WallPosition direction, int expectedDeadSquaresCount) { sq = sq.NeighborSquare(direction); List <MazeSquare> deadSquares = target.Visit(sq); Assert.AreEqual(expectedDeadSquaresCount, deadSquares.Count, "Number of dead squares doesn't match."); return(deadSquares); }
public bool IsMazeBorder(WallPosition wall) { Debug.Assert(Enum.IsDefined(typeof(WallPosition), wall)); switch (wall) { case WallPosition.West: return X == 0; case WallPosition.North: return Y == 0; case WallPosition.East: // Never called from rightmost cells. return X == _maze.Width - 1; case WallPosition.South: // Never called from lowermost cells. return Y == _maze.Height - 1; default: throw new Exception("Invalid wall position"); } }
public bool HasWall(WallPosition wall) { Debug.Assert(Enum.IsDefined(typeof(WallPosition), wall)); switch (wall) { case WallPosition.West: return _hasWestWall; case WallPosition.North: return _hasNorthWall; case WallPosition.East: // Never called from rightmost cells. return _maze.Cells[Y, X + 1]._hasWestWall; case WallPosition.South: // Never called from lowermost cells. return _maze.Cells[Y + 1, X]._hasNorthWall; default: throw new Exception("Invalid wall position"); } }
/// <summary> /// Setup method: Define the adjoining sqare on the other side of a wall. /// </summary> /// <param name="side"></param> /// <param name="neighbor"></param> internal void SetNeighbor(WallPosition side, MazeSquare neighbor) { this.neighbors[(int)side] = neighbor; }
public WallState this[WallPosition side] { get { return(walls[(int)side]); } set { walls[(int)side] = value; } }
/// <summary> /// Returns the square on the other side of a wall. /// </summary> /// <param name="side"></param> /// <returns></returns> public MazeSquare NeighborSquare(WallPosition side) { return(this.neighbors[(int)side]); }