Ejemplo n.º 1
0
        public static ICodemaker CreateCodemaker(IGameOptions options, ICodemaker lastCodemaker)
        {
            var type = ShellEx.PromptPlayerType("Codemaker", lastCodemaker?.Type);

            ShellEx.WriteKeyValue("Codemaker", type.ToString().ToLower());

            switch (type)
            {
            case PlayerType.Human:
                return(new HumanCodemaker(options));

            case PlayerType.Computer:
                PegPattern code;
                var        codeType = Shell.PromptEnum <ComputerCodeType>("Choose secret code", ComputerCodeType.Random);
                switch (codeType)
                {
                case ComputerCodeType.Random:
                    code = options.Palette.GetRandomPattern(options);
                    break;

                case ComputerCodeType.Custom:
                    code = ShellEx.PromptPegPattern("Enter secret code", options);
                    break;

                default:
                    throw new Exception($"Unknown code type");
                }
                ShellEx.WriteKeyValue("Code", codeType.ToString().ToLower());
                return(new ComputerCodemaker(options, code));

            default: throw new Exception($"Unknown player type: {type}");
            }
        }
Ejemplo n.º 2
0
        private static GameOptions CreateGameOptions(GameOptions lastOptions)
        {
            var options = new GameOptions();

            options.Palette = new Palette(Shell.PromptInt("Number of peg color", lastOptions?.Palette.PegCount ?? 6, (1, 10)));
            ShellEx.WriteKeyValue("Peg colors", options.Palette.PegCount);

            options.AllowDuplicates = Shell.PromptBool("Allow duplicates", lastOptions?.AllowDuplicates ?? true);
            ShellEx.WriteKeyValue("Duplicates", options.AllowDuplicates ? "yes" : "no");

            var maxSize = options.AllowDuplicates ? 10 : options.Palette.PegCount;

            options.Size = Shell.PromptInt("Length of secret code", Math.Min(maxSize, lastOptions?.Size ?? 4), (1, maxSize));
            ShellEx.WriteKeyValue("Code length", options.Size);

            if (!CheckExecutionTime(options.Palette.PegCount, options.Size))
            {
                return(null);
            }
            return(options);
        }
Ejemplo n.º 3
0
        public static ICodebreaker CreateCodebreaker(IGameOptions options, ICodebreaker lastCodebreaker)
        {
            var type = ShellEx.PromptPlayerType("Codebreaker", lastCodebreaker?.Type);

            ShellEx.WriteKeyValue("Codebreaker", type.ToString().ToLower());

            switch (type)
            {
            case PlayerType.Human:
                return(new HumanCodebreaker(options));

            case PlayerType.Computer:
                PegPattern initialGuess;
                var        initialGuessType = Shell.PromptEnum <ComputerInitialGuessType>("Choose initial guess", ComputerInitialGuessType.Default);
                switch (initialGuessType)
                {
                case ComputerInitialGuessType.Default:
                    initialGuess = null;
                    break;

                case ComputerInitialGuessType.Random:
                    initialGuess = options.Palette.GetRandomPattern(options);
                    break;

                case ComputerInitialGuessType.Custom:
                    initialGuess = ShellEx.PromptPegPattern("Enter initial guess", options);
                    break;

                default:
                    throw new Exception($"Unknown initial guess type");
                }
                ShellEx.WriteKeyValue("Initial guess", initialGuessType.ToString().ToLower());
                return(new ComputerCodebreaker(options, initialGuess));

            default: throw new Exception($"Unknown player type: {type}");
            }
        }