def setUp(self):
    self.tb = Toybox('breakout')

    fire = Input()
    fire.button1 = True
    noop = Input()
    self.tb.apply_action(fire)
 def test_amidar_straight_up(self):
     with Toybox("amidar") as tb:
         up = Input()
         up.up = True
         score = 0
         while not tb.game_over():
             score = max(tb.get_score(), score)
             tb.apply_action(up)
         self.assertEqual(2, score)
 def test_amidar_straight_down(self):
     with Toybox("amidar") as tb:
         down_fire = Input()
         # down and fire!
         down_fire.down = True
         down_fire.button1 = True
         score = 0
         while not tb.game_over():
             score = max(tb.get_score(), score)
             tb.apply_action(down_fire)
         self.assertEqual(2, score)
Esempio n. 4
0
 def test_rand_start_10_seeds(self):
     with Toybox('breakout') as tb:
         balls = []
         input = Input()
         input.button1 = True
         for i in range(10):
             tb.set_seed(i)
             tb.new_game()
             tb.apply_action(input)
             json = tb.state_to_json()
             self.assertNotEqual(len(json['balls']), 0)
             balls.append(json['balls'][0])
         ball_xpos = [ball['position']['x'] for ball in balls]
         x = ball_xpos[0]
         # At least one of these should be different!
         self.assertFalse(all([bx == x for bx in ball_xpos]))
Esempio n. 5
0
def smoke_test(tb):
    print(tb.get_width(), tb.get_height())
    # Score and lives make sense!
    assert(tb.get_score() == 0)
    assert(tb.get_lives() > 0)

    for _ in range(100):
        # NOOP should work for every game.
        tb.apply_action(Input())
    
    # Color rendering should work.
    image = tb.get_rgb_frame()
Esempio n. 6
0
  def test_standard_eq(self):
    s1, s2, s3 = None, None, None
    with Toybox('breakout') as tb:

      fire = Input()
      fire.button1 = True
      noop = Input()
      tb.apply_action(fire)

      with BreakoutIntervention(tb) as intervention:
        s1 = intervention.game

      with BreakoutIntervention(tb) as intervention:
        s2 = intervention.game

      with BreakoutIntervention(tb) as intervention:
        intervention.game.paddle_speed = 10
        s3 = intervention.game
    
    self.assertEqual(s1, s2)
    self.assertNotEqual(s1, s3)
    self.assertNotEqual(s2, s3)
Esempio n. 7
0
        for brick in self.game.bricks:
            brick.alive = False


if __name__ == "__main__":
    import argparse
    from ctoybox import Toybox, Input

    parser = argparse.ArgumentParser(description='test Amidar interventions')
    parser.add_argument('--partial_config', type=str, default="null")
    parser.add_argument('--save_json', type=bool, default=False)
    args = parser.parse_args()

    with Toybox('breakout') as tb:

        fire = Input()
        fire.button1 = True
        noop = Input()
        tb.apply_action(fire)

        state = tb.to_state_json()
        config = tb.config_to_json()

        if args.save_json:
            # save a sample starting state and config
            with open(
                    'toybox/toybox/interventions/defaults/breakout_state_default.json',
                    'w') as outfile:
                json.dump(state, outfile)

            with open(