Ejemplo n.º 1
0
        protected override GameState Update0(float deltaTime)
        {
            // query hole states from physical interface
            int[] newHoleStates = new int[HoleCount];
            for (int i = 0; i < HoleCount; i++)
            {
                newHoleStates[i] = Physical.GetHoleState(i);
            }

            // update hole states in solution checker
            bool[] instructionsSolved = wall.CheckSolution(scenario, newHoleStates);

            // compare old and new hole states to send notifications on changes
            for (int i = 0; i < HoleCount; i++)
            {
                if (newHoleStates[i] != lastHoleStates[i])
                {
                    if (lastHoleStates[i] == -1)   // if there was no stick and now there is
                    {
                        Log.Verbose("Dynamite: Stick {0} has been inserted into hole {1}.", newHoleStates[i], i);
                        OnStickInserted?.Invoke(this, new StickEventArgs(DynamiteStick.Sticks[newHoleStates[i]], i));
                    }
                    if (newHoleStates[i] == -1)   // if there was a stick and now there isn't
                    {
                        Log.Verbose("Dynamite: Stick {0} has been removed from hole {1}.", lastHoleStates[i], i);
                        OnStickRemoved?.Invoke(this, new StickEventArgs(DynamiteStick.Sticks[lastHoleStates[i]], i));
                    }
                }
                lastHoleStates[i] = newHoleStates[i];
            }

            for (int i = 0; i < lastInstructionsSolvedState.Length; i++)
            {
                if (lastInstructionsSolvedState[i] != instructionsSolved[i])
                {
                    Log.Verbose("Dynamite: Instruction {0} has been {1}.", i, instructionsSolved[i] ? "solved" : "unsolved");
                    OnInstructionSolvedStateChanged?.Invoke(this, new InstructionSolvedStateChangedArgs(i, instructionsSolved[i]));
                }
                lastInstructionsSolvedState[i] = instructionsSolved[i];
            }

            if (instructionsSolved.Contains(false))
            {
                return(GameState.Running);
            }

            return(GameState.Completed);
        }
Ejemplo n.º 2
0
        public static DynamiteScenario ChooseScenario(GameDifficulty difficulty, DynamiteWall wall, int[] currentHoleStates)
        {
            //LastScenario last;
            //bool lastScenarioAvailable = readLastScenario(out last);

            List <DynamiteScenario> possibleScenarios = getPossibleScenarios(difficulty);

            /*
             * if (lastScenarioAvailable && difficulty == last.difficulty) {
             *  for (int i = 0; i < possibleScenarios.Count; i++)
             *      if (possibleScenarios[i].Number == last.number) {
             *          Log.Verbose("Last scenario found ({0} for difficulty {1}), skipping number {2}", last.name, last.difficulty, last.number);
             *          possibleScenarios.RemoveAt(i);
             *          break;
             *      }
             * }*/

            DynamiteScenario[] shuffled = possibleScenarios.ToArray();
            shuffled.Shuffle();

            for (int i = 0; i < shuffled.Length; i++)
            {
                bool[] instructionsSolved = wall.CheckSolution(shuffled[i], currentHoleStates);
                if (instructionsSolved.Count(false) > 0)
                {
                    return(shuffled[i]);
                }
            }

            Log.Warn("Current hole states fulfil every possible scenario for difficulty " + difficulty);
            return(shuffled[0]);

            /*
             * Scenario result = possibleScenarios[Extensions.r.Next(possibleScenarios.Count)];
             * writeLastScenario(result);
             * return result;
             */
        }