public DefaultApp() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var notifiableView = new NotifiableGameView();; this.view = notifiableView; var board = new SquareBoard(4); var game = new Game(notifiableView, board); this.controller = new DefaultGameController(game); mainWindow = new Window(view, controller); mainWindow.SetEventOnNewImageSelected(ChangePuzzleImage); var outputControl = FindControl(boardOutputControlName); var defaultImage = Image.FromFile(defaultImagePath); var cellFactory = new BoardCellFactory(controller, defaultImage); this.boardRenderer = new BoardRenderer(outputControl, board, cellFactory); view.SetEventOnCellMoved(boardRenderer.SwapCells); view.SetEventOnBoardChanged(boardRenderer.Render); boardRenderer.Render(board); }
private Node[] GetSuccessorStates(Node state) { var generator = new MoveGenerator(state.board); var moves = generator.GetMoves(); var successors = new Node[moves.Length]; for (int i = 0; i < moves.Length; ++i) { var board = new SquareBoard(state.board); board.SwapCells(board.GetEmptyCellPos(), moves[i]); var successorCost = state.Cost() + 1; successors[i] = new Node ( board, successorCost, board.GetManhattanDistFromCompletion() + successorCost, state, moves[i] ); } return(successors); }
public Node(SquareBoard board, int cost, int estimation, Node parent, CellIndices moveToThis) { this.parent = parent; this.board = board; this.cost = cost; this.estimation = estimation; this.moveToThis = moveToThis; }
public PuzzleSolver(SquareBoard board) { this.board = board; closed = new HashSet <Node>(new NodeEqualityComparer()); open = new PriorityQueue <Node>(); AddInitialStateToOpen(); }
public SquareBoard(SquareBoard other) { this.size = other.size; this.correctlyOrderedCells = other.correctlyOrderedCells; this.emptyCellPos = other.emptyCellPos; this.cells = new Cell[size, size]; CopyCellsFrom(ref other.cells, ref this.cells); }
public void ChangeBoardSize(int size) { if (isGameBeingSolved) { return; } this.board = new SquareBoard(size); DisorderBoard(); view.NotifyOnBoardChanged(board); }
public Game(NotifiableGameView view, SquareBoard board) { this.view = view; this.board = board; this.isGameBeingSolved = false; this.drawCounter = 0; this.solveTimer = new System.Windows.Forms.Timer(); solveTimer.Interval = replayStepTimeInMs; DisorderBoard(); }
public void Render(SquareBoard board) { this.board = board; Render(); }
public BoardRenderer(Control outputControl, SquareBoard board, BoardCellFactory cellFactory) { this.outputControl = outputControl; this.board = board; this.cellFactory = cellFactory; }
public MoveGenerator(SquareBoard board) { this.board = board; random = new Random(); }