コード例 #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
ファイル: Node.cs プロジェクト: Hamsterarsch/TilePuzzleAI
 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
ファイル: Game.cs プロジェクト: Hamsterarsch/TilePuzzleAI
        public void ChangeBoardSize(int size)
        {
            if (isGameBeingSolved)
            {
                return;
            }

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

            view.NotifyOnBoardChanged(board);
        }
コード例 #7
0
ファイル: Game.cs プロジェクト: Hamsterarsch/TilePuzzleAI
        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();
 }