当前位置: 首页>>代码示例>>Python>>正文


Python Simulator.start方法代码示例

本文整理汇总了Python中simulator.Simulator.start方法的典型用法代码示例。如果您正苦于以下问题:Python Simulator.start方法的具体用法?Python Simulator.start怎么用?Python Simulator.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在simulator.Simulator的用法示例。


在下文中一共展示了Simulator.start方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from simulator import Simulator [as 别名]
# 或者: from simulator.Simulator import start [as 别名]
def main():
    drone = RealDrone()
    # controller = ConConController(drone=drone,
            # log=True)
    controller = SingleAxisController(drone=drone, log=True)
    sim = Simulator(drone=drone, controller=controller)
    sim.start()
开发者ID:EECampCaoCao,项目名称:EECampTeaching,代码行数:9,代码来源:real.py

示例2: main

# 需要导入模块: from simulator import Simulator [as 别名]
# 或者: from simulator.Simulator import start [as 别名]
def main():
    opts, args = getopt.getopt(sys.argv[1:], "f:", ["help"])
    # f framerate
    players = []
    player_no = 0
    frame_delay = None
    for type in opts:
        if type[0] == '-f':
            frame_delay = int(type[1])

    for type in args:
        players.append(create_player(type, player_no))
        player_no += 1
        
    vis = PyGameVisualizer(frame_delay)
    sim = Simulator(players, vis)
    sim.start()
开发者ID:jsyrjala,项目名称:pyrobots,代码行数:19,代码来源:robots.py

示例3: readUdpPackets

# 需要导入模块: from simulator import Simulator [as 别名]
# 或者: from simulator.Simulator import start [as 别名]
def readUdpPackets(udpSocket):
    print "--- reading UDP packets"

    # all received packet ids
    receivedIds = set();

    while udpKeepRunning:
        try:
            data, addr = udpSocket.recvfrom(2048)
        except:
            break

        print "--- read %d bytes from %s:%d" % (len(data), addr[0], addr[1])

        (packetType,) = struct.unpack_from('>B', data, 0)

        if packetType == packet.Packet.UDP_PONG:
            (oldTime,) = struct.unpack_from('>L', data, struct.calcsize('>B'))
            now = datetime.datetime.now()
            milliseconds = (now.day * 24 * 60 * 60 + now.second) * 1000 + now.microsecond / 1000
            print "--- pong received, time: %d ms" % (milliseconds - oldTime)

        elif packetType == packet.Packet.UDP_DATA_START_ACTION:
            print "--- start action, starting simulator"
            # create the simulator and start it
            global simulator
            simulator = Simulator( units, udpSocket, udpAddress )
            simulator.start()

        elif packetType == packet.Packet.UDP_DATA:
            (packetType, subPacketType, packetId,) = struct.unpack_from('>BBI', data, 0)
            offset = struct.calcsize('>BBL')
            print "--- UDP data type %d, packet id: %d, total bytes: %d" % (subPacketType, packetId, len(data))

            # already received this?
            if packetId in receivedIds:
                # skip this
                print "--- ignoring duplicate packet %d" % packetId
                continue

            receivedIds.add( packetId )

            if subPacketType == packet.Packet.UDP_DATA_MISSION:
                (unitCount,) = struct.unpack_from('>B', data, offset)
                offset += struct.calcsize('>B')
                print "--- mission data, %d units" % unitCount

                for count in range( unitCount ):
                    (unitId, missionType, ) = struct.unpack_from('>hB', data, offset)
                    offset += struct.calcsize('>hB')
                    print "--- unit %d, mission %d" % (unitId, missionType )

            elif subPacketType == packet.Packet.UDP_DATA_UNIT_STATS:
                (unitCount,) = struct.unpack_from('>B', data, offset)
                offset += struct.calcsize('>B')
                print "--- unit stats, %d units" % unitCount

                for count in range( unitCount ):
                    (unitId, men, mode, missionType, morale, fatigue, ammo, x, y, facing, ) = struct.unpack_from('>hBBBBBBhhh', data, offset)
                    offset += struct.calcsize('>hBBBBBBhhh')

                    # convert some data back
                    x /= 10
                    y /= 10
                    facing /= 10

                    print "--- unit %d, men: %d, mode: %d, mission %d, morale: %d, fatigue: %d, ammo: %d pos: %d,%d, facing: %d" \
                          % (unitId, men, mode, missionType, morale, fatigue, ammo, x, y, facing)

            elif subPacketType == packet.Packet.UDP_DATA_FIRE:
                (attackerId, x, y, ) = struct.unpack_from('>hhh', data, offset)
                offset += struct.calcsize('>hhh')
                x /= 10
                y /= 10

                # any targets left?
                if offset == len(data):
                    print "--- smoke, %d fires smoke at %d,%d" % (attackerId, x, y )
                else:
                    (targetCount, ) = struct.unpack_from('>B', data, offset)
                    offset += struct.calcsize('>B')
                    print "--- fire, %d fires at %d,%d, hitting %d units" % (attackerId, x, y, targetCount )

                    for count in range( targetCount ):
                        (targetId, casualties, type, targetMoraleChange ) = struct.unpack_from('>hBBh', data, offset)
                        offset += struct.calcsize('>hBBh')
                        targetMoraleChange /= 10.0
                        print "    target %d lost %d men, type: %d, target morale: %.1f" % (targetId, casualties, type, targetMoraleChange)
                        for unit in units:
                            if unit.id == targetId:
                                unit.men = max( 0, unit.men - casualties )
                                unit.morale = max( 0, unit.morale - targetMoraleChange )

            elif subPacketType == packet.Packet.UDP_DATA_MELEE:
                (attackerId, targetId, missionType, casualties, targetMoraleChange ) = struct.unpack_from('>hhBBh', data, offset)
                offset += struct.calcsize('>hhBBh')
                targetMoraleChange /= 10.0
                print "    %d melees with %d, target lost %d men, type: %d, target morale: %.1f" % (attackerId, targetId, casualties, type, targetMoraleChange)
                for unit in units:
                    if unit.id == targetId:
#.........这里部分代码省略.........
开发者ID:D-Pointer,项目名称:imperium-server,代码行数:103,代码来源:imperium-server-test.py

示例4: Simulator

# 需要导入模块: from simulator import Simulator [as 别名]
# 或者: from simulator.Simulator import start [as 别名]
#!/usr/bin/env python3

"""Main module. Checks command line arguments."""

import sys
from simulator import Simulator

# -------------------------------------------------------------

try:
    simulator = Simulator(sys.argv[1])
    simulator.start()
except IndexError:
    print("Simulation file not specified!")
except FileNotFoundError:
    print("Simulation file '%s' not found!" % sys.argv[1])
except KeyboardInterrupt:
    print("Simulation canceled!")
开发者ID:redes-2015,项目名称:simula-rede,代码行数:20,代码来源:main.py


注:本文中的simulator.Simulator.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。