public void RandomSolutionIsValid()
        {
            Mastermind mastermind = new Mastermind();

            Colors[] colorSet = mastermind.SetColorSelection();

            List <Colors> allColors = new List <Colors>();

            for (int i = 0; i < Enum.GetNames(typeof(Colors)).Length; i++)
            {
                allColors.Add((Colors)i);
            }

            bool allValidColors = true;

            for (int i = 0; i < 5 && allValidColors; i++)
            {
                if (!allColors.Contains(colorSet[i]))
                {
                    allValidColors = false;
                }
            }

            Assert.True(allValidColors);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Mastermind mm = new Mastermind();

            mm.code_Genaration();
            mm.Getting_input();
        }
 public MastermindGame(Mastermind codeChecker, CodeRandomiser codeRandomiser, UIWriter uiWriter, InputCleanser inputCleanser)
 {
     _mastermind     = codeChecker;
     _uiWriter       = uiWriter;
     _inputCleanser  = inputCleanser;
     _codeRandomiser = codeRandomiser;
 }
        public void PlayerLosesAfter20Tries()
        {
            Mastermind mastermind = new Mastermind();

            mastermind.SetColorSelection(Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple);

            Response[] response = new Response[5];
            Response[] expected = new Response[] { Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION, Response.MATCH_POSITION };

            bool gameWon    = false;
            int  roundCount = 0;

            for (int i = 0; i < 20 && !gameWon; i++)
            {
                roundCount = i + 1;

                response = mastermind.Guess(Colors.Orange, Colors.Gray, Colors.White, Colors.Yellow, Colors.Black);
                if (response == expected)
                {
                    gameWon = true;
                }
            }

            Assert.True(!gameWon && (roundCount == 20));
        }
Exemple #5
0
        public static async Task CreateMastermindAsync(GameServiceClient client)
        {
            var mastermind = new Mastermind();

            mastermind.Name          = ConsoleUtility.GetUserInput("Mastermind Name: ");
            mastermind.GamePackageId = await GamePackageUtility.SelectGamePackageId(client);

            mastermind.AbilityIds.AddRange(await AbilityUtility.SelectAbilityIds(client));
            mastermind.HasEpicSide = ConsoleUtility.GetUserInputBool("Has Epic side?");
            mastermind.CardRequirements.AddRange(await CardRequirementUtility.GetCardRequirements(client, mastermind.GamePackageId, true));

            if (!ConsoleUtility.ShouldContinue($"Creating Mastermind: {mastermind}"))
            {
                await CreateMastermindAsync(client);

                return;
            }

            var createRequest = new CreateMastermindsRequest();

            createRequest.Masterminds.Add(mastermind);
            var createReply = await client.CreateMastermindsAsync(createRequest);

            if (createReply.Status.Code != 200)
            {
                ConsoleUtility.WriteLine($"Failed to create mastermind: {createReply.Status.Message}");
            }
            else
            {
                ConsoleUtility.WriteLine($"Mastermind '{createReply.Masterminds.First().Name}' was created with Id '{createReply.Masterminds.First().Id}'");
            }
        }
 // Start is called before the first frame update
 void Start()
 {
     mastermind = Chimera.GetInstance().mastermindScreen.GetComponent <Mastermind>();
     image      = transform.Find("Image").GetComponent <Image>();
     button     = GetComponent <Button>();
     SetMastermindColor(mastermind.colors[0]);
 }
