def test_updating_above_duration1_below_duration(self, duration1, duration2):
        global rec

        if duration2==0.0:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)
        node.do(composite)
        elapsed = 0.0
        next_elapsed = (duration1 + duration2)/2.0
        dt = next_elapsed - elapsed
        node._step(dt)
        elapsed = next_elapsed
        next_elapsed = (next_elapsed + composite.duration)/2.0
        dt = next_elapsed - elapsed
        rec = []
        node._step(dt)

        assert len([e for e in rec if e[0]==name1])==0
        rec = [ e for e in rec if e[1]!='step' ]
        print rec
        assert rec[0][1]=='update'
        assert abs(rec[0][2]-(next_elapsed-duration1)/duration2)<fe
        assert len(rec)==1
    def test_update_crossing_total_duration_at_1st_step(self, duration1, duration2):
        # elapsed==0, next_elapsed>=duration1 + duration2
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        elapsed = 0.0
        rec = []
        composite = ac.sequence(a1, a2)
        node.do(composite)
        next_elapsed = duration1 + duration2 +fe
        dt = next_elapsed - elapsed
        node._step(dt)
        # expected: for both actions start-update(1)-stop called, in that order
        recx = [ e for e in rec if e[1]!='step' ]
        rec = [ e for e in recx if e[0]==name1]
        print 'rec',rec
        assert len(rec)==3
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'

        rec = [ e for e in recx if e[0]==name2]
        print 'rec',rec
        assert len(rec)==3
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'
    def test_update_crossing_duration1_not_duration_at_1st_step(self, duration1, duration2):
        global rec

        if duration2==0.0:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)
        rec = []
        node.do(composite)
        elapsed = 0.0
        next_elapsed = (duration1 + duration2)/2.0
        dt = next_elapsed - elapsed
        node._step(dt)

        #expect start, update(1), stop for action 1, start + update(x) for action2
        recx = [ e for e in rec if e[1]!='step' ]
        rec = [ e for e in recx if e[0]==name1]
        print 'rec',rec
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'
        assert len(rec)==3

        rec = [ e for e in recx if e[0]==name2]
        print 'rec',rec
        assert rec[0][1]=='start'
        assert rec[1][1]=='update'
        assert abs(rec[1][2]-(next_elapsed-duration1)/duration2)<fe
        assert len(rec)==2
    def test_update_below_duration1(self, duration1, duration2):
        global rec

        if duration1 == 0.0:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)
        node.do(composite)
        elapsed = 0.0
        # check cases 1st step and not 1st step
        for next_elapsed in [duration1 * 0.5, duration1 * 0.75]:
            dt = next_elapsed - elapsed
            rec = []
            node._step(dt)
            rec = [e for e in rec if e[1] != 'step']
            print(rec)
            assert rec[0][1] == 'update' and abs(rec[0][2] -
                                                 next_elapsed / duration1) < fe
            assert len(rec) == 1
            elapsed = next_elapsed
Exemplo n.º 5
0
    def test_updating_above_duration1_below_duration(self, duration1, duration2):
        global rec

        if duration2==0.0:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)
        node.do(composite)
        elapsed = 0.0
        next_elapsed = (duration1 + duration2)/2.0
        dt = next_elapsed - elapsed
        node._step(dt)
        elapsed = next_elapsed
        next_elapsed = (next_elapsed + composite.duration)/2.0
        dt = next_elapsed - elapsed
        rec = []
        node._step(dt)

        assert len([e for e in rec if e[0]==name1])==0
        rec = [ e for e in rec if e[1]!='step' ]
        print(rec)
        assert rec[0][1]=='update'
        assert abs(rec[0][2]-(next_elapsed-duration1)/duration2)<fe
        assert len(rec)==1
