Ejemplo n.º 1
0
        public int CountMismatches(EightPuzzleBoard aBoard)
        {
            int count = 0;

            for (int i = 0; i < 9; i++)
            {
                if (board[i] != aBoard[i] && board[i] != 0)
                {
                    count++;
                }
            }
            return(count);
        }
Ejemplo n.º 2
0
        public EightPuzzleBoard Scramble(int n)
        {
            var newPuzzle     = new EightPuzzleBoard(this);
            var directions    = Enum.GetValues(typeof(Direction)).Cast <Direction>().ToList();
            var lastDirection = Direction.DOWN;

            for (int i = 0; i < n;)
            {
                var direction = directions[rng.Next(directions.Count)];
                if (newPuzzle.CanMoveGap(direction) && (i == 0 || !direction.IsOppositeOf(lastDirection)))
                {
                    newPuzzle.MoveGap(direction);
                    lastDirection = direction;
                    i            += 1;
                }
            }

            return(newPuzzle);
        }
Ejemplo n.º 3
0
 public EightPuzzleBoard(EightPuzzleBoard aBoard)
 {
     this.board = (int[])aBoard.board.Clone();
 }