示例#1
0
            internal PancakeState NextState(int flipperPosition, int flipperSize)
            {
                StringBuilder sb = new StringBuilder(Config);

                for (int i = flipperPosition; i < flipperPosition + flipperSize; i++)
                {
                    sb[i] = (sb[i] == '+' ? '-' : '+');
                }

                PancakeState result = new PancakeState(sb.ToString());

                //result.InputFlipperPositions = InputFlipperPositions.Append(flipperPosition).ToList();
                return(result);
            }
示例#2
0
        public string Solve(string line)
        {
            if (_testCaseCount == 0)
            {
                _testCaseCount = int.Parse(line);
                return(null);
            }

            ResetState();
            TestCase testCase = new TestCase(line.Split(' ')[0], int.Parse(line.Split(' ')[1]), "");

            PancakeState initialState = testCase.InitialState;
            int          problemSize  = initialState.Size;
            int          flipperSize  = testCase.FlipperSize;

            if (IsFinal(initialState))
            {
                return("0");
            }

            PancakeState prevState = initialState;

            _allStatesExplored.Add(initialState);
            bool foundNewMove = true;  // so we can enter the loop
            int  moves        = 1;

            // Move to the first pancake which needs to be flipped
            for (int flipperPos = Math.Min(prevState.FirstMinusPos, problemSize - flipperSize);
                 foundNewMove;
                 flipperPos = Math.Min(prevState.FirstMinusPos, problemSize - flipperSize))
            {
                foundNewMove = false;
                PancakeState state = prevState.NextState(flipperPos, flipperSize);
                if (IsFinal(state))
                {
                    return(moves.ToString());
                }
                if (!WasAlreadyExplored(state))
                {
                    _allStatesExplored.Add(state);
                    foundNewMove = true;
                    prevState    = state;
                }
                moves++;
            }

            return("IMPOSSIBLE");
        }
    /// <summary>
    /// Sets state of pancake that is face down in the pan.
    /// </summary>
    /// <returns> returns true if successful</returns>
    public bool SetState(PancakeState state)
    {
        // search for state and set it if not found do nothing

        foreach (CookingState cState in cookingStates)
        {
            if (cState.pancakeState == state)
            {
                pancakeStates[currentSideDown] = state;

                SetTimer(currentSideDown);

                OnStateChanged?.Invoke(state);
                return(true);
            }
        }

        return(false);
    }
 public void OnPancakeStateChanged(PancakeState state)
 {
     // only update pancake scale when in a state of mixture :)
     active = state == PancakeState.Mixture;
 }
示例#5
0
 public bool CompareState(PancakeState state)
 {
     return(pancakeState == state);
 }
示例#6
0
 public void SetState(PancakeState state)
 {
     pancakeState = state;
 }
 public void SetState(CookingState state)
 {
     pancakeState = state.pancakeState;
     stateLength  = state.stateLength;
     endColor     = state.endColor;
 }
 public void OnPancakeStateChanged(PancakeState state)
 {
     // only update radius when in a state of mixture.
     canUpdatePancakeRadius = state == PancakeState.Mixture;
 }
示例#9
0
 private bool WasAlreadyExplored(PancakeState state)
 {
     return(_allStatesExplored.Contains(state));
 }
示例#10
0
 public TestCase(string initialState, int flipperSize, string expectedResult)
 {
     InitialState   = new PancakeState(initialState);
     FlipperSize    = flipperSize;
     ExpectedResult = expectedResult;
 }
示例#11
0
 bool IsFinal(PancakeState state)
 {
     return(state.ToString().All(c => c == '+'));
 }