Example #1
0
    def testTeleport(self):

        random.seed(1)

        worldActor = SWorld()  # For debugging use
        world = worldActor.channel

        location0 = (32 * 3 + 16, 32 * 3 + 16)
        wc = SWoodcutter(world,
                         location=location0,
                         velocity=0,
                         instanceName='Woodcutter',
                         roamingRadius=200,
                         stamina=10,
                         maxStamina=100,
                         intention='RESTING')

        self.tick(world)
        self.assertEqual('RESTING', wc.intention)
        self.assertEqual(location0, wc.location)

        location1 = (32 * 7 + 16, 32 * 7 + 16)
        worldActor.teleportActor(wc.channel, location1)
        self.tick(world)
        self.assertEqual('RESTING', wc.intention)
        self.assertEqual(location1, wc.location)
Example #2
0
def main():
    random.seed(1)

    world = SWorld().channel

    SDisplayWindow(world)

    home = SHome(world, location=(250, 400), instanceName='Home')

    STree(world,
          'WOOD',
          location=(150, 150),
          instanceName='FarawayTree',
          hitpoints=1)

    SWoodcutter(world,
                location=(200, 400),
                homeLocation=home.location,
                velocity=50,
                instanceName='Woodcutter',
                stamina=100,
                maxStamina=100)

    try:
        #actor.printAllActorChannelBalances()
        world.send((None, 'START_TICK_TASKLET'))
        r = stackless.run()
        print 'stackless.run() result =', r

    except KeyboardInterrupt:
        print "Exit"

    print "End of Program"
Example #3
0
def main():
    random.seed(1)

    world = SWorld().channel

    SDisplayWindow(world)        

    home = SHome(world, location=(100,100), instanceName='WoodcutterHome')
    SWoodcutter(world, location=(100,100), homeLocation=home.location, velocity=4, instanceName='Woodcutter', roamingRadius=200, stamina=10, maxStamina=10)

    for i in range(20):
        SWoodcutter(world,
                    location=getRandomLoc(),
                    homeLocation=home.location,
                    velocity=50 + (random.random() - 0.5) * 3,
                    instanceName="Woodcutter #%d" % (i + 1)
                    )
    

    home2 = SHome(world, location=(300,300), instanceName='BanditHome', staminaRefillSpeed=100)
    SBandit(world, location=(300,300), homeLocation=home2.location, velocity=5, instanceName='Bandit')
    
    try:
        actor.printAllActorChannelBalances()
        r = stackless.run()
        print 'stackless.run() result =', r
        
    except KeyboardInterrupt:
        print "Exit"

    print "End of Program"
    
    actor.printAllActorChannelBalances()
Example #4
0
def main():
    random.seed(1)

    totalWood = 0

    world = SWorld().channel

    SDisplayWindow(world)

    homeList = []
    gatheringList = ["WOOD"]

    for i in range(1):
        homeList.append(
            SHome(world,
                  location=getRandomLoc(),
                  instanceName="Home #%d" % (i + 1)))
        #homeList.append(SHome(world, location=(250,400), instanceName="Home #%d" % (i + 1)))

    for i in range(20):
        gatheringName = random.choice(gatheringList)
        STree(world,
              gatheringName,
              location=getRandomLoc(),
              instanceName="Tree #%d [%s]" % (i + 1, gatheringName),
              hitpoints=10)

    for i in range(20):
        SWoodcutter(world,
                    location=getRandomLoc(),
                    homeLocation=random.choice(homeList).location,
                    velocity=50 + (random.random() - 0.5) * 3,
                    instanceName="Woodcutter #%d" % (i + 1))

    homeLoc = random.choice(homeList).location
    SArchitect(world,
               location=homeLoc,
               homeLocation=homeLoc,
               velocity=50 + (random.random() - 0.5) * 3,
               instanceName="Architect")

    try:
        actor.printAllActorChannelBalances()
        r = stackless.run()
        print 'stackless.run() result =', r

    except KeyboardInterrupt:
        print "Exit"

    print "End of Program", totalWood

    actor.printAllActorChannelBalances()
Example #5
0
    def testOneWoodcutterAndOneWood(self):
        '''
        logging.getLogger().setLevel(logging.DEBUG)
        logging.debug('Debug level logging enabled.')
        '''

        random.seed(1)

        world = SWorld(exitOnNoHarvestables=True).channel

        home = SHome(world,
                     location=(32 * 5, 32 * 5),
                     instanceName='WoodcutterHome')

        SWoodcutter(world,
                    location=(32 * 3 + 16, 32 * 3 + 16),
                    homeLocation=home.location,
                    velocity=4,
                    instanceName='Woodcutter',
                    roamingRadius=200,
                    stamina=10000,
                    maxStamina=10000,
                    intention='PATHFINDING_HARVESTABLE')

        tree = STree(world,
                     'WOOD',
                     location=(32 * 4, 32 * 3),
                     instanceName='Tree',
                     hitpoints=1)

        world.send((None, 'START_TICK_TASKLET'))
        r = stackless.run()
        logging.info('End of Program, stackless.run() result = %s' % r)

        self.assertEqual(0, tree.hitpoints)
        self.assertEqual('DEPLETED', tree.deathReason)
