Пример #1
0
        private void MoveCellAccordingToRules(CellIndices indices)
        {
            if (board.CellIsAdjacentToEmpty(indices))
            {
                var moveToPos = board.GetEmptyCellPos();

                board.SwapCells(indices, moveToPos);

                view.NotifyOnCellMoved(indices, moveToPos);
            }
        }
Пример #2
0
        public CellIndices GetMove()
        {
            var displacement = GetRandomNonDiagonalIndexDisplacement();

            var adjacentCell = board.GetEmptyCellPos();

            adjacentCell.column += displacement.column;
            adjacentCell.row    += displacement.row;

            return(EnforceBoardBoundariesByMirroringMove(adjacentCell));
        }
Пример #3
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);
        }
Пример #4
0
 private bool IsNotLowerRightCell(CellIndices indices)
 {
     return(board.GetEmptyCellPos() != indices);
 }