Ejemplo n.º 1
0
def part_two(args, input_lines):
    "Process part two of the puzzle"

    # 1. Create the astroids map
    a_map = asteroids.Asteroids(text=input_lines, verbose=args.verbose)

    # 2. Get the maximum number of asteroids viewable from one station
    solution = a_map.maximum()
    if not solution:
        print("Unable to determine maximum number of asteroids")
        return False

    print("Maximum asteroids can be detected = %d at (%d,%d)" %
          (solution[0], solution[1][0], solution[1][1]))

    # 3. Put a laser there
    mylaser = laser.Laser(center=solution[1], text=input_lines)

    # 4. Go shoot 'em up
    loc = mylaser.shoot_until(number=args.maxtime, verbose=args.verbose)

    # 5. Announce the result
    if loc is not None:
        solution = 100 * loc[0] + loc[1]
        print("Shot the %d asteroid at %s, solution is %d" %
              (args.maxtime, loc, solution))
    else:
        solution = None

    # 6. Return result
    return solution is not None
Ejemplo n.º 2
0
    def __init__(self, width, height, frame_rate):

        # Title of the application ""
        game.Game.__init__(self, "Asteroids", width, height, frame_rate)
        # Creates a game instance
        self.mGame = asteroids.Asteroids(width, height)
        return
 def setUp( self ):
     self.expected_rock_count = 10
     self.expected_object_count = 11
     self.expected_world_width = 800
     self.expected_world_height = 600
     self.constructed_obj = asteroids.Asteroids( self.expected_world_width, self.expected_world_height )
     
     return
Ejemplo n.º 4
0
    def __init__(self, title, width, height, frame_rate):

        game.Game.__init__(self, title, width, height, frame_rate)

        # create a game instance
        # YOU SHOULD CHANGE THIS TO IMPORT YOUR GAME MODULE
        self.mGame = asteroids.Asteroids(width, height)
        return
Ejemplo n.º 5
0
    def test_part_one_examples(self):
        """Test Asteroids object with examples from the part 1 problem"""

        # 1. Example 1
        myass = asteroids.Asteroids(text=P1_EXP1_TEXT)
        self.assertEqual(myass.maximum(), (8, (3, 4)))

        # 2. Example 2
        myass = asteroids.Asteroids(text=P1_EXP2_TEXT)
        self.assertEqual(myass.maximum(), (33, (5, 8)))

        # 3. Example 3
        myass = asteroids.Asteroids(text=P1_EXP3_TEXT)
        self.assertEqual(myass.maximum(), (35, (1, 2)))

        # 4. Example 4
        myass = asteroids.Asteroids(text=P1_EXP4_TEXT)
        self.assertEqual(myass.maximum(), (41, (6, 3)))

        # 5. Example 5
        myass = asteroids.Asteroids(text=P1_EXP5_TEXT)
        self.assertEqual(myass.maximum(), (210, (11, 13)))
Ejemplo n.º 6
0
    def test_text_init(self):
        "Test Asteroids object creation with text"

        # 1. Create Intcode obhect with values
        myass = asteroids.Asteroids(text=P1_EXP1_TEXT)

        # 2. Make sure it has the specified values
        self.assertEqual(myass.rows, 5)
        self.assertEqual(myass.cols, 5)
        self.assertEqual(len(myass.amap), 5)
        self.assertEqual(len(myass.knts), 5)
        self.assertEqual(myass.knts, P1_EXP1_KNTS)

        # 3. Check methods
        self.assertEqual(myass.maximum(), (8, (3, 4)))
Ejemplo n.º 7
0
    def test_empty_init(self):
        """Test default Asteroids object creation"""

        # 1. Create default Astroids object
        myass = asteroids.Asteroids()

        # 2. Make sure it has the default values
        self.assertEqual(myass.rows, 0)
        self.assertEqual(myass.cols, 0)
        self.assertEqual(len(myass.amap), 0)
        self.assertEqual(len(myass.knts), 0)

        # 3. Check methods
        self.assertEqual(myass.maximum(), None)
        self.assertEqual(str(myass), '')
Ejemplo n.º 8
0
def part_one(args, input_lines):
    "Process part one of the puzzle"

    # 1. Create the astroids map
    a_map = asteroids.Asteroids(text=input_lines, verbose=args.verbose)

    # 2. Get the maximum number of asteroids viewable from one station
    solution = a_map.maximum()
    if not solution:
        print("Unable to determine maximum number of asteroids")
    else:
        print("Maximum asteroids that can be detected is %d at %s" %
              (solution))

    # 3. Return result
    return solution is not None
Ejemplo n.º 9
0
    def test_add_next_row(self):
        "Test looking at the row below for asteroids"

        # 1. Create Intcode obhect with values
        myass = asteroids.Asteroids(text=P1_EXP1_TEXT, knts=False)

        # 2. Make sure it has the specified values
        self.assertEqual(myass.rows, 5)
        self.assertEqual(myass.cols, 5)
        self.assertEqual(len(myass.amap), 5)
        self.assertEqual(len(myass.knts), 5)

        # 3. Look to the right for all
        for rnum in range(myass.rows - 1):
            myass.add_next_row(rnum)

        # 3. Check methods
        self.assertEqual(myass.knts, P1_EXP1_ROW_BELOW_KNTS)
        self.assertEqual(myass.maximum(), (7, (4, 3)))
Ejemplo n.º 10
0
    def test_add_to_the_right(self):
        "Test looking to the right for asteroids"

        # 1. Create Intcode obhect with values
        myass = asteroids.Asteroids(text=P1_EXP1_TEXT, knts=False)

        # 2. Make sure it has the specified values
        self.assertEqual(myass.rows, 5)
        self.assertEqual(myass.cols, 5)
        self.assertEqual(len(myass.amap), 5)
        self.assertEqual(len(myass.knts), 5)

        # 3. Look to the right for all
        for rnum in range(myass.rows):
            myass.add_to_the_right(rnum)

        # 3. Check methods
        self.assertEqual(myass.knts, P1_EXP1_RIGHT_KNTS)
        self.assertEqual(myass.maximum(), (2, (1, 2)))
Ejemplo n.º 11
0
    def test_add_to_the_bottom(self):
        "Test looking at the column below for asteroids"

        # 1. Create Intcode obhect with values
        myass = asteroids.Asteroids(text=P1_EXP1_TEXT, knts=False)

        # 2. Make sure it has the specified values
        self.assertEqual(myass.rows, 5)
        self.assertEqual(myass.cols, 5)
        self.assertEqual(len(myass.amap), 5)
        self.assertEqual(len(myass.knts), 5)

        # 3. Look to the bottom for all
        for rnum in range(myass.rows - 1):
            #print("add_to_the_bottom(%d)" % (rnum))
            myass.add_to_the_bottom(rnum)
            #print(myass.str_knts())

        # 3. Check methods
        self.assertEqual(myass.knts, P1_EXP1_BOTTOM_KNTS)
        self.assertEqual(myass.maximum(), (1, (1, 0)))
Ejemplo n.º 12
0
    def __init__(self, title, width, height, frame_rate):

        game.Game.__init__(self, title, width, height, frame_rate)

        self.game = asteroids.Asteroids(width, height)
        return