Example #6
0
    def testWoodcutterAddStamina(self):

        random.seed(1)

        worldActor = SWorld()  # For debugging use
        world = worldActor.channel

        woodcutter = SWoodcutter(world,
                                 location=(32 * 6 + 16, 32 * 4 + 16),
                                 velocity=4,
                                 instanceName='Woodcutter',
                                 roamingRadius=200,
                                 stamina=0,
                                 maxStamina=10)

        SHome(world, location=(32 * 6, 32 * 3), instanceName='WoodcutterHome')

        world.send((None, 'START_SINGLE_TICK_TASKLET'))
        r = stackless.run()
        logging.info('End of Program, stackless.run() result = %s' % r)

        self.assertGreater(woodcutter.stamina, 0)
Example #7
0
    def testHomelessStarvation(self):

        random.seed(1)

        worldActor = SWorld()  # For debugging use
        world = worldActor.channel

        woodcutter = SWoodcutter(world,
                                 location=(100, 100),
                                 velocity=4,
                                 instanceName='Woodcutter',
                                 roamingRadius=200,
                                 stamina=10,
                                 maxStamina=10)

        world.send((None, 'START_TICK_TASKLET'))
        r = stackless.run()
        logging.info('End of Program, stackless.run() result = %s' % r)

        self.assertEqual('STARVATION', woodcutter.deathReason)
        self.assertFalse(worldActor.registeredActors)
        self.assertFalse(worldActor.aboutToBeKilledActors)
        self.assertFalse(worldActor.tickDisabledActors)
Example #8
0
def main():
    random.seed(1)

    logging.getLogger().setLevel(logging.INFO)

    worldActor = SWorld(width=8, height=8, disableCollisionCheck=True)
    world = worldActor.channel

    client = SClient(world, 'Client', ('14.49.42.133', 3000)).channel

    SDisplayWindow(world, windowTitle='Falling Sun Client', client=client)

    logging.info('All actors initialized successfully.')
    logging.info('Starting the tick tasklet...')

    try:
        world.send((None, 'START_TICK_TASKLET'))
        r = stackless.run()
        assert r is None

    except KeyboardInterrupt:
        logging.info('Exit by KeyboardInterrupt')

    logging.info('End of Program')
Example #9
0
def main():
    random.seed(1)

    logging.getLogger().setLevel(logging.INFO)

    worldSizeX = 15
    worldSizeY = 15
    worldActor = SWorld(width=worldSizeX,
                        height=worldSizeY,
                        disableCollisionCheck=True,
                        useTestData=True)
    world = worldActor.channel

    #
    # Initially joining actors
    #
    #STree(world, 'WOOD', location=(32*5+16,32*5+16), instanceName='TestTree')
    STree(world,
          'WOOD',
          location=(32 * 5 + 16, 32 * 15 + 16),
          instanceName='Tree',
          hitpoints=3,
          hitpointsDecay=0)

    STree(world,
          'WOOD',
          location=(32 * 11 + 16, 32 * 7 + 16),
          instanceName='FarawayTree',
          hitpoints=4,
          hitpointsDecay=0)

    STree(world,
          'WOOD',
          location=(32 * 15 + 16, 32 * 8 + 16),
          instanceName='VFTree',
          hitpoints=15,
          hitpointsDecay=0)

    STree(world,
          'WOOD',
          location=(32 * 6 + 16, 32 * 5 + 16),
          instanceName='HiddenTree',
          hitpoints=7,
          hitpointsDecay=0)

    home = SHome(world,
                 location=(32 * 10 + 16, 32 * 13 + 16),
                 instanceName='WoodcutterHome').channel
    SWoodcutter(world,
                location=(32 * 0 + 16, 32 * 16 + 16),
                velocity=20,
                home=home,
                instanceName='Woodcutter',
                roamingRadius=200,
                stamina=10,
                maxStamina=1000,
                intention='PATHFINDING_HARVESTABLE',
                display=None)

    for i in range(10):
        SPrey(world,
              location=getRandomActorTile(0, 0, 1, 1),
              velocity=20,
              angle=getRandomAngle(),
              instanceName='Prey%d' % i,
              stamina=100,
              maxStamina=100,
              roamingVelocity=random.randrange(25, 35),
              intention='ROAMING')

    #
    # Sight
    #
    '''
    sightX, sightY = 14, 14
    sight = SSight(world, location=(32 * sightX, 32 * sightY),
                   instanceName='TestSight', sightRange=7).channel'''
    you = SPrey(world,
                location=getRandomActorTile(19, 6, 20, 7),
                velocity=20,
                angle=getRandomAngle(),
                instanceName='YOU',
                stamina=100,
                maxStamina=100,
                roamingVelocity=random.randrange(25, 35),
                intention='SYNCING').channel

    #
    # 막촌 보좌관
    #
    SPrey(world,
          location=getRandomActorTile(19, 5, 20, 6),
          velocity=20,
          angle=180,
          instanceName='HeadmanAssistant',
          stamina=100,
          maxStamina=100,
          roamingVelocity=random.randrange(25, 35),
          intention='SYNCING',
          conversation=dialog.HeadmanAssistant())

    #
    # 평범한 막촌 주민
    #
    SPrey(world,
          location=getRandomActorTile(19, 2, 20, 3),
          velocity=20,
          angle=180,
          instanceName='Villager',
          stamina=100,
          maxStamina=100,
          roamingVelocity=random.randrange(25, 35),
          intention='SYNCING',
          conversation=dialog.Villager())

    #
    # Display
    #
    SDisplayWindow(world,
                   windowTitle='Falling Sun Server',
                   swidth=32 * 23,
                   sheight=32 * 15,
                   client=you,
                   sightedActorsOnly=False)

    #
    # Servers
    #
    SServer(world, 'Server')
    SWebSocketServer(world, 'WebSocketServer')

    logging.info('All actors initialized successfully.')
    logging.info('Starting the tick tasklet...')

    try:
        world.send((None, 'START_TICK_TASKLET'))
        r = stackless.run()
        assert r is None

    except KeyboardInterrupt:
        logging.info('Exit by KeyboardInterrupt')

    logging.info('End of Program')
