public static GameMoveResult TestGuessAgainstSolution(GameMove theGuess, GameMove theSolution)
        {
            var result = new GameMoveResult();
            var placeTracker = new string[theGuess.Slots.Length];

            for (int position = 0; position < theGuess.Slots.Count(); position++)
            {
                var currentSlot = theGuess.Slots[position];

                // check the current slot against the corresponding color
                if (currentSlot.ColorCode == theSolution.Slots[position].ColorCode)
                {
                    result.NumberOfReds++;
                    placeTracker[position] = "R";
                }
                else
                {
                    // now check to see if you can find the corresponding color somewhere else
                    int index = 0;
                    while (index >= 0)
                    {
                        index = Array.FindIndex<ColorSelection>(theSolution.Slots, index, (color) => color.ColorCode == currentSlot.ColorCode);
                        if (index >= 0)
                        {
                            if (placeTracker[index] == null)
                            {
                                result.NumberOfWhites++;
                                placeTracker[index] = "W";
                                index = -1; // reset
                            }
                            else
                            {
                                // shift up one to increment the search
                                index++;
                            }
                        }
                    }
                }
            }
            result.NumberOfEmpties = theSolution.Slots.Count() - result.NumberOfReds - result.NumberOfWhites;
            return result;
        }
示例#2
0
 public GameMoveResult RecordGuess(GameMove move)
 {
     Moves.Add(move);
     var result = GameEngine.TestGuessAgainstSolution(move, _solution);
     result.SequenceNumber = Moves.Count;
     if (result.IsSolved)
     {
         IsSolved = true;
         if (OnVictory != null) OnVictory(this, new EventArgs());
     }
     else
     {
         IsSolved = false;
         if (Moves.Count >= Game.MAX_MOVES_ALLOWED)
         {
             if (OnFailure != null) OnFailure(this, new EventArgs());
         }
     }
     return result;
 }
示例#3
0
 private void GenerateSolution()
 {
     Random random = new Random();
     int max = ColorSelection.ColorSwatches.Count();
     _solution = new GameMove(
         ColorSelection.ColorSwatches[random.Next(0, max)],
         ColorSelection.ColorSwatches[random.Next(0, max)],
         ColorSelection.ColorSwatches[random.Next(0, max)],
         ColorSelection.ColorSwatches[random.Next(0, max)]);
 }
示例#4
0
 internal Game(GameMove solution)
 {
     InitBasicGame();
     _solution = solution;
 }
        private void SubmitGuess()
        {
            var pvm = new PlayerMoveViewModel();

            var guess = new GameMove(
                ColorSelection.FindColorSwatchByColorCode(_MoveSlotOne),
                ColorSelection.FindColorSwatchByColorCode(_MoveSlotTwo),
                ColorSelection.FindColorSwatchByColorCode(_MoveSlotThree),
                ColorSelection.FindColorSwatchByColorCode(_MoveSlotFour));

            var result = _game.RecordGuess(guess);

            pvm.MoveData = guess;
            pvm.ResultData = result;

            DispatcherHelper.CheckBeginInvokeOnUI(() => Moves.Add(pvm));

            if (!CurrentGame.IsSolved)
                SaveGameState();

        }
 public static Game CreateSampleGame(GameMove solution)
 {
     return new Game(solution);
 }