Exemplo n.º 6
0
    def test_update_crossing_total_duration_at_1st_step(self, duration1, duration2):
        # elapsed==0, next_elapsed>=duration1 + duration2
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        elapsed = 0.0
        rec = []
        composite = ac.sequence(a1, a2)
        node.do(composite)
        next_elapsed = duration1 + duration2 +fe
        dt = next_elapsed - elapsed
        node._step(dt)
        # expected: for both actions start-update(1)-stop called, in that order
        recx = [ e for e in rec if e[1]!='step' ]
        rec = [ e for e in recx if e[0]==name1]
        print('rec', rec)
        assert len(rec)==3
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'

        rec = [ e for e in recx if e[0]==name2]
        print('rec', rec)
        assert len(rec)==3
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'
Exemplo n.º 7
0
    def test_update_crossing_duration1_not_duration_at_1st_step(self, duration1, duration2):
        global rec

        if duration2==0.0:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)
        rec = []
        node.do(composite)
        elapsed = 0.0
        next_elapsed = (duration1 + duration2)/2.0
        dt = next_elapsed - elapsed
        node._step(dt)

        #expect start, update(1), stop for action 1, start + update(x) for action2
        recx = [ e for e in rec if e[1]!='step' ]
        rec = [ e for e in recx if e[0]==name1]
        print('rec', rec)
        assert rec[0][1]=='start'
        assert rec[1][1]=='update' and rec[1][2]==1.0
        assert rec[2][1]=='stop'
        assert len(rec)==3

        rec = [ e for e in recx if e[0]==name2]
        print('rec', rec)
        assert rec[0][1]=='start'
        assert rec[1][1]=='update'
        assert abs(rec[1][2]-(next_elapsed-duration1)/duration2)<fe
        assert len(rec)==2
    def test_test_receiving_stop_async_after_duration1_before_duration2(
            self, duration1, duration2):
        #0<duration2
        global rec

        if duration2 == 0.0:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        elapsed = 0.0
        rec = []
        composite = ac.sequence(a1, a2)
        a_copy = node.do(composite)
        next_elapsed = (duration1 + duration2) / 2.0
        dt = next_elapsed - elapsed
        node._step(dt)

        rec = []
        a_copy.stop()
        assert rec[0] == (name2, 'stop')
        assert len(rec) == 1
    def test_instantiation(self):
        global rec, next_done
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        assert isinstance(a1, ac.Action)
        a2 = UAction(name2)

        rec = []
        composite = ac.sequence(a1, a2)
        assert isinstance(composite, ac.Action)
        assert len(rec)==0
Exemplo n.º 10
0
    def test_instantiation(self):
        global rec, next_done
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        assert isinstance(a1, ac.Action)
        a2 = UAction(name2)

        rec = []
        composite = ac.sequence(a1, a2)
        assert isinstance(composite, ac.Action)
        assert len(rec) == 0
