Ejemplo n.º 1
0
        internal Game GetEmptyGame()
        {
            var pgn = new Pgn();

            pgn.Add("1.e4 c5 2.Nf3 d6 3.d4 cxd4 4.Nxd4 Nf6 5.Nc3 a6 6.Be3 e5 7.Nb3 Be7 8.f3 Be6");
            pgn.Add("9.Qd2 O-O 10.O-O-O a5 11.a4 Nc6 12.g4 Nb4 13.Kb1 Qc7 14.Bb5 Rac8 15.g5 Nh5");
            pgn.Add("16.Rhg1 g6 17.Qf2 Bd8 18.Qd2 Be7 19.Qf2 Bd8 20.Qd2 Be7 21.Qf2 1/2-1/2");

            return(new Game(new Metadata(), pgn));
        }
Ejemplo n.º 2
0
        public void ReadGame(Action <Game> returnGame)
        {
            var metadata = new Metadata();
            var pgn      = new Pgn();
            var files    = Directory.EnumerateFiles(_folder, "*.pgn", SearchOption.AllDirectories);

            foreach (var file in files)
            {
                using (var reader = new StreamReader(file))
                {
                    string line;

                    while ((line = reader.ReadLine()) != null)
                    {
                        if (ContainsMetadata(line))
                        {
                            metadata.Add(line);
                        }

                        if (ContainsMoves(line))
                        {
                            pgn.Add(line);
                        }

                        if (ContainsResultAtTheEnd(line) && !ContainsMoves(line))
                        {
                            pgn.Add(line);
                        }

                        if (ContainsResultAtTheEnd(line))
                        {
                            returnGame(new Game(metadata, pgn)
                            {
                                Source = file
                            });
                            metadata = new Metadata();
                            pgn      = new Pgn();
                        }


                        if (!ContainsMetadata(line) && !ContainsMoves(line) &&
                            !ContainsResultAtTheEnd(line) && !ContainsEmpty(line))
                        {
                            metadata = new Metadata();
                            pgn      = new Pgn();
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public TestFixture()
        {
            FakeReader = Substitute.For <IReadPgnFiles>();
            FakeWriter = Substitute.For <IWritePgnFiles>();
            FakeRepo   = Substitute.For <IGameRepository>();
            FakeLogger = Substitute.For <ILogger>();

            PgnWithAtLeast15Moves = new Pgn();
            PgnWithAtLeast15Moves.Add("1.e4 e5 2.Bc4 Bc5 3.c3 Nf6 4.d4 exd4 5.cxd4 Bb6 6.Nc3 O-O 7.Nge2 c6 8.Bd3 d5 9.e5 Ne8 10.Be3 f6 11.Qd2 fxe5 12.dxe5 Be6 13.Nf4 Qe7 14.Bxb6 axb6 15.O-O Nd7");

            PgnWithLessThan15Moves = new Pgn();
            PgnWithLessThan15Moves.Add("1.e4 e5 2.Bc4 Bc5 3.c3 Nf6 4.d4 exd4 5.cxd4 Bb6 6.Nc3 O-O 7.Nge2 c6 8.Bd3 d5");
        }
Ejemplo n.º 4
0
        public void Add_should_replace_star_with_draw()
        {
            // Arrange
            var pgn    = new Pgn();
            var spaces = GenerateRandomSpaces();

            var line     = $"1. d4 Nf6 2. c4 e6 3. Nf3 d5 4. g3 dxc4 5. Bg2 c6 *";
            var withDraw = "1.d4 Nf6 2.c4 e6 3.Nf3 d5 4.g3 dxc4 5.Bg2 c6 1/2-1/2 ";

            // Act
            pgn.Add(line);

            // Assert
            pgn.Moves.ShouldBe(withDraw);
        }
Ejemplo n.º 5
0
        public void Add_should_remove_space_after_dot()
        {
            // Arrange
            var pgn    = new Pgn();
            var spaces = GenerateRandomSpaces();

            var line          = $"1. d4 Nf6 2. c4 e6 3. Nf3 d5 4. g3 dxc4 5. Bg2 c6";
            var withoutSpaces = "1.d4 Nf6 2.c4 e6 3.Nf3 d5 4.g3 dxc4 5.Bg2 c6 ";

            // Act
            pgn.Add(line);

            // Assert
            pgn.Moves.ShouldBe(withoutSpaces);
        }
Ejemplo n.º 6
0
        internal Game GetGame()
        {
            var metadata = new Metadata();

            metadata.Add("[Event \"Gibraltar Masters 2017\"]");
            metadata.Add("[Site \"Caleta ENG\"]");
            metadata.Add("[Date \"2017.01.29\"]");
            metadata.Add("[Round \"6.65\"]");
            metadata.Add("[White \"Heinemann, Josefine\"]");
            metadata.Add("[Black \"Tsolakidou, Stavroula\"]");
            metadata.Add("[Result \"1/2-1/2\"]");
            metadata.Add("[WhiteElo \"2227\"]");
            metadata.Add("[BlackElo \"2387\"]");
            metadata.Add("[ECO \"B90\"]");
            metadata.Add("[EventDate \"2017.01.24\"]");

            var pgn = new Pgn();

            pgn.Add("1.e4 c5 2.Nf3 d6 3.d4 cxd4 4.Nxd4 Nf6 5.Nc3 a6 6.Be3 e5 7.Nb3 Be7 8.f3 Be6");
            pgn.Add("9.Qd2 O-O 10.O-O-O a5 11.a4 Nc6 12.g4 Nb4 13.Kb1 Qc7 14.Bb5 Rac8 15.g5 Nh5");
            pgn.Add("16.Rhg1 g6 17.Qf2 Bd8 18.Qd2 Be7 19.Qf2 Bd8 20.Qd2 Be7 21.Qf2 1/2-1/2");

            return(new Game(metadata, pgn));
        }
Ejemplo n.º 7
0
        public void PlyCount_should_count_all_moves_of_the_game()
        {
            // Arrange
            var line = "1.d4 Nf6 2.c4 e6 3.Nf3 d5 4.g3 dxc4 5.Bg2 c6";
            var pgn  = new Pgn();

            pgn.Add(line);


            // Act
            var game = new Game(new Metadata(), pgn);

            // Assert
            game.PlyCount.ShouldBe(10);
        }
Ejemplo n.º 8
0
        public void ToString_should_add_empty_line_between_metadata_and_moves()
        {
            // Arrange
            var line  = "[Event \"11th Kings Rapid women\"]";
            var moves = "1.d4 Nf6 2.c4 e6 3.Nf3 d5 4.g3 dxc4 5.Bg2 c6 ";
            var emptyLineInBetween = $"{line}{Environment.NewLine}[PlyCount \"10\"]{Environment.NewLine}{Environment.NewLine}{moves}";

            var metadata = new Metadata();

            metadata.Add(line);

            var pgn = new Pgn();

            pgn.Add(moves);

            var game = new Game(metadata, pgn);

            // Act
            var text = game.ToString();

            // Assert
            text.ShouldBe(emptyLineInBetween);
        }