예제 #1
0
class TestScoutNetwork(asynctest.TestCase):
    def setUp(self):
        self.game_id = "3"
        self.player_id = "31"
        self.country = "NATO"
        self.input_data = {
            "game_id": self.game_id,
            "player_id": self.player_id,
            "ai_type": "neuron-network",
            "ai_address": "scout-layer",
            "location": TestRouteController.generate_mock_location_info(),
            "country": self.country,
            "gameState": TestRouteController.generate_test_game_state(),
            "ai_options": {"troopType": "motorized", "isTrain": True}
        }
        self._game_info = GameInfo(int(self.game_id), int(self.player_id))
        self.controller = RouteController()

    def test_life_circle_network(self):

        self.controller.create_ai(self.input_data)
        commands: Json = self.controller.update_ai(
            TestRouteController.generate_test_game_state(),
            self._game_info
        )
        self.controller.delete_ai(self._game_info)
        with self.assertRaises(Exception):
            var = self.controller.ai_manager.get_ai(self.game_id, self.player_id)
        with self.assertRaises(Exception):
            var = self.controller.ai_manager.get_ai_socket_connection_info(self.game_id, self.player_id)
예제 #2
0
 def create_ai(cls, game_id, player_id, ai_type, ai_name):
     controller = RouteController()
     input_data = {
         "game_id": game_id,
         "player_id": player_id,
         "ai_type": ai_type,
         "ai_name": ai_name,
         "location": TestAiCommands.generate_mock_location_info(),
         "country": "NATO",
     }
     controller.create_ai(input_data)
     return controller.ai_manager.get_ai(game_id, player_id)
예제 #3
0
 def create_template_controller_with_ai(cls, game_id, player_id, ai_type,
                                        ai_name):
     controller = RouteController()
     input_data = {
         "game_id": game_id,
         "player_id": player_id,
         "ai_type": ai_type,
         "ai_name": ai_name,
         "location": TestRouteController.generate_mock_location_info(),
         "country": "Ukraine",
     }
     controller.create_ai(input_data)
     return controller
예제 #4
0
    def test_generate_ai_address(self):
        controller = RouteController()

        game_id = 2
        player_id = 21
        ai_type = "script-bot"
        ai_name = "intellectual-000"

        game_info = [game_id, player_id]
        ai_info = [ai_type, ai_name]

        response = controller.generate_ai_address(game_info, ai_info)
        self.assertEqual(response, (TestRouteController.generate_ai_address(game_id, player_id), 200))
예제 #5
0
 def setUp(self):
     self.game_id = "3"
     self.player_id = "31"
     self.country = "NATO"
     self.input_data = {
         "game_id": self.game_id,
         "player_id": self.player_id,
         "ai_type": "neuron-network",
         "ai_address": "scout-layer",
         "location": TestRouteController.generate_mock_location_info(),
         "country": self.country,
         "gameState": TestRouteController.generate_test_game_state(),
         "ai_options": {"troopType": "motorized", "isTrain": True}
     }
     self._game_info = GameInfo(int(self.game_id), int(self.player_id))
     self.controller = RouteController()
예제 #6
0
    def test_create_ai(self):
        game_id = "3"
        player_id = "31"
        country = "NATO"
        input_data = {
            "game_id": game_id,
            "player_id": player_id,
            "ai_type": "script-bot",
            "ai_address": "intellectual-000",
            "location": TestRouteController.generate_mock_location_info(),
            "country": country,
            "gameState": self.generate_test_game_state(),
        }

        controller = RouteController()

        with self.assertRaises(Exception):
            var = controller.ai_manager.get_ai(game_id, player_id)
        with self.assertRaises(Exception):
            var = controller.ai_manager.get_ai_socket_connection_info(game_id, player_id)

        controller.create_ai(input_data)

        # (7kia) For creating connection create ai_socket_connection_info on AI server
        # for understanding that server handle request or no
        try:
            ai = controller.ai_manager.get_ai(game_id, player_id)
            self.assertEqual(ai is not None, True)
            self.assertEqual(
                ai.get_location(),
                LocationBuilder.build(
                    TestRouteController.generate_mock_location_info()
                ))
            self.assertEqual(ai.get_country(), country)

            ai_socket_connection_info = controller.ai_manager.get_ai_socket_connection_info(game_id, player_id)
            self.assertEqual(
                ai_socket_connection_info,
                TestRouteController.generate_ai_address(game_id, player_id)
            )
        except Exception as e:
            self.fail(e)
예제 #7
0
from flask import Flask
from flask import request, session
from flask_socketio import SocketIO
from flask_socketio import join_room, leave_room
from flask_socketio import send, emit

from src.routeController import RouteController
from src.ai.ai_manager import AiManager

app = Flask(__name__)
socketio = SocketIO(app,
                    async_mode='eventlet',
                    logger=True,
                    engineio_logger=True)
controller = RouteController()
sem = threading.Semaphore()


@socketio.on('join')
def test_connect(data):
    # sem.acquire()
    print("join")
    controller.create_ai(data)

    room_info = data['channel_info']
    game_id = str(room_info["game_id"])
    player_id = str(room_info["player_id"])
    address = AiManager.generate_ai_address(game_id, player_id)
    join_room(address)
    print('Open socket {0} socket info={1}'.format(