Esempio n. 1
0
        public void MultipleMoveSequencesAreRun()
        {
            var game = new GameChallenge(Output.Object);

            game.Play(ValidSettings, "[[\"Rotate\"],[\"Rotate\"],[\"Rotate\"]]");
            Output.Verify(x => x.Start(It.IsAny <int>()), Times.Exactly(3));
        }
Esempio n. 2
0
        public void InvalidMovesOutputsAnError()
        {
            var game = new GameChallenge(Output.Object);

            game.Play(ValidSettings, "[[],[],[]]");
            Output.Verify(x => x.Error(It.Is <string>(m => m.Equals("Error loading game moves from file, no moves defined"))), Times.Once);
        }
Esempio n. 3
0
        public void ValidSettingsRunASequence()
        {
            var game = new GameChallenge(Output.Object);

            game.Play(ValidSettings, ValidMoves);
            Output.Verify(x => x.Start(It.IsAny <int>()), Times.Once);
        }
Esempio n. 4
0
        public void InvalidSettingsOutputsAnError()
        {
            var game = new GameChallenge(Output.Object);

            game.Play("{}", ValidMoves);
            Output.Verify(x => x.Error(It.Is <string>(m => m.Equals("Settings contain invalid values"))), Times.Once);
        }
Esempio n. 5
0
        public void MalformedMovesJsonOutputsAnError()
        {
            var game = new GameChallenge(Output.Object);

            game.Play(ValidSettings, "abc");
            Output.Verify(x => x.Error(It.Is <string>(m => m.Equals("Error loading game moves from file, please check they are in correct format"))), Times.Once);
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            if (args.Length != 2)
            {
                throw new ArgumentException("Game should have at 2 parameters: <settings> file and <moves> files.\nRun: TurtleChallengeCSharp.EXE <SettingsFileName> <MovesFileName>");
            }

            if (!File.Exists(args[0]))
            {
                throw new FileNotFoundException("Settings file not found: " + args[0]);
            }

            if (!File.Exists(args[1]))
            {
                throw new FileNotFoundException("Moves file not found: " + args[1]);
            }

            var settingsJson = File.ReadAllText(args[0]);
            var movesJson    = File.ReadAllText(args[1]);

            var game = new GameChallenge();

            game.Play(settingsJson, movesJson);

            Console.WriteLine("Press any key...");
            Console.ReadKey();
        }
Esempio n. 7
0
        public void MalformedSettingsJsonOutputsAnError()
        {
            var game = new GameChallenge(Output.Object);

            game.Play("abc", ValidMoves);
            Output.Verify(x => x.Error(It.Is <string>(m => m.Equals("Could not load settings from file, please check that data is correct format"))), Times.Once);
        }
Esempio n. 8
0
        public void ResolveChallenge(GameChallenge challenge)
        {
            var    currentPlayer = this.gameState.CurrentPlayer;
            string resolution    = currentPlayer is GamePlayerBot?
                                   this.botService.ResolveChallenge(challenge) :
                                       this.view.ResolveChallenge(currentPlayer.Name, challenge.ChallengeLetter);

            challenge.Suggest(resolution);
        }
Esempio n. 9
0
        public string ResolveChallenge(GameChallenge challenge)
        {
            var letter         = challenge.ChallengeLetter;
            var words          = this.wordStorage.GetWords(letter);
            var usedWords      = this.gameState.ChallengeHistory.Select(ch => ch.ChallengeResolution);
            var suggestedWords = this.gameState.ChallengeHistory.SelectMany(ch => ch.HistoryOfSuggestedResolutions);

            var feasibleWords = words
                                .Where(word => usedWords.All(usedWord => !string.Equals(usedWord, word, StringComparison.InvariantCultureIgnoreCase)))
                                .Where(word => suggestedWords.All(suggestedWord => !string.Equals(suggestedWord, word, StringComparison.InvariantCultureIgnoreCase)))
                                .ToList();

            var wordIndex = this.random.Next(0, feasibleWords.Count - 1);

            return(feasibleWords[wordIndex]);
        }
Esempio n. 10
0
        public bool ApproveResolution(GameChallenge challenge)
        {
            var agreed        = true;
            var currentPlayer = this.gameState.CurrentPlayer;

            foreach (var player in this.gameState.Players)
            {
                if (player == currentPlayer || player is GamePlayerBot)
                {
                    continue;
                }

                if (!this.view.ApproveResolution(player.Name, challenge.CurrentSuggestedResolution, this.gameState.CurrentPlayer.Name))
                {
                    agreed = false;
                    break;
                }
            }

            return(agreed);
        }
Esempio n. 11
0
        public void SuccessResult()
        {
            var game     = new GameChallenge(Output.Object);
            var settings = new Settings
            {
                StartPosition = new Coordinates {
                    X = 1, Y = 1
                },
                StartDirection = Direction.North,
                Exit           = new Coordinates {
                    X = 1, Y = 2
                },
                Height = 3,
                Width  = 3,
                Mines  = new List <Coordinates> {
                    new Coordinates {
                        X = 0, Y = 0
                    }
                }
            };

            game.Play(JsonConvert.SerializeObject(settings), "[[\"Move\"]]");
            Output.Verify(x => x.Won(), Times.Once);
        }
Esempio n. 12
0
        public void MoveUpdatesPosition(Direction startDirection, int expectedX, int expectedY)
        {
            var game     = new GameChallenge(Output.Object);
            var settings = new Settings
            {
                StartPosition = new Coordinates {
                    X = 1, Y = 1
                },
                StartDirection = startDirection,
                Exit           = new Coordinates {
                    X = 2, Y = 2
                },
                Height = 3,
                Width  = 3,
                Mines  = new List <Coordinates> {
                    new Coordinates {
                        X = 1, Y = 2
                    }
                }
            };

            game.Play(JsonConvert.SerializeObject(settings), "[[\"Move\"]]");
            Output.Verify(x => x.Moved(It.Is <Coordinates>(m => m.Y == expectedY && m.X == expectedX)), Times.Once);
        }
Esempio n. 13
0
        public void RoteUpdatesDirection(Direction startDirection, Direction expectedDirection)
        {
            var game     = new GameChallenge(Output.Object);
            var settings = new Settings
            {
                StartPosition = new Coordinates {
                    X = 1, Y = 1
                },
                StartDirection = startDirection,
                Exit           = new Coordinates {
                    X = 2, Y = 2
                },
                Height = 3,
                Width  = 3,
                Mines  = new List <Coordinates> {
                    new Coordinates {
                        X = 1, Y = 2
                    }
                }
            };

            game.Play(JsonConvert.SerializeObject(settings), "[[\"Rotate\"]]");
            Output.Verify(x => x.Rotated(It.Is <Direction>(m => m == expectedDirection)), Times.Once);
        }