Exemplo n.º 11
0
 def start(self):
     arena = self.target.parent  #type:Arena
     map = arena.map
     map.turn += 1
     if map.turn <= 5:
         if map.check_states():
             self.target.do(
                 sequence(MoveTo(coordinate(map.i, map.j, arena.size), 2),
                          Check_state(1)))
         else:
             self.target.do(Check_state(1))
     else:
         print('gg')
    def test_target_set(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.sequence(a1, a2)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.one.target==node
        assert a_copy.two.target==node
Exemplo n.º 13
0
    def test_instantiation(self, duration1, duration2):
        global rec
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        assert isinstance(a1, ac.IntervalAction)
        assert a1.duration == duration1
        a2 = UIntervalAction(name2, duration2)

        rec = []
        composite = ac.sequence(a1, a2)
        assert isinstance(composite, ac.IntervalAction)
        assert composite.duration == (duration1 + duration2)
        assert len(rec)==0
    def test_instantiation(self, duration1, duration2):
        global rec
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        assert isinstance(a1, ac.IntervalAction)
        assert a1.duration == duration1
        a2 = UIntervalAction(name2, duration2)

        rec = []
        composite = ac.sequence(a1, a2)
        assert isinstance(composite, ac.IntervalAction)
        assert composite.duration == (duration1 + duration2)
        assert len(rec)==0
Exemplo n.º 15
0
    def test_target_set(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.sequence(a1, a2)

        rec = []
        a_copy = node.do(composite)
        assert a_copy.one.target == node
        assert a_copy.two.target == node
    def test_receiving_stop_async_before_done1(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.sequence(a1, a2)
        a_copy = node.do(composite)
        rec = []
        a_copy.stop()

        assert rec[0]==(name1, 'stop')
        len(rec)==0
Exemplo n.º 17
0
    def test_receiving_stop_async_before_done1(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.sequence(a1, a2)
        a_copy = node.do(composite)
        rec = []
        a_copy.stop()

        assert rec[0] == (name1, 'stop')
        len(rec) == 0
    def test_start(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.sequence(a1, a2)

        rec = []
        a_copy = node.do(composite)
        print 'start rec:', rec
        assert rec[0]==(name1, 'start')
        assert len(rec)==1
        assert not a_copy.done()
Exemplo n.º 19
0
    def test_start(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.sequence(a1, a2)

        rec = []
        a_copy = node.do(composite)
        print 'start rec:', rec
        assert rec[0] == (name1, 'start')
        assert len(rec) == 1
        assert not a_copy.done()
 def test_step_before_done1(self):
     global rec, next_done
     next_done=0
     node = CocosNode()
     name1 = '1'
     name2 = '2'
     a1 = UAction(name1)
     a2 = UAction(name2)
     composite = ac.sequence(a1, a2)
     a_copy = node.do(composite)
     dt = 0.1
     rec = []
     node._step(dt)
     assert rec[0][0]==name1 and rec[0][1]== 'step'
     assert rec[0][2]==dt
     assert len(rec)==1
     assert not a_copy.done()
Exemplo n.º 21
0
 def test_step_before_done1(self):
     global rec, next_done
     next_done = 0
     node = CocosNode()
     name1 = '1'
     name2 = '2'
     a1 = UAction(name1)
     a2 = UAction(name2)
     composite = ac.sequence(a1, a2)
     a_copy = node.do(composite)
     dt = 0.1
     rec = []
     node._step(dt)
     assert rec[0][0] == name1 and rec[0][1] == 'step'
     assert rec[0][2] == dt
     assert len(rec) == 1
     assert not a_copy.done()
 def test_step_setting_done1(self):
     global rec, next_done
     next_done=0
     node = CocosNode()
     name1 = '1'
     name2 = '2'
     a1 = UAction(name1)
     a2 = UAction(name2)
     composite = ac.sequence(a1, a2)
     a_copy = node.do(composite)
     dt = 0.1
     rec = []
     next_done = 1
     node._step(dt)
     print rec
     assert rec[0][0]==name1 and rec[0][1]== 'step'
     assert rec[1][0]==name1 and rec[1][1]=='stop'
     assert rec[2][0]==name2 and rec[2][1]=='start'
     assert not a_copy.done()
Exemplo n.º 23
0
 def test_step_setting_done1(self):
     global rec, next_done
     next_done = 0
     node = CocosNode()
     name1 = '1'
     name2 = '2'
     a1 = UAction(name1)
     a2 = UAction(name2)
     composite = ac.sequence(a1, a2)
     a_copy = node.do(composite)
     dt = 0.1
     rec = []
     next_done = 1
     node._step(dt)
     print rec
     assert rec[0][0] == name1 and rec[0][1] == 'step'
     assert rec[1][0] == name1 and rec[1][1] == 'stop'
     assert rec[2][0] == name2 and rec[2][1] == 'start'
     assert not a_copy.done()
    def test_start(self, duration1, duration2):
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)

        rec = []
        node.do(composite)
        print 'start rec:', rec
        num = 0
        assert rec[num]==(name1, 'start')
        if duration1==0.0:
            assert rec[num + 1]==(name1, 'update', 1.0)
            assert rec[num + 2]==(name1, 'stop')
            assert rec[num + 3]==(name2, 'start')
            num = num + 3
        assert len(rec)==num+1
Exemplo n.º 25
0
    def test_start(self, duration1, duration2):
        global rec
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)

        rec = []
        node.do(composite)
        print('start rec:', rec)
        num = 0
        assert rec[num]==(name1, 'start')
        if duration1==0.0:
            assert rec[num + 1]==(name1, 'update', 1.0)
            assert rec[num + 2]==(name1, 'stop')
            assert rec[num + 3]==(name2, 'start')
            num = num + 3
        assert len(rec)==num+1
    def test_test_receiving_stop_async_before_duration1(self, duration1, duration2):
        #0<duration1
        global rec

        if duration1==0.0:
            return
        
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        elapsed = 0.0
        rec = []
        composite = ac.sequence(a1, a2)
        a_copy = node.do(composite)

        rec = []
        a_copy.stop()
        assert rec[0]==(name1, 'stop')
        assert len(rec)==1
Exemplo n.º 27
0
    def test_test_receiving_stop_async_before_duration1(self, duration1, duration2):
        #0<duration1
        global rec

        if duration1==0.0:
            return
        
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        elapsed = 0.0
        rec = []
        composite = ac.sequence(a1, a2)
        a_copy = node.do(composite)

        rec = []
        a_copy.stop()
        assert rec[0]==(name1, 'stop')
        assert len(rec)==1
Exemplo n.º 28
0
    def test_step_after_done1_before_done2(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.sequence(a1, a2)
        a_copy = node.do(composite)
        dt = 0.1
        next_done = 1
        node._step(dt)
        next_done = 0
        rec = []
        dt = 0.2
        node._step(dt)
        print rec

        assert 0 == len([e for e in rec if e[0] == name1])
        assert rec[0] == (name2, 'step', dt)
        assert not a_copy.done()
    def test_step_after_done1_before_done2(self):
        global rec, next_done
        next_done=0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.sequence(a1, a2)
        a_copy = node.do(composite)
        dt = 0.1
        next_done = 1
        node._step(dt)
        next_done = 0
        rec = []
        dt = 0.2
        node._step(dt)
        print rec

        assert 0==len([e for e in rec if e[0]==name1 ])
        assert rec[0]==(name2, 'step', dt)
        assert not a_copy.done()
Exemplo n.º 30
0
 def test_reaching_done2(self):
     global rec, next_done
     next_done=0
     node = CocosNode()
     name1 = '1'
     name2 = '2'
     a1 = UAction(name1)
     a2 = UAction(name2)
     composite = ac.sequence(a1, a2)
     a_copy = node.do(composite)
     dt = 0.1
     next_done = 1
     node._step(dt)
     next_done = 2
     rec = []
     dt = 0.2
     node._step(dt)
     print(rec)
     
     assert 0==len([e for e in rec if e[0]==name1 ])
     assert rec[0]==(name2, 'step', dt)
     assert rec[1]==(name2, 'stop')
     assert a_copy.done()
     assert len(rec)==2
    def test_test_receiving_stop_async_after_duration1_before_duration2(self, duration1, duration2):
        #0<duration2
        global rec

        if duration2==0.0:
            return
        
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        elapsed = 0.0
        rec = []
        composite = ac.sequence(a1, a2)
        a_copy = node.do(composite)
        next_elapsed = (duration1+duration2)/2.0
        dt = next_elapsed - elapsed
        node._step(dt)

        rec = []
        a_copy.stop()
        assert rec[0]==(name2, 'stop')
        assert len(rec)==1
    def test_update_below_duration1(self, duration1, duration2):
        global rec

        if duration1==0.0:
            return

        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UIntervalAction(name1, duration1)
        a2 = UIntervalAction(name2, duration2)
        composite = ac.sequence(a1, a2)
        node.do(composite)
        elapsed = 0.0
        # check cases 1st step and not 1st step
        for next_elapsed in [ duration1*0.5, duration1*0.75]:
            dt = next_elapsed - elapsed
            rec = []
            node._step(dt)
            rec = [ e for e in rec if e[1]!='step' ]
            print rec
            assert rec[0][1]=='update' and abs(rec[0][2]-next_elapsed/duration1)<fe
            assert len(rec)==1
            elapsed = next_elapsed
Exemplo n.º 33
0
    def test_reaching_done2(self):
        global rec, next_done
        next_done = 0
        node = CocosNode()
        name1 = '1'
        name2 = '2'
        a1 = UAction(name1)
        a2 = UAction(name2)
        composite = ac.sequence(a1, a2)
        a_copy = node.do(composite)
        dt = 0.1
        next_done = 1
        node._step(dt)
        next_done = 2
        rec = []
        dt = 0.2
        node._step(dt)
        print(rec)

        assert 0 == len([e for e in rec if e[0] == name1])
        assert rec[0] == (name2, 'step', dt)
        assert rec[1] == (name2, 'stop')
        assert a_copy.done()
        assert len(rec) == 2