Exemple #7
0
        private void CommandBinding_ExecuteExportGlo(object sender, ExecutedRoutedEventArgs e)
        {
            var result = Mastermind.ShowPromptTimeSpan(this, "Export start time", TimeSpan.Zero);

            if (!result.Success)
            {
                return;
            }
            TimeSpan startTime = result.Value;

            string exportName = main.DocumentName;

            if (exportName.EndsWith(FileSerializer.EXTENSION_PROJECT, StringComparison.InvariantCultureIgnoreCase))
            {
                exportName = exportName.Substring(0, exportName.Length - FileSerializer.EXTENSION_PROJECT.Length);
            }

            var diag = new Microsoft.Win32.SaveFileDialog();

            diag.FileName     = exportName + FileSerializer.EXTENSION_EXPORT;
            diag.AddExtension = true;
            diag.DefaultExt   = FileSerializer.EXTENSION_EXPORT;
            diag.Filter       = string.Format("Aerotech Ultimate Program (*{0})|*{0}", FileSerializer.EXTENSION_EXPORT);
            diag.FilterIndex  = 0;

            if (diag.ShowDialog(this).GetValueOrDefault(false))
            {
                if (main.ExportProgram(diag.FileName, (float)startTime.TotalSeconds))
                {
                    MessageBox.Show(this, "Done!");
                }
            }
        }
        public void Should_not_match_pegs_more_than_once()
        {
            var mastermind = new Mastermind("r y y y");

            var result = mastermind.Guess("g r r r");

            result.ShouldEqual("m");
        }
        public void Should_return_several_matches_if_there_are_sevral_matches_in_wrong_location()
        {
            var mastermind = new Mastermind("r r y y");

            var result = mastermind.Guess("b b r r");

            result.ShouldEqual("mm");
        }
        public void Should_return_only_p_when_guess_is_correct()
        {
            var mastermind = new Mastermind("r r r y");

            var result = mastermind.Guess("r r r y");

            result.ShouldEqual("pppp");
        }
        public void Should_return_a_specific_match_if_a_match_is_in_correct_location()
        {
            var mastermind = new Mastermind("r r r y");

            var result = mastermind.Guess("b b b y");

            result.ShouldEqual("p");
        }
        public void Should_return_a_match_if_there_is_a_match_in_wrong_location()
        {
            var mastermind = new Mastermind("r y y y");

            var result = mastermind.Guess("b r b b");

            result.ShouldEqual("m");
        }
        public void Should_not_return_any_matches_when_there_is_no_matches()
        {
            var mastermind = new Mastermind("r r r r");

            var result = mastermind.Guess("b b b b");

            result.ShouldEqual(string.Empty);
        }
        public void Should_not_include_partial_matches_if_the_color_is_already_matched_in_spesific_position()
        {
            var mastermind = new Mastermind("r r r y");

            var result = mastermind.Guess("b b y y");

            result.ShouldEqual("p");
        }
Exemple #15
0
        public void SelectSecretSolutionShould_ReturnArrayOf4Pegs()
        {
            var secretSolutionGenerator = new SecretSolutionGenerator();
            var mastermind = new Mastermind(secretSolutionGenerator);

            mastermind.SetSecretSolution(_colours);

            Assert.Equal(4, mastermind.SecretSolution.Length);
        }
Exemple #16
0
        public void Guess_ThrowsIfAttemptedAfterGameWon()
        {
            // Arrange
            var underTest = new Mastermind(new int[] { 1, 2, 3, 4 });

            underTest.Guess("1234");

            // Act/Assert
            underTest.Invoking(x => x.Guess("1234")).Should().Throw <InvalidOperationException>();
        }
Exemple #17
0
        public void ShouldNotMatchAnyPlayerGuesses()
        {
            Mastermind mastermind = new Mastermind();

            mastermind.SetColorSelection(Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple);

            Response[] response = mastermind.Guess(Colors.Orange, Colors.Gray, Colors.White, Colors.Yellow, Colors.Black);

            Assert.False(response.All <Response>(r => r == Response.MATCH_POSITION));
        }
Exemple #18
0
        public IActionResult PostNew([FromBody] Mastermind newM)
        {
            var result = mmService.NewGame(newM);

            if (result == null)
            {
                return(BadRequest(-1));
            }
            return(Ok(result));
        }
Exemple #19
0
        public void Guess_WithCorrectSolution_EndsGame()
        {
            // Arrange
            var underTest = new Mastermind(new int[] { 1, 2, 3, 4 });

            // Act
            underTest.Guess("1234");

            // Assert
            underTest.IsComplete.Should().BeTrue();
        }
Exemple #20
0
        public void Guess_DecrementsGuessesRemaining()
        {
            // Arrange
            var underTest = new Mastermind(new int[] { 1, 2, 3, 4 });

            // Act
            underTest.Guess("1231");

            // Assert
            underTest.GuessesRemaining.Should().Be(9);
        }
Exemple #21
0
        public void MatchesGuessCorrectly([Range(1, 6)] int first, [Range(1, 6)] int second, [Range(1, 6)] int third, [Range(1, 6)] int fourth)
        {
            // Arrange
            var underTest = new Mastermind(new int[] { first, second, third, fourth });

            // Act
            var result = underTest.Guess($"{first}{second}{third}{fourth}");

            // Assert
            result.Result.Should().BeTrue();
        }
Exemple #22
0
    static void Main(string[] args)
    {
        Mastermind mastermind = new Mastermind();
        //Flag which will track if the user wants to continue playing.
        bool continuePlaying = true;

        while (continuePlaying)
        {
            continuePlaying = mastermind.Play();
        }
    }
Exemple #23
0
 public void Setup()
 {
     GameField1 = string.Join("", GameField1.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries));
     mapParser  = new MapParser(codes);
     map        = mapParser.ParseMapFromString(GameField1, new VectorInt2(8, 7));
     graph      = map.ToFullGraph();
     mind       = new Mastermind("");
     pathfinder = new DijkstraPathfinder();
     playerTile = map.Values.First(x => x.IsPlayer);
     pathfinder.FindAllPaths(graph, playerTile);
 }
