Ejemplo n.º 1
0
 def setUp(self):
     self.game = ExampleGame(Builder(10, 10, 7, 6).create())
     self.game.addUnit(Unit(1), 1, (0, 0))
     self.bot1 = ExampleBot(1)
     self.bot1.gameState = self.game.copy()
     self.linker1 = ExampleBotControllerWrapper(self.bot1)
     self.game.addUnit(Unit(2), 1, (0, 0))
     self.bot2 = ExampleBot(2)
     self.bot2.gameState = self.game.copy()
     self.linker2 = ExampleBotControllerWrapper(self.bot2)
     self.game_info_pipe_parent1, self.game_info_pipe_child1 = Pipe(
     )  # type: Tuple[PipeConnection, PipeConnection]
     self.game_info_pipe_parent2, self.game_info_pipe_child2 = Pipe(
     )  # type: Tuple[PipeConnection, PipeConnection]
     self.move_pipe_parent1, self.move_pipe_child1 = Pipe(
     )  # type: Tuple[PipeConnection, PipeConnection]
     self.move_pipe_parent2, self.move_pipe_child2 = Pipe(
     )  # type: Tuple[PipeConnection, PipeConnection]
     self.linker1.setMainPipe(self.move_pipe_child1)
     self.linker1.setGameInfoPipe(self.game_info_pipe_child1)
     self.linker2.setMainPipe(self.move_pipe_child2)
     self.linker2.setGameInfoPipe(self.game_info_pipe_child2)
     self.collaboration_pipe_1, self.collaboration_pipe_2 = Pipe()
     self.linker1.addCollaborationPipe(2, self.collaboration_pipe_1)
     self.linker2.addCollaborationPipe(1, self.collaboration_pipe_2)
Ejemplo n.º 2
0
 def __init__(self):
     self._reader, self._writer = Pipe(duplex=False)
     self._rlock = Lock()
     self._poll = self._reader.poll
     if sys.platform == 'win32':
         self._wlock = None
     else:
         self._wlock = Lock()
     self._make_methods()
Ejemplo n.º 3
0
    def _addControllerWrapper(self, wrapper: ControllerWrapper,
                              unit: Unit) -> None:
        """
        Adds the linker to the loop, creating the pipe connections

        Args:
            wrapper: The linker to add
            unit: The unit, linked by this linker
        """
        self.wrappers[wrapper] = unit
        parent_conn, child_conn = Pipe()
        parent_info_conn, child_info_conn = Pipe()
        self.wrappersConnection[wrapper] = parent_conn
        self.wrappersInfoConnection[wrapper] = parent_info_conn
        self._eventsToSend[wrapper] = []
        wrapper.setMainPipe(child_conn)
        wrapper.setGameInfoPipe(child_info_conn)
        if isinstance(wrapper, BotControllerWrapper):
            self._addCollaborationPipes(wrapper)
Ejemplo n.º 4
0
    def __init__(self, maxsize=0):
        if maxsize <= 0:
            maxsize = _multiprocessing.SemLock.SEM_VALUE_MAX
        self._maxsize = maxsize
        self._reader, self._writer = Pipe(duplex=False)
        self._rlock = Lock()
        self._opid = os.getpid()
        if sys.platform == 'win32':
            self._wlock = None
        else:
            self._wlock = Lock()
        self._sem = BoundedSemaphore(maxsize)
        # For use by concurrent.futures
        self._ignore_epipe = False

        self._after_fork()

        if sys.platform != 'win32':
            register_after_fork(self, Queue._after_fork)
Ejemplo n.º 5
0
    def _addCollaborationPipes(self, linker: BotControllerWrapper) -> None:
        """
        Adds the collaboration pipes between the given linker and its teammate's

        Args:
            linker: The linker to connect with its teammate
        """
        for teammate in self.game.teams[self.game.unitsTeam[
                self.wrappers[linker]]]:
            if teammate is not self.wrappers[linker]:
                teammate_linker = None  # type: BotControllerWrapper
                for other_linker in self.wrappers:
                    if self.wrappers[other_linker] is teammate:
                        teammate_linker = other_linker
                        break
                pipe1, pipe2 = Pipe()
                linker.addCollaborationPipe(
                    teammate_linker.controller.playerNumber, pipe1)
                teammate_linker.addCollaborationPipe(
                    linker.controller.playerNumber, pipe2)
Ejemplo n.º 6
0
def Pipe(duplex=True):
    '''
    Returns two connection object connected by a pipe
    '''
    from multiprocess.connection import Pipe
    return Pipe(duplex)