def move_to_dir(self, dir, fr, to, step):
        self.setUp()

        # Add and move player to middle of board
        msg = m.JoinGame(id=uuid.uuid4(), preferred_team='red', type='player')
        self.gm.join_game(msg)

        pl = self.gm.red_team[0]

        mid_x = int(self.gm.board.board_width / 2)
        mid_y = int(self.gm.board.board_height / 2)

        sq = self.gm.board.get_square(pl.x, pl.y)
        mid_sq = self.gm.board.get_square(mid_x, mid_y)

        pl.move(sq, mid_sq)

        # Moving in dir to the end
        for _ in range(fr, to, step):
            msg = m.Move(id=pl.id, direction=dir)
            self.gm.move_player(msg)

            res = current_msg.result
            self.assertEqual(res, 'OK')

        # Now should not be able to go more in the given direction
        msg = m.Move(id=pl.id, direction=dir)
        self.gm.move_player(msg)

        res = current_msg.result
        self.assertNotEqual(res, dir)
Example #2
0
 def connectionMade(self):
     global team
     msg = m.JoinGame(id=self.id, preferred_team=team, type='player')
     self.bot = b.Bot(id=self.id,
                      teamPref=team,
                      callback=self.pass_to_server)
     self.pass_to_server(msg)
    def test_join_game(self):
        pl = player.GmPlayer(id=uuid.uuid4(), team='blue')
        msg = m.JoinGame(id=pl.id, preferred_team='red', type='player')

        self.gm.join_game(msg)

        self.assertIn(pl.id, self.gm.players)
 def fill_game(self):
     # Fill game with players
     for _ in range(self.settings.player_count_per_team * 2):
         self.gm.join_game(
             m.JoinGame(id=uuid.uuid4(),
                        preferred_team='blue',
                        type='player'))
Example #5
0
    def test_deregister_exchange(self):
        # Add recipient to game
        pl_to = player.GmPlayer(id=uuid.uuid4(), team='red')
        self.external.gm.join_game(
            m.JoinGame(id=pl_to.id, preferred_team='red', type='player'))

        # Init exchange
        from_id = uuid.uuid4()
        to_id = pl_to.id
        msg = m.AuthorizeKnowledgeExchange(userGuid=from_id,
                                           receiverGuid=to_id)

        self.external.register_exchange(msg)

        # Reject exchange, single
        msg = m.RejectKnowledgeExchange(id=from_id, rejectDuration='single')
        self.external.deregister_exchange(msg)

        # Check that it has been removed
        self.assertEqual(len(self.external.exchange_storage), 0)

        # Init exchange
        msg = m.AuthorizeKnowledgeExchange(userGuid=from_id,
                                           receiverGuid=to_id)

        self.external.register_exchange(msg)

        # Reject exchange, permanent
        msg = m.RejectKnowledgeExchange(id=from_id, rejectDuration='permanent')
        self.external.deregister_exchange(msg)

        # Check that it has been added to permanent exclusion
        self.assertEqual(len(self.external.disabled_exchanges), 1)
Example #6
0
    def test_storing_knowledge_data(self):
        # Add recipient to game
        pl_to = player.GmPlayer(id=uuid.uuid4(), team='red')
        self.external.gm.join_game(
            m.JoinGame(id=pl_to.id, preferred_team='red', type='player'))

        msg = m.KnowledgeExchangeData(id=uuid.uuid4(), to=pl_to.id, fields=[])

        self.external.store_knowledge_data(msg)

        # Don't store if unknown exchange
        self.assertEqual(len(self.external.exchange_storage), 0)

        # Init exchange
        from_id = uuid.uuid4()
        to_id = pl_to.id
        msg = m.AuthorizeKnowledgeExchange(userGuid=from_id,
                                           receiverGuid=to_id)

        self.external.register_exchange(msg)

        msg = m.KnowledgeExchangeData(id=uuid.uuid4(),
                                      to=uuid.uuid4(),
                                      fields=[])

        self.external.store_knowledge_data(msg)

        # Check that the data is stored
        self.assertEqual(len(self.external.exchange_storage), 1)
    def test_deny_join_game(self):
        self.fill_game()
        msg = m.JoinGame(id=uuid.uuid4, preferred_team='red', type='player')

        self.gm.join_game(msg)

        res = current_msg.result
        self.assertEqual(res, 'denied')
    def test_move_over_player(self):
        self.setUp()

        # Add and move player to middle of board
        msg = m.JoinGame(id=uuid.uuid4(), preferred_team='red', type='player')
        self.gm.join_game(msg)

        pl1 = self.gm.red_team[0]

        mid_x = int(self.gm.board.board_width / 2)
        mid_y = int(self.gm.board.board_height / 2)

        sq = self.gm.board.get_square(pl1.x, pl1.y)
        mid_sq = self.gm.board.get_square(mid_x, mid_y)

        pl1.move(sq, mid_sq)

        # Add and move player to middle of board
        msg = m.JoinGame(id=uuid.uuid4(), preferred_team='blue', type='player')
        self.gm.join_game(msg)

        pl2 = self.gm.blue_team[0]

        pl2_x = int(self.gm.board.board_height / 2)
        pl2_y = int(self.gm.board.board_width / 2) + 1

        sq = self.gm.board.get_square(pl2.x, pl2.y)
        next_sq = self.gm.board.get_square(pl2_x, pl2_y)

        pl2.move(sq, next_sq)

        msg = m.Move(id=pl1.id, direction='E')
        self.gm.move_player(msg)

        res = current_msg.result
        self.assertEqual(res, 'denied')
Example #9
0
    def test_register_exchange(self):
        # Add recipient to game
        pl_to = player.GmPlayer(id=uuid.uuid4(), team='red')
        self.external.gm.join_game(
            m.JoinGame(id=pl_to.id, preferred_team='red', type='player'))

        # Allowed
        msg = m.AuthorizeKnowledgeExchange(userGuid=uuid.uuid4(),
                                           receiverGuid=pl_to.id)

        self.external.register_exchange(msg)

        # Check that the exchange was added
        self.assertEqual(len(self.external.exchange_storage), 1)

        # Check that the message was relayed
        from_id = current_msg.userGuid
        self.assertEqual(from_id, msg.userGuid)