Exemple #24
0
        static void Main(string[] args)
        {
            var codeChecker    = new Mastermind(new GuessValidator());
            var inputCleanser  = new InputCleanser();
            var uiWriter       = new UIWriter();
            var codeRandomiser = new CodeRandomiser();

            var mastermindGame = new MastermindGame(codeChecker, codeRandomiser, uiWriter, inputCleanser);

            mastermindGame.Run();
        }
Exemple #25
0
        private void CommandBinding_ExecuteSetTrackHeight(object sender, ExecutedRoutedEventArgs e)
        {
            var result = Mastermind.ShowPrompt(this, "Enter track height in pixels", globalParams.TrackDisplayHeight.ToString(), double.Parse,
                                               value => value > 0 && !double.IsNaN(value));

            if (!result.Success)
            {
                return;
            }

            globalParams.TrackDisplayHeight = result.Value;
        }
Exemple #26
0
        public void SelectSecretSolutionShould_ReturnArrayOf4Pegs_WithCorrectColour()
        {
            var secretSolutionGenerator = new SecretSolutionGenerator();
            var mastermind = new Mastermind(secretSolutionGenerator);

            mastermind.SetSecretSolution(_colours);

            foreach (var peg in mastermind.SecretSolution)
            {
                Assert.Contains(peg.Colour, _colours);
            }
        }
Exemple #27
0
        private void HintTestBody(int[] solution, string guess, string expectedHint, bool expectedResult = false)
        {
            // Arrange
            var underTest = new Mastermind(solution);

            // Act
            var(result, hint) = underTest.Guess(guess);

            // Assert
            result.Should().Be(expectedResult);
            hint.Should().Be(expectedHint);
        }
        private void ButtonPopOut2_Click(object sender, RoutedEventArgs e)
        {
            Mastermind.OpenPoppedOutVisualizationWindow(
                visualizationContent.ActualWidth,
                visualizationContent.ActualHeight,
                ReintegratePoppedOut2);

            visualizationContent.Visibility = Visibility.Collapsed;
            colWidthWhilePoppingOut2        = visualizationColumn.Width;
            visualizationColumn.Width       = new GridLength(0);
            visualizationColumn.MaxWidth    = 0;
            UpdateLowerAreaCollapse();
        }
        private void ButtonPopOut_Click(object sender, RoutedEventArgs e)
        {
            Mastermind.OpenPoppedOutSelectionPropertiesWindow(
                selectionDataContent.ActualWidth,
                selectionDataContent.ActualHeight,
                ReintegratePoppedOut);

            selectionDataContent.Visibility = Visibility.Collapsed;
            colWidthWhilePoppingOut         = selectionDataColumn.Width;
            selectionDataColumn.Width       = new GridLength(0);
            selectionDataColumn.MaxWidth    = 0;
            UpdateLowerAreaCollapse();
        }
Exemple #30
0
        public void CreateHintBasedOnPlayerSolutionShould_CreateHintWith4KeyPegs_BasedOnPlayerSolution()
        {
            var secretSolutionGenerator = new SecretSolutionGenerator();
            var mastermind = new Mastermind(secretSolutionGenerator);
            var peg1       = new Peg(Colour.Red);
            var peg2       = new Peg(Colour.Blue);
            var peg3       = new Peg(Colour.Green);
            var peg4       = new Peg(Colour.Orange);
            var solution   = new[] { peg1, peg2, peg3, peg4 };
            var hint       = mastermind.CreateHintBasedOnPlayerSolution(solution);

            Assert.Equal(4, hint.Length);
        }
Exemple #31
0
        public void Guess_ThrowsIfAttemptedAfterGameLost()
        {
            // Arrange
            var underTest = new Mastermind(new int[] { 1, 2, 3, 4 });

            for (int i = 0; i < 10; i++)
            {
                underTest.Guess("1111");
            }

            // Act/Assert
            underTest.Invoking(x => x.Guess("1111")).Should().Throw <InvalidOperationException>();
        }
Exemple #32
0
        static void Main(string[] args)
        {
            var rand  = new RandomGenerator();
            var inout = new ConsoleInputOutput();
            var game  = new Mastermind(inout, rand);

            var password = args.Length > 0 ? args[0] : null;

            game.Play(password);

            inout.WriteLine("Press any key to quit.");
            inout.Read();
        }
