コード例 #1
0
        public void TestValid(string sentence, string[] colors)
        {
            var parser  = CreateParser();
            var builder = new GameDefinitionBuilder();

            (new BoardGrid()).Parse(builder, "The board is an 8x8 grid", out _);

            var didMatch = parser.Parse(builder, sentence, out ParserError[] errors);

            Assert.True(didMatch);
            Assert.Empty(errors);

            var definition = builder.Build();

            Assert.Single(definition.Boards);

            var board  = definition.Boards[0];
            int iColor = 0;

            foreach (var cell in board.Cells)
            {
                Assert.Equal(cell.Color, colors[iColor++]);

                if (iColor >= colors.Length)
                {
                    iColor = 0;
                }
            }
        }
コード例 #2
0
ファイル: BoardGridTests.cs プロジェクト: FTWinston/GameRules
        public override void TestDefaults()
        {
            var builder    = new GameDefinitionBuilder();
            var definition = builder.Build();

            Assert.Empty(definition.Boards);
        }
コード例 #3
0
        public override void TestDefaults()
        {
            var builder    = new GameDefinitionBuilder();
            var definition = builder.Build();

            Assert.Equal(2, definition.Players.Count(player => player.Required));
            Assert.Equal(2, definition.Players.Length);
        }
コード例 #4
0
        public override void TestDefaults()
        {
            var builder    = new GameDefinitionBuilder();
            var definition = builder.Build();

            Assert.Equal(2, definition.Players.Length);
            Assert.Equal("red", definition.Players[0].Color);
            Assert.Equal("blue", definition.Players[1].Color);
        }
コード例 #5
0
        public override void TestDefaults()
        {
            var builder    = new GameDefinitionBuilder();
            var definition = builder.Build();

            Assert.Equal(2, definition.Players.Length);
            Assert.Equal("Player 1", definition.Players[0].Name);
            Assert.Equal("Player 2", definition.Players[1].Name);
        }
コード例 #6
0
        public override void TestDefaults()
        {
            var builder = new GameDefinitionBuilder();

            (new BoardGrid()).Parse(builder, "The board is a 2x2 grid", out _);

            var definition = builder.Build();

            Assert.Single(definition.Boards);

            var board = definition.Boards[0];

            Assert.True(board.AllowMultipleOccupancy);
        }
コード例 #7
0
        public IEnumerable <ParserError> Parse([FromBody] ParserData data)
        {
            var parser  = new GameDefinitionParser();
            var builder = new GameDefinitionBuilder();

            var errors = parser.Parse(builder, data.Text);

            if (errors.Count == 0)
            {
                var definition = builder.Build();
                // TODO: use definition somehow
            }

            return(errors);
        }
コード例 #8
0
        public void TestValid(string sentence, int min, int max)
        {
            var parser  = CreateParser();
            var builder = new GameDefinitionBuilder();

            var didMatch = parser.Parse(builder, sentence, out ParserError[] errors);

            Assert.True(didMatch);
            Assert.Empty(errors);

            var definition = builder.Build();

            Assert.Equal(min, definition.Players.Count(player => player.Required));
            Assert.Equal(max, definition.Players.Length);
        }
コード例 #9
0
        public override void TestDefaults()
        {
            var builder = new GameDefinitionBuilder();

            (new BoardGrid()).Parse(builder, "The board is a 2x2 grid", out _);

            var definition = builder.Build();

            Assert.Single(definition.Boards);

            var board = definition.Boards[0];

            Assert.Equal(0, board.BorderWidth);
            Assert.Null(board.BorderColor);
        }
