示例#1
0
        private static async Task <PGNMetadata> GetPGN(string fileName)
        {
            var serializer = new PGNSerializer();

            using var file   = File.OpenRead(fileName);
            using var reader = new StreamReader(file);

            return(await serializer.DeserializeAsync(reader));
        }
示例#2
0
        public async Task ReplayedGameEndsInCheckmate(string scenario)
        {
            var pgnSerializer = new PGNSerializer();

            using var stream = ResourceHelpers.GetEmbeddedPGNStream(scenario);
            var pgn = await pgnSerializer.DeserializeAsync(new StreamReader(stream));

            var game = new Game();

            foreach (var move in pgn.Moves)
            {
                var result = game.Move(move);
                Warn.If(result, Is.Not.EqualTo(ErrorCondition.None), $"Unexpected result for move {move}");
            }

            Assert.That(game.AttackState, Is.EqualTo(AttackState.Checkmate));
        }
示例#3
0
        public async Task ReplayedGameMatchesExpectedFEN(string scenario)
        {
            var pgnSerializer = new PGNSerializer();

            using var stream = ResourceHelpers.GetEmbeddedPGNStream(scenario);
            var pgn = await pgnSerializer.DeserializeAsync(new StreamReader(stream));

            var expectedFen = Scenarios.FinalPositions[scenario];

            var game = new Game();

            foreach (var move in pgn.Moves)
            {
                var result = game.Move(move);
                Warn.If(result, Is.Not.EqualTo(ErrorCondition.None), $"Unexpected result for move {move}");
            }

            var fenSerializer = new FenSerializer();
            var actualFen     = fenSerializer.Serialize(game.CurrentState.Board);

            Assert.That(actualFen, Is.EqualTo(expectedFen));
        }