Exemple #33
0
        public void MatchAllColorsWrongPositions()
        {
            Mastermind mastermind = new Mastermind();

            Colors[] selectedColors = new Colors[5] {
                Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple
            };
            mastermind.SetColorSelection(selectedColors);

            Response[] response = mastermind.Guess(Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple, Colors.Red);
            Response[] expected = new Response[] { Response.MATCH_COLOR, Response.MATCH_COLOR, Response.MATCH_COLOR, Response.MATCH_COLOR, Response.MATCH_COLOR };

            Assert.AreEqual(expected, response);
        }
Exemple #34
0
        public void Guess_InputNonNumeric_Throws()
        {
            // Arrange
            string guess1 = "some string",
                   guess2 = "124d",
                   guess3 = " a22";

            var underTest = new Mastermind(new int[] { 1, 2, 3, 4 });

            // Act/Assert
            underTest.Invoking(x => x.Guess(guess1)).Should().Throw <ArgumentException>();
            underTest.Invoking(x => x.Guess(guess2)).Should().Throw <ArgumentException>();
            underTest.Invoking(x => x.Guess(guess3)).Should().Throw <ArgumentException>();
        }
Exemple #35
0
        public void SameColorTwiceOnePositionIsCorrectBothColorsCorrect()
        {
            Mastermind mastermind = new Mastermind();

            Colors[] selectedColors = new Colors[5] {
                Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Red
            };
            mastermind.SetColorSelection(selectedColors);

            Response[] response = mastermind.Guess(Colors.Gray, Colors.Red, Colors.Yellow, Colors.Orange, Colors.Red);
            Response[] expected = new Response[] { Response.NO_MATCH, Response.MATCH_COLOR, Response.NO_MATCH, Response.NO_MATCH, Response.MATCH_POSITION };

            Assert.AreEqual(expected, response);
        }
Exemple #36
0
        public void Match2Positions2Colors()
        {
            Mastermind mastermind = new Mastermind();

            Colors[] selectedColors = new Colors[5] {
                Colors.Red, Colors.Blue, Colors.Green, Colors.Pink, Colors.Purple
            };
            mastermind.SetColorSelection(selectedColors);

            Response[] response = mastermind.Guess(Colors.Red, Colors.Green, Colors.Pink, Colors.Black, Colors.Purple);
            Response[] expected = new Response[] { Response.MATCH_POSITION, Response.MATCH_COLOR, Response.MATCH_COLOR, Response.NO_MATCH, Response.MATCH_POSITION };

            Assert.AreEqual(expected, response);
        }
Exemple #37
0
        private static async ValueTask <IReadOnlyList <Mastermind> > CreateMasterminds(GameServiceClient client, IReadOnlyList <Ability> abilities, IReadOnlyList <GamePackage> packages)
        {
            ConsoleUtility.WriteLine("Creating masterminds");
            List <Mastermind> result = (await MastermindUtility.GetMastermindsAsync(client, null)).ToList();

            if (result.Any())
            {
                return(result);
            }

            foreach (var file in Directory.EnumerateFiles(@"C:\Users\Ryan\SkyDrive\code\LegendaryGameStarter\LegendaryGameModel2\GameSets", s_fileMask))
            {
                var doc = XDocument.Load(file);

                var name = doc.Element("Set").Attribute("Name").Value;
                var activeGamePackage = packages.FirstOrDefault(x => x.Name == name);
                if (activeGamePackage == null)
                {
                    ConsoleUtility.WriteLine($"Failed to find matching game package for {file}");
                }

                foreach (var mastermindElement in doc.Element("Set").Element("Cards").Elements("Card").Where(x => x?.Attribute("Area").Value == "Mastermind"))
                {
                    var request = new CreateMastermindsRequest();
                    request.CreateOptions.Add(CreateOptions.ErrorOnDuplicates);

                    var mastermind = new Mastermind();
                    mastermind.Name          = mastermindElement.Attribute("Name").Value;
                    mastermind.GamePackageId = activeGamePackage.Id;
                    mastermind.AbilityIds.AddRange(GetMatchingItems(mastermindElement.Attribute("Abilities")?.Value, name => abilities.First(x => x.Name == name)).Select(x => x.Id));
                    mastermind.CardRequirements.AddRange(GetCardRequirements(client, mastermindElement, activeGamePackage.Id));
                    mastermind.HasEpicSide = (mastermindElement.Attribute("HasEpicSide")?.Value.ToLower() ?? "false") == "true";

                    request.Masterminds.Add(mastermind);

                    var reply = await client.CreateMastermindsAsync(request);

                    if (reply.Status.Code != 200)
                    {
                        ConsoleUtility.WriteLine($"Failed to create '{mastermind.Name}': {reply.Status.Message}");
                    }

                    result.AddRange(reply.Masterminds);
                }

                ConsoleUtility.WriteLine($"Completed: {name}");
            }

            return(result);
        }
 public static void Main()
 {
     Mastermind game = new Mastermind();
     game.StartGame();
 }