public static bool IsValidMove(Playfield playfield, Direction nextDirection) { int playerCurrentRow = playfield.PlayerPosition.Row; int playerCurrentCol = playfield.PlayerPosition.Col; Position playerCurrentPosition = new Position(playerCurrentRow, playerCurrentCol); if (playerCurrentPosition.IsWinner()) { return false; } playerCurrentPosition.MoveAtDirection(nextDirection); int[,] fieldGrid = playfield.LabyrinthGrid; return IsValidPosition(fieldGrid, playerCurrentPosition); }
/// <summary> /// Ensure clear escaping path from player start position /// </summary> private void EnsureClearPath() { Direction nextDirection = new Direction(); Position currentPosition = new Position(); while (!currentPosition.IsWinner()) { int randomNumber = randomNumberGenerator.Next(-1, 4); nextDirection = (Direction)(randomNumber); if (!MovesChecker.IsValidMove(this, nextDirection)) { currentPosition.MoveAtDirection(nextDirection); this.LabyrinthGrid[currentPosition.Row, currentPosition.Col] = 0; } } }