예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 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;
 }
예제 #4
0
        public PuzzleSolver(SquareBoard board)
        {
            this.board = board;
            closed     = new HashSet <Node>(new NodeEqualityComparer());

            open = new PriorityQueue <Node>();
            AddInitialStateToOpen();
        }
예제 #5
0
        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);
        }
예제 #6
0
        public void ChangeBoardSize(int size)
        {
            if (isGameBeingSolved)
            {
                return;
            }

            this.board = new SquareBoard(size);
            DisorderBoard();

            view.NotifyOnBoardChanged(board);
        }
예제 #7
0
        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();
        }
예제 #8
0
 public void Render(SquareBoard board)
 {
     this.board = board;
     Render();
 }
예제 #9
0
 public BoardRenderer(Control outputControl, SquareBoard board, BoardCellFactory cellFactory)
 {
     this.outputControl = outputControl;
     this.board         = board;
     this.cellFactory   = cellFactory;
 }
예제 #10
0
 public MoveGenerator(SquareBoard board)
 {
     this.board = board;
     random     = new Random();
 }