예제 #1
0
        public void MoveOffTheBoard()
        {
            string[] lines =
            {
                "--->",
                "--*-",
                "-*--",
                "-*-e"
            };

            Game game = GameParser.ParseGameSettings(lines);

            Exception exception = null;

            try
            {
                game.Move(Move.Move);
            }
            catch (InvalidMoveException ex)
            {
                exception = ex;
            }

            Assert.IsNotNull(exception);
        }
예제 #2
0
        protected GameBase(string gameInput)
        {
            ListOfKickedPins = new List <int>();
            var gameParser = new GameParser();

            ListOfKickedPins = gameParser.ParseGameInputString(gameInput);
        }
예제 #3
0
        public void Whether_GameParser_ParsesFENGame_On_Parse()
        {
            var parser = new GameParser();
            var result = parser.Parse(fenGame);

            Assert.That(result != null);
        }
예제 #4
0
        public void GameOver()
        {
            string[] lines =
            {
                "->-*",
                "--*-",
                "-*--",
                "-*-e"
            };

            Game game = GameParser.ParseGameSettings(lines);

            game.Move(Move.Move);
            Assert.AreEqual(GameState.InProgress, game.State);

            game.Move(Move.Move);
            Assert.AreEqual(GameState.Dead, game.State);

            Exception exception = null;

            try
            {
                game.Move(Move.Move);
            }
            catch (GameOverException ex)
            {
                exception = ex;
            }

            Assert.IsNotNull(exception);
        }
예제 #5
0
파일: Program.cs 프로젝트: agabuza/chezzles
        static void Main(string[] args)
        {
            using (var context = new GamesStoreContext())
            {
                var parser = new GameParser();
                var repo   = new Repository <GameDTO>(context);
                for (int i = 1; i <= 8; i++)
                {
                    using (var errorLog = new StreamWriter($"..\\..\\puzzles\\errorLog.txt"))
                        using (var reader = new StreamReader($"..\\..\\puzzles\\m2_{i}.pgn"))
                        {
                            var builder = new StringBuilder();
                            var line    = string.Empty;
                            while (!reader.EndOfStream)
                            {
                                builder.Clear();
                                builder.AppendLine(line);
                                while (!reader.EndOfStream && !(line = reader.ReadLine()).Contains("Event"))
                                {
                                    if (line.Contains("Date"))
                                    {
                                        line = line.Replace("-", ".");
                                        line.Replace("\"?\"", "\"????\"");
                                    }

                                    // Skip [Round] as it's not properly parsed by pgn
                                    if (line.Contains("Round"))
                                    {
                                        continue;
                                    }

                                    builder.AppendLine(line);
                                }

                                var text = builder.ToString();
                                text = text.TrimEnd('\r', '\n');
                                try
                                {
                                    foreach (var game in parser.Parse(text))
                                    {
                                        var gameDto = new GameDTO()
                                        {
                                            PgnString = text
                                        };

                                        repo.Insert(gameDto);
                                        repo.Save();
                                    }
                                }
                                catch (Exception ex)
                                {
                                    errorLog.WriteLine($"File m2_{i}.pgn\n Error: {ex.Message}\n While parsing FEN: {text}");
                                }
                            }
                        }
                    Console.WriteLine($"File m2_{i}.pgn processed");
                }
            }
        }
예제 #6
0
        public void NoData()
        {
            string[] lines = { };

            List <Move> moves = GameParser.ParseGameMoves(lines);

            Assert.AreEqual(0, moves.Count);
        }
예제 #7
0
        public void InvalidData()
        {
            string[] lines =
            {
                "TurnAround"
            };

            GameParser.ParseGameMoves(lines);
        }
예제 #8
0
        public void EmptyData()
        {
            string[] lines =
            {
                ""
            };

            GameParser.ParseGameMoves(lines);
        }
