Example #1
0
        /// <remarks>
        /// Starts with a solved cube and moves the desired cubies into the constraint. (essentially unsolving it but finding the correct moves)
        /// Could alternatively move the cubes backwards from the solved state into their desired starting position and then reverse the moves.
        /// </remarks>
        static internal TurnSequence GetStepsToAcheiveMatch(
            int maxTurnCount,
            CubeConstraint constraint,
            NodeMoveGenerator <Cube> moveGenerator
            )
        {
            var moveIterator = new IterativeDeepeningIterator <Cube>(moveGenerator, maxTurnCount)
            {
                DontRepeat = true
            };

            Node <Cube> winner = moveIterator.Iterate(new Cube())
                                 .FirstOrDefault(node => constraint.IsMatch(node.State));

            if (winner == null)
            {
                throw new MoveNotFoundExcpetion();
            }

            var path = winner.GetNodePath();

            Turn[] ddd = path
                         .Skip(1)
                         .SelectMany(x => ((TurnSequenceMove)x.Move)._sequence._turns)
                         .ToArray();

            return(new TurnSequence(ddd));
        }
Example #2
0
 static public void VerifyConstraint(Cube cube, CubeConstraint constraint, string msg)
 {
     if (!constraint.IsMatch(cube))
     {
         throw new System.InvalidOperationException(msg);
     }
 }
 public void Add(CubeConstraint constraint) => _parts.Add(constraint);