‘name’: ‘Problem 5’,
‘points’: 7,
‘suites’: [
‘cases’: [
Copyright By PowCoder代写 加微信 powcoder
‘answer’: ’85effb03bb8322771f6200ad2f37342f’,
‘choices’: [
‘By accessing the place instance attribute, which is a Place object’,
By accessing the place instance attribute, which is the name of
some Place object
‘By calling the Place constructor, passing in the FireAnt instance’,
‘By calling the FireAnt constructor’
‘hidden’: False,
‘locked’: True,
‘multiline’: False,
‘question’: ‘How can you obtain the current place of a FireAnt?’
‘answer’: ’41da24ae355d8821ef79ab7c01a0ddef’,
‘choices’: [
By accessing the bees instance attribute, which is a list of Bee
By accessing the bees instance attribute, which is a dictionary of
Bee objects
‘By calling the add_insect method on the place instance’,
‘By calling the Bee constructor, passing in the place instance’
‘hidden’: False,
‘locked’: True,
‘multiline’: False,
‘question’: ‘How can you obtain all of the Bees currently in a given place?’
‘answer’: ‘1c42340b1fffff1e62120398655b91e2’,
‘choices’: [
Yes, but you should iterate over a copy of the list to avoid skipping
‘Yes, you can mutate a list while iterating over it with no problems’,
No, Python doesn’t allow list mutation on a list that is being
iterated through
‘hidden’: False,
‘locked’: True,
‘multiline’: False,
‘question’: ‘Can you iterate over a list while mutating it?’
‘scored’: False,
‘type’: ‘concept’
‘cases’: [
‘code’: r”””
>>> # Testing FireAnt parameters
>>> fire = FireAnt()
>>> FireAnt.food_cost
4c973153c4739175edf72f69c49c509d
>>> fire.health
e22b4783782de9e5b17a082cf33c6f51
‘hidden’: False,
‘locked’: True,
‘multiline’: False
‘code’: r”””
>>> # Abstraction tests
>>> original = Ant.__init__
>>> Ant.__init__ = lambda self, health: print(“init”) #If this errors, you are not calling the parent constructor correctly.
>>> fire = FireAnt()
>>> Ant.__init__ = original
>>> fire = FireAnt()
>>> original = Ant.reduce_health
>>> Ant.reduce_health = lambda self, amount: print(“reduced”) #If this errors, you are not calling the inherited method correctly
>>> place = gamestate.places[‘tunnel_0_4’]
>>> place.add_insect(fire)
>>> fire.reduce_health(1)
>>> Ant.reduce_health = original
‘hidden’: False,
‘locked’: False,
‘multiline’: False
‘code’: r”””
>>> # Testing fire does damage to all Bees in its Place
>>> place = gamestate.places[‘tunnel_0_4’]
>>> fire = FireAnt(health=1)
>>> place.add_insect(fire) # Add a FireAnt with 1 health
>>> place.add_insect(Bee(3)) # Add a Bee with 3 health
>>> place.add_insect(Bee(5)) # Add a Bee with 5 health
>>> len(place.bees) # How many bees are there?
1218df75a941ebc08cec539b1f16208f
>>> place.bees[0].action(gamestate) # The first Bee attacks FireAnt
>>> fire.health
40031e7755cbca1da159a160d30dbc21
>>> fire.place is None
154afc22815a37701b5fa71e532da526
>>> len(place.bees) # How many bees are left?
10d7626438082950badf2b6216f9b0a8
>>> place.bees[0].health # What is the health of the remaining Bee?
10d7626438082950badf2b6216f9b0a8
‘hidden’: False,
‘locked’: True,
‘multiline’: False
‘code’: r”””
>>> place = gamestate.places[‘tunnel_0_4’]
>>> ant = FireAnt(health=1) # Create a FireAnt with 1 health
>>> place.add_insect(ant) # Add a FireAnt to place
>>> ant.place is place
154afc22815a37701b5fa71e532da526
>>> place.remove_insect(ant) # Remove FireAnt from place
>>> ant.place is place # Is the ant’s place still that place?
e0390565eddec8c7f85375354a9d8b87
‘hidden’: False,
‘locked’: True,
‘multiline’: False
‘code’: r”””
>>> # Testing fire damage when the fire ant does not die
>>> place = gamestate.places[‘tunnel_0_4’]
>>> bee = Bee(5)
>>> ant = FireAnt(health=100)
>>> place.add_insect(bee)
>>> place.add_insect(ant)
>>> bee.action(gamestate) # attack the FireAnt
>>> ant.health
>>> bee.health
‘hidden’: False,
‘locked’: False,
‘multiline’: False
‘code’: r”””
>>> # Testing no hardcoded 3
>>> place = gamestate.places[‘tunnel_0_4’]
>>> bee = Bee(100)
>>> ant = FireAnt(health=1)
>>> ant.damage = 49
>>> place.add_insect(bee)
>>> place.add_insect(ant)
>>> bee.action(gamestate) # attack the FireAnt
>>> ant.health
>>> bee.health
‘hidden’: False,
‘locked’: False,
‘multiline’: False
‘code’: r”””
>>> # Testing fire damage when the fire ant does die
>>> place = gamestate.places[‘tunnel_0_4’]
>>> bee = Bee(5)
>>> ant = FireAnt(health=1)
>>> place.add_insect(bee)
>>> place.add_insect(ant)
>>> bee.action(gamestate) # attack the FireAnt
>>> ant.health
>>> bee.health
‘hidden’: False,
‘locked’: False,
‘multiline’: False
‘code’: r”””
>>> # Testing fire does damage to all Bees in its Place
>>> place = gamestate.places[‘tunnel_0_4’]
>>> place.add_insect(FireAnt(1))
>>> for i in range(100): # Add 100 Bees with 3 health
… place.add_insect(Bee(3))
>>> place.bees[0].action(gamestate) # The first Bee attacks FireAnt
>>> len(place.bees) # How many bees are left?
‘hidden’: False,
‘locked’: False,
‘multiline’: False
‘code’: r”””
>>> # Testing fire damage is instance attribute
>>> place = gamestate.places[‘tunnel_0_4’]
>>> bee = Bee(900)
>>> buffAnt = FireAnt(1)
>>> buffAnt.damage = 500 # Feel the burn!
>>> place.add_insect(bee)
>>> place.add_insect(buffAnt)
>>> bee.action(gamestate) # attack the FireAnt
>>> bee.health # is damage an instance attribute?
‘hidden’: False,
‘locked’: False,
‘multiline’: False
‘code’: r”””
>>> # General FireAnt Test
>>> place = gamestate.places[‘tunnel_0_4’]
>>> bee = Bee(10)
>>> ant = FireAnt(1)
>>> place.add_insect(bee)
>>> place.add_insect(ant)
>>> bee.action(gamestate) # Attack the FireAnt
>>> bee.health
>>> ant.health
>>> place.ant is None # The FireAnt should not occupy the place anymore
>>> bee.action(gamestate)
>>> bee.health # Bee should not get damaged again
>>> bee.place.name # Bee should not have been blocked
‘tunnel_0_3’
‘hidden’: False,
‘locked’: False,
‘multiline’: False
‘code’: r”””
>>> # General FireAnt Test
>>> place = gamestate.places[‘tunnel_0_4’]
>>> bee = Bee(10)
>>> ant = FireAnt()
>>> place.add_insect(bee)
>>> place.add_insect(ant)
>>> ant.reduce_health(0.1) # Poke the FireAnt
>>> bee.health # Bee should only get slightly damaged
>>> ant.health
>>> place.ant is ant # The FireAnt should still be at place
‘hidden’: False,
‘locked’: False,
‘multiline’: False
‘code’: r”””
>>> # test proper call to death callback
>>> original_death_callback = Insect.death_callback
>>> Insect.death_callback = lambda x: print(“insect died”)
>>> place = gamestate.places[“tunnel_0_0″]
>>> bee = Bee(3)
>>> ant = FireAnt()
>>> place.add_insect(bee)
>>> place.add_insect(ant)
>>> bee.action(gamestate)
>>> bee.action(gamestate)
>>> bee.action(gamestate) # if you fail this test you probably didn’t correctly call Ant.reduce_health or Insect.reduce_health
insect died
insect died
>>> Insect.death_callback = original_death_callback
‘hidden’: False,
‘locked’: False,
‘multiline’: False
‘scored’: True,
‘setup’: r”””
>>> from ants import *
>>> beehive, layout = Hive(AssaultPlan()), dry_layout
>>> dimensions = (1, 9)
>>> gamestate = GameState(None, beehive, ant_types(), layout, dimensions)
‘teardown’: ”,
‘type’: ‘doctest’
‘cases’: [
‘code’: r”””
>>> from ants import *
>>> FireAnt.implemented
‘hidden’: False,
‘locked’: False,
‘multiline’: False
‘scored’: True,
‘setup’: ”,
‘teardown’: ”,
‘type’: ‘doctest’
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com