예제 #9
0
        public void Whether_Game_ParsesPgnGame_On_Construct()
        {
            var parser = new GameParser();

            var game = parser.Parse(fenGame).FirstOrDefault();

            Assert.That(game.Board != null);
            Assert.That(game.Board.Pieces.Count() == 17);
        }
예제 #10
0
        public void Whether_GameParser_ParsesMultipleGames_On_Parse()
        {
            var parser = new GameParser();

            var result = parser.Parse(gamesPgn);

            Assert.That(result != null);
            Assert.That(result.Count() == 2);
        }
예제 #11
0
    // Start is called before the first frame update
    void Start()
    {
        StreamReader reader = new StreamReader(game_file_path);

        _game = GameParser.ParseFile(reader.ReadToEnd());
        _game.SetDefaultValues();
        Debug.Log($"nodes: {_game.nodes.Count}");
        LoadNode(_game.nodes.First(x => x.NodeType == NodeTypes.START));
    }
예제 #12
0
        public void Whether_GameParser_ParsesIsWhiteMove_On_Parse(string fenGame, bool isWhiteMove)
        {
            var parser = new GameParser();
            var result = parser.Parse(fenGame);

            var game = result.FirstOrDefault();

            Assert.That(game != null);
            Assert.That(game.Board.IsWhiteMove == isWhiteMove);
        }
예제 #13
0
        public void Whether_GameParser_ParsesFENGameMoves_On_Parse()
        {
            var parser = new GameParser();
            var result = parser.Parse(fenBlackMove);

            var game = result.FirstOrDefault();

            Assert.That(game != null);
            Assert.That(game.MoveEntries != null);
            Assert.That(game.MoveEntries.Count() == 3);
        }
예제 #14
0
        public void Success()
        {
            string[] lines =
            {
                ">---",
                "--*-",
                "-*--",
                "-*-e"
            };

            GameParser.ParseGameSettings(lines);
        }
        public void Should_Not_Have_No_Bonus_Balls_When_Frame_Ten_Is_Spare()
        {
            const string bowlingGameStats = "X|X|X|X|X|X|X|X|X|5/||";
            var          sut = new GameParser(new ScoreBoardValidator());

            Action act = () =>
            {
                sut.GenerateScoreBoard(bowlingGameStats);
            };

            act.Should().Throw <InvalidGameInputException>()
            .WithMessage($"Invalid game input {bowlingGameStats}");
        }
        public void A_Bowling_Game_Should_Have_Bonus_Balls_Indicator()
        {
            const string bowlingGameStats = "X|X|X|X|X|X|X|X|X|X";
            var          sut = new GameParser(new ScoreBoardValidator());

            Action act = () =>
            {
                sut.GenerateScoreBoard(bowlingGameStats);
            };

            act.Should().Throw <InvalidGameInputException>()
            .WithMessage($"Invalid game input {bowlingGameStats}");
        }
        public void Should_Not_Have_Sum_Of_Two_Bonus_Balls_Greater_Than_Ten()
        {
            const string bowlingGameStats = "X|X|X|X|X|X|X|X|X|5/||88";
            var          sut = new GameParser(new ScoreBoardValidator());

            Action act = () =>
            {
                sut.GenerateScoreBoard(bowlingGameStats);
            };

            act.Should().Throw <InvalidGameInputException>()
            .WithMessage($"Invalid game input {bowlingGameStats}");
        }
        public void A_FRAME_In_A_Bowling_Game_Should_Not_Have_More_Than_Two_Input()
        {
            const string bowlingGameStats = "X|X|X|X|X|X|234|X|X|X||XX";
            var          sut = new GameParser(new ScoreBoardValidator());

            Action act = () =>
            {
                sut.GenerateScoreBoard(bowlingGameStats);
            };

            act.Should().Throw <InvalidGameInputException>()
            .WithMessage($"Invalid game input {bowlingGameStats}");
        }
        public void A_FRAME_In_A_Bowling_Game_Should_Not_Have_Strike_As_First_Input_Follow_By_Zero_Pins()
        {
            const string bowlingGameStats = "X|X|X|X|X|X|X-|X|X|X||XX";
            var          sut = new GameParser(new ScoreBoardValidator());

            Action act = () =>
            {
                sut.GenerateScoreBoard(bowlingGameStats);
            };

            act.Should().Throw <InvalidGameInputException>()
            .WithMessage($"Invalid game input {bowlingGameStats}");
        }
