private static void SolveBoard(int boardSize, Piece[] pieces) { var board = new Board(boardSize); var solver = new Solver(); var pieceFeeder = new PieceFeeder(pieces); var solutionDetails = solver.SolvePuzzle(board, pieceFeeder); if (solutionDetails.Solved) { var consolePrintTarget = new ConsolePrintTarget(); var boardPrinter = new BoardPrinter(consolePrintTarget); Console.WriteLine("Solution found after {0} iterations.", solutionDetails.Iterations); PrintPermutation(solutionDetails.Solution); Console.WriteLine(); boardPrinter.Print(board); } else { Console.WriteLine("Failed to find a solution after {0} iterations.", solutionDetails.Iterations); } Console.WriteLine(); }
public RotatedPieceHolder(Piece piece) { Piece = piece; Reset(); }
private object CreatePiece(Piece piece) { var initStrings = CreateArray(); for (var y = piece.Height - 1; y >= 0; y--) { var initString = string.Empty; for (var x = 0; x < piece.Width; x++) { var square = piece.SquareAt(x, y); if (square != null) initString += (square.Colour == Colour.Black) ? "B" : "W"; else initString += " "; } initStrings.Add(CreateString(initString)); } var name = CreateString(piece.Name.ToString(CultureInfo.InvariantCulture)); return CreateDict( new[] {"InitStrings", "Name"}, new[] {initStrings, name}); }
private void AddDataItemsForPieceWithSpecificOrientation(IList<IList<bool>> data, int pieceIndex, Piece piece, Orientation orientation) { var rotatedPiece = new RotatedPiece(piece, orientation); for (var x = 0; x < _board.BoardSize; x++) { for (var y = 0; y < _board.BoardSize; y++) { _board.Reset(); _board.ForceColourOfSquareZeroZeroToBeBlack(); if (!_board.PlacePieceAt(rotatedPiece, x, y)) continue; var dataItem = BuildDataItem(pieceIndex, rotatedPiece, x, y); data.Add(dataItem); _dictionary.Add(data.Count - 1, Tuple.Create(rotatedPiece, x, y)); } } }
public bool PlacePieceAt(Piece piece, int x, int y) { return PlacePieceAt(new RotatedPiece(piece, Orientation.North), x, y); }