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