예제 #20
0
            public void SetUp()
            {
                const string gameText = "1 0 | 2 1 | 3 1 | 4 1 | 5 1 | 6 1 | 7 1 | 8 1 | 9 1 | / 1 1 ";

                _mockFrame = new Frame {
                    RollOne = 1, RollTwo = 0
                };
                var frameParser = Substitute.For <IFrameParser>();

                frameParser.Parse(null).ReturnsForAnyArgs(_mockFrame);
                var subject = new GameParser(frameParser);

                _gameState = subject.Parse(gameText);
            }
예제 #21
0
    public static string Parser(string input)
    {
        if (parserSelect == 0)
        {
            string output = MainMenuParser.Parse(input);
            previousParser = parserSelect;
            parserSelect   = stateChange(output);
            return(output);
        }
        else if (parserSelect == 1)
        {
            string output = GameParser.Parse(input);
            previousParser = parserSelect;
            parserSelect   = stateChange(output);
            return(output);
        }
        else if (parserSelect == 2)
        {
            string output = GameData.saveParser(input);
            previousParser = parserSelect;
            stateChange(output);
            return(output);
        }
        else if (parserSelect == 3)
        {
            string output = GameData.loadParser(input);
            previousParser = parserSelect;
            parserSelect   = stateChange(output);
            return(output);
        }
        else if (parserSelect == 4)
        {
            string output = NewGameParser.Parse(input);
            previousParser = parserSelect;
            parserSelect   = stateChange(output);
            return(output);
        }

        else if (parserSelect == 5)
        {
            string output = GenericCommands.quitParser(input);
            previousParser = parserSelect;
            parserSelect   = stateChange(output);
            return(output);
        }
        else
        {
            return(input);
        }
    }
예제 #22
0
 public static Game ParseAndRunGame(string[] args)
 {
     try
     {
         var game = GameParser.ParseArgsIntoGame(args);
         RunGame(game);
         return(game);
     }
     catch (InvalidOperationException exception)
     {
         HandleInvalidArgument(exception.Message);
         return(null);
     }
 }
예제 #23
0
        public static void PrintScore(string s)
        {
            try
            {
                var gameParser            = new GameParser(new ScoreBoardValidator());
                var bowlingGameScoreBoard = new ScoreBoard(s, gameParser);
                var currentResult         = bowlingGameScoreBoard.GetCurrentScores();

                Console.WriteLine($"\t\t\t\t{currentResult.ScoreType} Score: {currentResult.Score}\n");
            }
            catch (InvalidGameInputException e)
            {
                Console.WriteLine(e.Message);
            }
        }
        public void Should_Generate_ScoreBoard_With_All_Strike_Frames()
        {
            const string bowlingGameStats         = "x|x|X|X|x|x|x|x|x|x||xx";
            const int    minNumberOfThrowPerFrame = 1;
            var          sut = new GameParser(new ScoreBoardValidator());

            var result = sut.GenerateScoreBoard(bowlingGameStats);

            result.Length.Should().Be(InputIndex.NumberOfFramesInBowlingGame);
            foreach (var frame in result)
            {
                frame.NumberOfBonusAcquired.Should().Be(FrameBonus.Strike);
                frame.PinsDroppedOfAThrow.Count().Should().Be(minNumberOfThrowPerFrame);
                frame.PinsDroppedOfABonusBall.Count().Should().Be((int)FrameBonus.Strike);
            }
        }