Example #10
0
def main():
    random.seed(1)

    logging.getLogger().setLevel(logging.INFO)
    # logging.debug('Debug level logging enabled.')

    # world = SWorld(disableCollisionCheck=True).channel
    world = SWorld(useTestData=True).channel

    display = SDisplayWindow(world, swidth=32 * 23, sheight=32 * 23).channel
    '''
    for i in range(10):
        SPrey(world,
              location=(32*11+16,32*8+16),
              velocity=10,
              angle=90,
              instanceName='PreyI #%d' % (i+1),
              stamina=100,
              maxStamina=100,
              intention='RESTING')
        
    for i in range(10):
        SPrey(world,
              location=(32*5+16,32*5+16),
              velocity=5,
              angle=90,
              instanceName='Prey II #%d' % (i+1),
              stamina=100,
              maxStamina=100,
              intention='RESTING')
    '''

    SPrey(world,
          location=(32 * 5 + 16, 32 * 5 + 16),
          velocity=50,
          angle=90,
          instanceName='Prey',
          stamina=100,
          maxStamina=100,
          intention='ROAMING')

    STree(world,
          'WOOD',
          location=(32 * 5, 32 * 15),
          instanceName='Tree',
          hitpoints=3,
          hitpointsDecay=0)

    STree(world,
          'WOOD',
          location=(32 * 11, 32 * 7),
          instanceName='FarawayTree',
          hitpoints=4,
          hitpointsDecay=0)

    STree(world,
          'WOOD',
          location=(32 * 15, 32 * 8),
          instanceName='VFTree',
          hitpoints=15,
          hitpointsDecay=0)

    STree(world,
          'WOOD',
          location=(32 * 6, 32 * 5),
          instanceName='HiddenTree',
          hitpoints=7,
          hitpointsDecay=0)

    home = SHome(world,
                 location=(32 * 10, 32 * 13),
                 instanceName='WoodcutterHome')

    home2 = SHome(world, location=(32 * 16, 32 * 17), instanceName='Wc2Home')

    SWoodcutter(world,
                location=(32 * 0 + 16, 32 * 16 + 16),
                homeLocation=home.location,
                velocity=20,
                home=home.channel,
                instanceName='Woodcutter',
                roamingRadius=200,
                stamina=10,
                maxStamina=1000,
                intention='PATHFINDING_HARVESTABLE',
                display=display)

    SWoodcutter(world,
                location=(32 * 0 + 16, 32 * 2 + 16),
                homeLocation=home2.location,
                velocity=20,
                home=home2.channel,
                instanceName='Wc2',
                roamingRadius=200,
                stamina=10,
                maxStamina=1000,
                intention='PATHFINDING_HARVESTABLE',
                display=display)

    SWoodcutter(world,
                location=(32 * 16 + 16, 32 * 18 + 16),
                homeLocation=home2.location,
                velocity=20,
                home=home2.channel,
                instanceName='Wc3-rest',
                roamingRadius=200,
                stamina=6,
                maxStamina=10,
                intention='RESTING',
                display=display)

    logging.info('All actors initialized successfully.')
    logging.info('Starting the tick tasklet...')

    try:
        world.send((None, 'START_TICK_TASKLET'))
        r = stackless.run()
        assert r is None

    except KeyboardInterrupt:
        logging.info('Exit by KeyboardInterrupt')

    logging.info('End of Program')
