Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private void MoveCellAccordingToRules(CellIndices indices)
        {
            if (board.CellIsAdjacentToEmpty(indices))
            {
                var moveToPos = board.GetEmptyCellPos();

                board.SwapCells(indices, moveToPos);

                view.NotifyOnCellMoved(indices, moveToPos);
            }
        }