예제 #25
0
        public void Success()
        {
            string[] lines =
            {
                ">---",
                "--*-",
                "-*--",
                "-*-e"
            };

            Game game = GameParser.ParseGameSettings(lines);

            game.Move(Move.Move);

            Assert.AreEqual(GameState.InProgress, game.State);
        }
예제 #26
0
        public void Whether_Game_NotifiesWhenPuzzleFailed_On_PieceMove()
        {
            var failed = false;
            var parser = new GameParser();
            var result = parser.Parse(fenWhiteMove);
            var game   = result.FirstOrDefault();

            game.PuzzleFailed += (b, m) => failed = true;
            var targetSquare = new Square(7, 7);

            var rook = game.Board.Pieces.FirstOrDefault(x => x.Type == PieceType.Rook &&
                                                        x.PossibleMoves().Contains(targetSquare));

            game.Board.PutPiece(targetSquare, rook);

            Assert.That(failed, Is.True);
        }
예제 #27
0
        public async Task <List <Game> > GetAll()
        {
            var serviceUrl = @"http://chezzles.azurewebsites.net/api/puzzles";
            var uri        = new Uri(serviceUrl);
            var response   = client.GetAsync(uri).Result;

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                var strGames = JsonConvert.DeserializeObject <List <GameDTO> >(content);
                var parser   = new GameParser();
                return(parser.Parse(string.Join(" ", strGames.Select(x => x.PgnString))).ToList());
            }

            return(null);
        }
예제 #28
0
        public override Room Read(string file)
        {
            var value             = File.ReadAllText(Path.Combine(Directory, $"{file}.{FileEnding}")).Split(':');
            var gameObjectsString = value[1];

            int.TryParse(value[0], out int id);

            var room        = new Room(id);
            var gameObjects = GameParser.DeserializeObjectList <GameObject>(gameObjectsString);

            foreach (var obj in gameObjects)
            {
                room.Add(new DrawableGameObject(obj));
            }

            return(room);
        }
예제 #29
0
        public async Task <Game> GetById(int id)
        {
            var serviceUrl = @"http://chezzles.azurewebsites.net/api/puzzles/{0}";
            var uri        = new Uri(string.Format(serviceUrl, id));
            var response   = client.GetAsync(uri).Result;

            if (response.IsSuccessStatusCode)
            {
                var content = await response.Content.ReadAsStringAsync();

                var strGame = JsonConvert.DeserializeObject <GameDTO>(content);
                var parser  = new GameParser();
                return(parser.Parse(strGame.PgnString).FirstOrDefault());
            }

            return(null);
        }
예제 #30
0
        public void Test_Game_With_Two_Throws_Spare()
        {
            //-- Arrange
            TenPinsGame game          = new TenPinsGame();
            GameParser  gameParser    = new GameParser();
            List <int>  intInputList  = gameParser.ParseGameInputString("1, 9");
            int         expectedScore = 0;
            int         actualScore   = 0;

            //-- Act
            foreach (var input in intInputList)
            {
                actualScore = game.Bowl(input);
            }

            //-- Assert
            Assert.AreEqual(expectedScore, actualScore);
        }
예제 #31
0
        public void switchEmulator()
        {
            GameParser gp = new GameParser ();
            switch (currentEmulator) {
            case 0:
                gameList = gp.loadMame (ConfigurationSettings.AppSettings ["MameInfos"]);
                gameList = gp.filterMameRoms (gameList, ConfigurationSettings.AppSettings ["MameRomFolder"]);
                break;
            case 1:
                gameList = gp.loadSnes (ConfigurationSettings.AppSettings ["SnesInfos"]);
                gameList = gp.filterSnesRoms (gameList, ConfigurationSettings.AppSettings ["SnesRomFolder"]);
                break;
            default:
                gameList = gp.loadMame (ConfigurationSettings.AppSettings ["MameInfos"]);
            //gameList = gp.filterMameRoms(gameList,ConfigurationSettings.AppSettings["MameRomFolder"]);
                break;
            }

            currentIndex = 0;
        }