コード例 #10
0
        public void TestCombo()
        {
            var text = @"
There are 3 players.
Player names are attacker, neutral and defender.
Player colors are red, #cccccc and blue.

The board is an 8x8 grid. Only one piece can occupy a cell on the board.
Cells on the board are referenced using a letter for their row and a number for their column, starting with A1 at the southwest corner.
Cells on the board are alternately colored black and white.
Cells on the board have a thin grey border.
";

            var parser  = new GameDefinitionParser();
            var builder = new GameDefinitionBuilder();

            var errors = parser.Parse(builder, text);

            Assert.Empty(errors);

            var definition = builder.Build();

            Assert.Equal(3, definition.Players.Count(player => player.Required));
            Assert.Equal(3, definition.Players.Length);

            Assert.Equal("attacker", definition.Players[0].Name);
            Assert.Equal("red", definition.Players[0].Color);

            Assert.Equal("neutral", definition.Players[1].Name);
            Assert.Equal("#cccccc", definition.Players[1].Color);

            Assert.Equal("defender", definition.Players[2].Name);
            Assert.Equal("blue", definition.Players[2].Color);

            Assert.Single(definition.Boards);

            var board = definition.Boards[0];

            Assert.Equal(64, board.Cells.Length);
            Assert.Equal("grey", board.BorderColor);
            Assert.Equal(1, board.BorderWidth);

            for (int iCell = 0; iCell < board.Cells.Length; iCell++)
            {
                Assert.Equal(board.Cells[iCell].Color, iCell % 2 == 0 ? "black" : "white");
            }
        }
コード例 #11
0
        public override void TestDefaults()
        {
            var builder = new GameDefinitionBuilder();

            (new BoardGrid()).Parse(builder, "The board is a 2x2 grid", out _);

            var definition = builder.Build();

            Assert.Single(definition.Boards);

            var board = definition.Boards[0];

            foreach (var cell in board.Cells)
            {
                Assert.Equal("grey", cell.Color);
            }
        }
コード例 #12
0
        public void TestValid(string sentence, string[] names)
        {
            var parser  = CreateParser();
            var builder = new GameDefinitionBuilder();

            (new PlayerCount()).Parse(builder, $"There are {names.Length} players", out _);

            var didMatch = parser.Parse(builder, sentence, out ParserError[] errors);

            Assert.True(didMatch);
            Assert.Empty(errors);

            var definition = builder.Build();

            for (int i = 0; i < definition.Players.Length && i < names.Length; i++)
            {
                Assert.Equal(names[i], definition.Players[i].Name);
            }
        }
コード例 #13
0
ファイル: BoardGridTests.cs プロジェクト: FTWinston/GameRules
        public void TestValid(string sentence, int width, int height)
        {
            var parser  = CreateParser();
            var builder = new GameDefinitionBuilder();

            var didMatch = parser.Parse(builder, sentence, out ParserError[] errors);

            Assert.True(didMatch);
            Assert.Empty(errors);

            var definition = builder.Build();

            Assert.Single(definition.Boards);

            var board = definition.Boards[0];

            Assert.Equal(width * height, board.Cells.Length);
            // TODO: need separate width and height checks
        }
コード例 #14
0
        public void TestValid(string sentence, bool allowMultiple)
        {
            var parser  = CreateParser();
            var builder = new GameDefinitionBuilder();

            (new BoardGrid()).Parse(builder, "The board is a 2x2 grid", out _);

            var didMatch = parser.Parse(builder, sentence, out ParserError[] errors);

            Assert.True(didMatch);
            Assert.Empty(errors);

            var definition = builder.Build();

            Assert.Single(definition.Boards);

            var board = definition.Boards[0];

            Assert.Equal(board.AllowMultipleOccupancy, allowMultiple);
        }
コード例 #15
0
        public void TestValid(string sentence, string color, int thickness)
        {
            var parser  = CreateParser();
            var builder = new GameDefinitionBuilder();

            (new BoardGrid()).Parse(builder, "The board is an 8x8 grid", out _);

            var didMatch = parser.Parse(builder, sentence, out ParserError[] errors);

            Assert.True(didMatch);
            Assert.Empty(errors);

            var definition = builder.Build();

            Assert.Single(definition.Boards);

            var board = definition.Boards[0];

            Assert.Equal(board.BorderColor, color);
            Assert.Equal(board.BorderWidth, thickness);
        }