Example #11
0
    def testEnterLeave(self):

        logging.getLogger().setLevel(logging.DEBUG)

        random.seed(1)

        worldActor = SWorld()  # For debugging use
        world = worldActor.channel

        wcLoc0 = (32 * 3 + 16, 32 * 3 + 16)
        wc = SWoodcutter(world,
                         location=wcLoc0,
                         velocity=0,
                         instanceName='Woodcutter',
                         roamingRadius=200,
                         stamina=10,
                         maxStamina=100,
                         intention='RESTING')

        homeLoc0 = (32 * 8, 32 * 8)
        home = SHome(world, location=homeLoc0, instanceName='WoodcutterHome')

        wcNb = wc.neighbors
        homeNb = home.neighbors
        self.assertEqual(set(), wcNb)
        self.assertEqual(set(), homeNb)

        self.tick(world)
        self.assertEqual(set(), wcNb)
        self.assertEqual(set(), homeNb)

        wcLoc1 = (32 * 8 + 16, 32 * 9 + 16)
        worldActor.teleportActor(wc.channel, wcLoc1)
        self.tick(world)
        self.assertEqual(set([home.channel]), wcNb)
        self.assertEqual(set([wc.channel]), homeNb)

        wcLoc2 = (32 * 9 + 16, 32 * 8 + 16)
        worldActor.teleportActor(wc.channel, wcLoc2)
        self.tick(world)
        self.assertEqual(set([home.channel]), wcNb)
        self.assertEqual(set([wc.channel]), homeNb)

        wcLoc3 = (32 * 9 + 16 + 5, 32 * 8 + 16 + 5)
        worldActor.teleportActor(wc.channel, wcLoc3)
        self.tick(world)
        self.assertEqual(set([home.channel]), wcNb)
        self.assertEqual(set([wc.channel]), homeNb)

        wcLoc4 = (32 * 9 + 16 + 5 + 32, 32 * 8 + 16 + 5 + 32)
        worldActor.teleportActor(wc.channel, wcLoc4)
        self.tick(world)
        self.assertEqual(set(), wcNb)
        self.assertEqual(set(), homeNb)

        wcLoc5 = (32 * 1 + 16, 32 * 2 + 16)
        worldActor.teleportActor(wc.channel, wcLoc5)
        self.tick(world)
        self.assertEqual(set(), wcNb)
        self.assertEqual(set(), homeNb)

        wc2Loc0 = (32 * 1 + 16, 32 * 2 + 16)
        wc2 = SWoodcutter(world,
                          location=wc2Loc0,
                          velocity=0,
                          instanceName='Woodcutter2',
                          roamingRadius=200,
                          stamina=10,
                          maxStamina=100,
                          intention='RESTING')
        wc2Nb = wc2.neighbors

        self.tick(world)
        self.assertEqual(set([wc2.channel]), wcNb)
        self.assertEqual(set([wc.channel]), wc2Nb)
        self.assertEqual(set(), homeNb)

        worldActor.teleportActor(wc.channel, wcLoc2)
        worldActor.teleportActor(wc2.channel, wcLoc2)
        self.tick(world)
        self.assertEqual(set([home.channel, wc2.channel]), wcNb)
        self.assertEqual(set([home.channel, wc.channel]), wc2Nb)
        self.assertEqual(set([wc.channel, wc2.channel]), homeNb)

        worldActor.teleportActor(wc.channel, wcLoc3)
        self.tick(world)
        self.assertEqual(set([home.channel, wc2.channel]), wcNb)
        self.assertEqual(set([home.channel, wc.channel]), wc2Nb)
        self.assertEqual(set([wc.channel, wc2.channel]), homeNb)

        wc.hitpoints = 0
        wc.deathReason = 'TEST'
        self.tick(world)
        self.assertEqual(set([home.channel]), wc2Nb)
        self.assertEqual(set([wc2.channel]), homeNb)

        self.tick(world)
        self.assertEqual(set([home.channel]), wc2Nb)
        self.assertEqual(set([wc2.channel]), homeNb)

        wc2.hitpoints = 0
        wc2.deathReason = 'TEST'
        self.tick(world)
        self.assertEqual(set(), homeNb)