protected override bool CheckRequest(Map map)
        {
            AbstractField position = map.GetPlayerById(_agentId).Position;

            _playerAlreadyHasPiece = map.GetPlayerById(_agentId).Holding != null;
            if (_playerAlreadyHasPiece)
            {
                return(false);
            }
            _fieldIsOnGoalArea = map.IsInsideBlueGoalArea(position) || map.IsInsideRedGoalArea(position);
            if (_fieldIsOnGoalArea)
            {
                return(false);
            }
            _noPieceOnField = !position.ContainsPieces();
            if (_noPieceOnField)
            {
                return(false);
            }
            return(true);
        }
Exemple #2
0
        public void TestInitGame()
        {
            // Arrange
            var conf       = new MockGameConfiguration();
            var queue      = new BufferBlock <Message>();
            var lifetime   = Mock.Of <IApplicationLifetime>();
            var client     = new TcpSocketClient <Message, Message>(logger);
            var gameMaster = new GM(lifetime, conf, queue, client, logger);

            // Act
            gameMaster.Invoke("InitGame");

            // Assert
            Assert.True(gameMaster.WasGameInitialized);

            int redGoalFieldsCount  = 0;
            int blueGoalFieldsCount = 0;
            int taskFieldsCount     = 0;
            int piecesCount         = 0;
            var board = gameMaster.GetValue <GM, AbstractField[][]>("board");

            for (int i = 0; i < board.Length; ++i)
            {
                for (int j = 0; j < board[i].Length; ++j)
                {
                    AbstractField field = board[i][j];
                    if (field is GoalField)
                    {
                        if (i < conf.GoalAreaHeight)
                        {
                            ++redGoalFieldsCount;
                        }
                        else if (i >= gameMaster.SecondGoalAreaStart)
                        {
                            ++blueGoalFieldsCount;
                        }
                        else
                        {
                            Assert.True(false, "Goal field should be on correct position");
                        }

                        if (field.ContainsPieces())
                        {
                            Assert.True(false, "Goal field should not contain any pieces");
                        }
                    }
                    else if (field is TaskField taskField)
                    {
                        ++taskFieldsCount;
                        if (field.ContainsPieces())
                        {
                            piecesCount += GetPieceCount(taskField);
                        }
                    }
                }
            }

            Assert.True(conf.NumberOfGoals == redGoalFieldsCount,
                        $"Number of red goal fields should match configuration setting.\n" +
                        $"Have: {redGoalFieldsCount}\n" +
                        $"Expected: {conf.NumberOfGoals}");
            Assert.True(conf.NumberOfGoals == blueGoalFieldsCount,
                        $"Number of red goal fields should match configuration setting.\n" +
                        $"Have: {blueGoalFieldsCount}\n" +
                        $"Expected: {conf.NumberOfGoals}");

            int expectedTaskFieldsCount = (conf.Height - (2 * conf.GoalAreaHeight)) * conf.Width;

            Assert.True(expectedTaskFieldsCount == taskFieldsCount,
                        "Task fields should cover all fields except goal areas.\n" +
                        $"Have: {taskFieldsCount}\n" +
                        $"Expected: {expectedTaskFieldsCount}");

            Assert.True(conf.NumberOfPiecesOnBoard == piecesCount,
                        "GM should generate enough pieces.\n" +
                        $"Have: {piecesCount}\n" +
                        $"Expected: {conf.NumberOfPiecesOnBoard}");
        }