Phase 3 - More Ants!

We now have some great offensive troops to help vanquish the bees, but let's make sure we're also keeping our defensive efforts up. In this phase you will implement ants that have special defensive capabilities such as increased armor and the ability to protect other ants.

Problem 8

Specs: https://inst.eecs.berkeley.edu/~cs61a/su19/proj/ants/#problem-8-1-pt

# BEGIN Problem 8
# The WallAnt class
class WallAnt(Ant):
    name = 'Wall'
    food_cost = 4
    implemented = True
    def __init__(self, armor=4):
        self.armor = armor

# END Problem 8

Problem 9

Specs: https://inst.eecs.berkeley.edu/~cs61a/su19/proj/ants/#problem-9-4-pt

class BodyguardAnt(Ant):
    """BodyguardAnt provides protection to other Ants."""

    name = 'Bodyguard'
    food_cost = 4
    is_container = True
    # OVERRIDE CLASS ATTRIBUTES HERE
    # BEGIN Problem 9
    implemented = True   # Change to True to view in the GUI
    # END Problem 9

    def __init__(self, armor=2):
        Ant.__init__(self, armor)
        self.contained_ant = None  # The Ant hidden in this bodyguard

    def can_contain(self, other):
        # BEGIN Problem 9
        "*** YOUR CODE HERE ***"
        return not other.is_container and not self.contained_ant
        # END Problem 9

    def contain_ant(self, ant):
        # BEGIN Problem 9
        "*** YOUR CODE HERE ***"
        self.contained_ant = ant
        # END Problem 9

    def action(self, colony):
        # BEGIN Problem 9
        "*** YOUR CODE HERE ***"
        if self.contained_ant:
            self.contained_ant.action(colony)
        # END Problem 9

Problem 10

Specs: https://inst.eecs.berkeley.edu/~cs61a/su19/proj/ants/#problem-10-1-pt

class TankAnt(BodyguardAnt):
    """TankAnt provides both offensive and defensive capabilities."""

    name = 'Tank'
    damage = 1
    food_cost = 6
    # OVERRIDE CLASS ATTRIBUTES HERE
    # BEGIN Problem 10
    implemented = False   # Change to True to view in the GUI
    # END Problem 10

    def action(self, colony):
        # BEGIN Problem 10
        "*** YOUR CODE HERE ***"
        bees = list(colony.bees)

        for bee in bees:
            Insect.reduce_armor(bee, self.damage)

        if self.contained_ant:
            self.contained_ant.action(colony)
        # END Problem 10

Last updated