private static Board GetNextBoard(Board board) { var boardPieces = board.ToIntArray(); var nextPerm = PermutationCalculator<int>.GetNextPermutation(boardPieces); return nextPerm == null ? null : new Board(nextPerm.ToArray()); }
public Board ReflectOverYEqualsX(Board board) { var newBoard = new Board(board.N); for (var i = 0; i < board.N; i++) { newBoard[board[i]] = i; } return newBoard; }
private static bool AreEqualBoards(Board left, Board right) { if (left.N != right.N) return false; for (var i = 0; i < left.N; i++) { if (left[i] != right[i]) return false; } return true; }
public Board ReflectOverXAxis(Board board) { var newBoard = new Board(board.N); var maxIndex = board.N - 1; for (var i = 0; i < board.N; i++) { newBoard[i] = maxIndex - board[i]; } return newBoard; }
public Board ReflectOverYEqualsMinusX(Board board) { var newBoard = new Board(board.N); var maxIndex = board.N - 1; for (var i = 0; i < board.N; i++) { var oldX = i; var oldY = board[i]; var newX = maxIndex - oldY; var newY = maxIndex - oldX; newBoard[newX] = newY; } return newBoard; }
public Board Rotate180Degrees(Board board) { var newBoard = new Board(board.N); var maxIndex = board.N - 1; for (var i = 0; i < board.N; i++) { var oldX = i; var oldY = board[i]; var newX = maxIndex - oldX; var newY = maxIndex - oldY; newBoard[newX] = newY; } return newBoard; }
public Board ReflectOverYAxis(Board board) { var values = board.ToIntArray().Reverse().ToArray(); return new Board(values); }
private static Board Shuffle(Board board) { var shuffler = new ArrayShuffler(); var shuffledBoard = new Board(shuffler.Execute(board.ToIntArray())); return shuffledBoard; }
private bool IsUnique(Board board) { if (IsAlreadySolution(board)) return false; var rotator = new BoardTransformer(); var copy = rotator.ReflectOverXAxis(board); if (IsAlreadySolution(copy)) return false; copy = rotator.ReflectOverYAxis(board); if (IsAlreadySolution(copy)) return false; copy = rotator.ReflectOverYEqualsX(board); if (IsAlreadySolution(copy)) return false; copy = rotator.ReflectOverYEqualsMinusX(board); if (IsAlreadySolution(copy)) return false; copy = rotator.Rotate90Degrees(board); if (IsAlreadySolution(copy)) return false; copy = rotator.Rotate180Degrees(board); if (IsAlreadySolution(copy)) return false; copy = rotator.Rotate270Degrees(board); if (IsAlreadySolution(copy)) return false; return true; }
private bool IsAUniqueSolution(Board board) { if (!IsASolution(board)) return false; return IsUnique(board); }
private bool IsASolution(Board board) { var clashChecker = new BoardClashChecker(); if (clashChecker.Execute(board)) return false; return true; }
private bool IsAlreadySolution(Board potantialSolution) { return _solutions.Any(solution => AreEqualBoards(potantialSolution, solution)); }
private Board InitializeBoard() { var board = new Board(N); for (int i = 0; i < N; i++) board[i] = i; return board; }