fork(1) download
  1. """
  2. The ants module implements game logic for Ants Vs. SomeBees.
  3. Name: William Xu, Eric Shen
  4. Login: cs61a-ol, cs61a-op
  5. TA: Andrew Nguyen
  6. Section: 22
  7. """
  8.  
  9. import random
  10. import sys
  11. from ucb import main, interact, trace
  12. from collections import OrderedDict
  13.  
  14.  
  15. ################
  16. # Core Classes #
  17. ################
  18.  
  19.  
  20. class Place(object):
  21. """A Place holds insects and has an exit to another Place."""
  22.  
  23. def __init__(self, name, exit=None):
  24. """Create a Place with the given exit.
  25.  
  26. name -- A string; the name of this Place.
  27. exit -- The Place reached by exiting this Place (may be None).
  28. """
  29. self.name = name
  30. self.exit = exit
  31. self.bees = [] # A list of Bees
  32. self.ant = None # An Ant
  33. self.entrance = None # A Place
  34. # Phase 1: Add an entrance to the exit
  35. "*** YOUR CODE HERE ***"
  36. if self.exit != None:
  37. self.exit.entrance = self
  38.  
  39. def add_insect(self, insect):
  40. """Add an Insect to this Place.
  41.  
  42. There can be at most one Ant in a Place, unless exactly one of them is
  43. a BodyguardAnt (Phase 2), in which case there can be two. If add_insect
  44. tries to add more Ants than is allowed, an assertion error is raised.
  45.  
  46. There can be any number of Bees in a Place.
  47. """
  48. if insect.is_ant():
  49. # Phase 2: Special handling for BodyguardAnt
  50. "*** YOUR CODE HERE ***"
  51. if self.ant != None:
  52. if self.ant.can_contain(insect):#if it can contain an ant
  53. self.ant.contain_ant(insect)#then do so
  54. elif insect.can_contain(self.ant):
  55. insect.contain_ant(self.ant)
  56. self.ant = insect
  57. else:
  58. assert self.ant is None, 'Two ants in {0}'.format(self)
  59. else:
  60. self.ant = insect
  61. else:
  62. self.bees.append(insect)
  63. insect.place = self
  64.  
  65. def remove_insect(self, insect):
  66. """Remove an Insect from this Place."""
  67. if not insect.is_ant():
  68. self.bees.remove(insect)
  69. else:
  70. assert self.ant == insect, '{0} is not in {1}'.format(insect, self)
  71. "*** YOUR CODE HERE ***"
  72. if self.ant.name == 'Queen':
  73. if self.ant.true_queen == True:
  74. return
  75. self.ant = None
  76.  
  77. insect.place = None
  78.  
  79. def __str__(self):
  80. return self.name
  81.  
  82.  
  83. class Insect(object):
  84. """An Insect, the base class of Ant and Bee, has armor and a Place."""
  85.  
  86. watersafe = False
  87.  
  88. def __init__(self, armor, place=None):
  89. """Create an Insect with an armor amount and a starting Place."""
  90. self.armor = armor
  91. self.place = place # set by Place.add_insect and Place.remove_insect
  92.  
  93.  
  94. def reduce_armor(self, amount):
  95. """Reduce armor by amount, and remove the insect from its place if it
  96. has no armor remaining.
  97.  
  98. >>> test_insect = Insect(5)
  99. >>> test_insect.reduce_armor(2)
  100. >>> test_insect.armor
  101. 3
  102. """
  103. self.armor -= amount
  104. if self.armor <= 0:
  105. print('{0} ran out of armor and expired'.format(self))
  106. self.place.remove_insect(self)
  107.  
  108. def action(self, colony):
  109. """Perform the default action that this Insect takes each turn.
  110.  
  111. colony -- The AntColony, used to access game state information.
  112. """
  113.  
  114. def is_ant(self):
  115. """Return whether this Insect is an Ant."""
  116. return False
  117.  
  118. def __repr__(self):
  119. cname = type(self).__name__
  120. return '{0}({1}, {2})'.format(cname, self.armor, self.place)
  121.  
  122.  
  123. class Bee(Insect):
  124. """A Bee moves from place to place, following exits and stinging ants."""
  125.  
  126. name = 'Bee'
  127. watersafe = True
  128.  
  129. def sting(self, ant):
  130. """Attack an Ant, reducing the Ant's armor by 1."""
  131. ant.reduce_armor(1)
  132.  
  133. def move_to(self, place):
  134. """Move from the Bee's current Place to a new Place."""
  135. self.place.remove_insect(self)
  136. place.add_insect(self)
  137.  
  138. def blocked(self):
  139. """Return True if this Bee cannot advance to the next Place."""
  140. # Phase 2: Special handling for NinjaAnt
  141. "*** YOUR CODE HERE ***"
  142. if self.place.ant is not None:
  143. if self.place.ant.blocks_path == False:
  144. return False
  145. return True
  146. else:
  147. return False
  148.  
  149. def action(self, colony):
  150. """A Bee's action stings the Ant that blocks its exit if it is blocked,
  151. or moves to the exit of its current place otherwise.
  152.  
  153. colony -- The AntColony, used to access game state information.
  154. """
  155. if self.blocked():
  156. self.sting(self.place.ant)
  157. else:
  158. if self.place.name != 'Hive' and self.armor > 0:
  159. self.move_to(self.place.exit)
  160.  
  161.  
  162. class Ant(Insect):
  163. """An Ant occupies a place and does work for the colony."""
  164.  
  165. implemented = False # Only implemented Ant classes should be instantiated
  166. damage = 0
  167. food_cost = 0
  168. blocks_path = True
  169. container = False
  170.  
  171. def __init__(self, armor=1):
  172. """Create an Ant with an armor quantity."""
  173. Insect.__init__(self, armor)
  174.  
  175. def is_ant(self):
  176. return True
  177.  
  178. def can_contain(self, other):
  179. if self.container == True:
  180. if self.ant == None:
  181. if other.container == False:
  182. return True
  183. return False
  184.  
  185. class HarvesterAnt(Ant):
  186. """HarvesterAnt produces 1 additional food per turn for the colony."""
  187.  
  188. name = 'Harvester'
  189. implemented = True
  190. food_cost = 2
  191.  
  192. def action(self, colony):
  193. """Produce 1 additional food for the colony.
  194.  
  195. colony -- The AntColony, used to access game state information.
  196. """
  197. "*** YOUR CODE HERE ***"
  198. colony.food += 1
  199.  
  200. def random_or_none(l):
  201. """Return a random element of list l, or return None if l is empty."""
  202. return random.choice(l) if l else None
  203.  
  204. class ThrowerAnt(Ant):
  205. """ThrowerAnt throws a leaf each turn at the nearest Bee in its range."""
  206.  
  207. name = 'Thrower'
  208. implemented = True
  209. damage = 1
  210. food_cost = 4
  211. min_range = 0
  212. max_range = 10
  213.  
  214. def nearest_bee(self, hive):
  215. """Return the nearest Bee in a Place that is not the Hive, connected to
  216. the ThrowerAnt's Place by following entrances.
  217.  
  218. This method returns None if there is no such Bee.
  219.  
  220. Problem B5: This method returns None if there is no Bee in range.
  221. """
  222. other_place = self.place
  223. index = 0#checks which place number it has checked
  224. while other_place != hive:#stops at the bee hive
  225. if len(other_place.bees) > 0 and index >= self.min_range and index <= self.max_range:
  226. #checks if there are bees in the place and
  227. # checks if the bee is in range
  228. return random_or_none(other_place.bees)
  229. else:
  230. other_place = other_place.entrance#goes to next place
  231. index += 1#increments the range tracker
  232. return None#returns None if no such bees
  233.  
  234. def throw_at(self, target):
  235. """Throw a leaf at the target Bee, reducing its armor."""
  236. if target is not None:
  237. target.reduce_armor(self.damage)
  238.  
  239. def action(self, colony):
  240. """Throw a leaf at the nearest Bee in range."""
  241. self.throw_at(self.nearest_bee(colony.hive))
  242.  
  243. class Hive(Place):
  244. """The Place from which the Bees launch their assault.
  245.  
  246. assault_plan -- An AssaultPlan; when & where bees enter the colony.
  247. """
  248.  
  249. name = 'Hive'
  250.  
  251. def __init__(self, assault_plan):
  252. self.name = 'Hive'
  253. self.assault_plan = assault_plan
  254. self.bees = []
  255. for bee in assault_plan.all_bees:
  256. self.add_insect(bee)
  257. # The following attributes are always None for a Hive
  258. self.entrance = None
  259. self.ant = None
  260. self.exit = None
  261.  
  262. def strategy(self, colony):
  263. exits = [p for p in colony.places.values() if p.entrance is self]
  264. for bee in self.assault_plan.get(colony.time, []):
  265. bee.move_to(random.choice(exits))
  266.  
  267.  
  268. class AntColony(object):
  269. """An ant collective that manages global game state and simulates time.
  270.  
  271. Attributes:
  272. time -- elapsed time
  273. food -- the colony's available food total
  274. queen -- the place where the queen resides
  275. places -- A list of all places in the colony (including a Hive)
  276. bee_entrances -- A list of places that bees can enter
  277. """
  278. def __init__(self, strategy, hive, ant_types, create_places, food=4):
  279. """Create an AntColony for simulating a game.
  280.  
  281. Arguments:
  282. strategy -- a function to deploy ants to places
  283. hive -- a Hive full of bees
  284. ant_types -- a list of ant constructors
  285. create_places -- a function that creates the set of places
  286. """
  287. self.time = 0
  288. self.food = food
  289. self.strategy = strategy
  290. self.hive = hive
  291. self.ant_types = OrderedDict((a.name, a) for a in ant_types)
  292. self.configure(hive, create_places)
  293.  
  294. def configure(self, hive, create_places):
  295. """Configure the places in the colony."""
  296. self.queen = Place('AntQueen')
  297. self.places = OrderedDict()
  298. self.bee_entrances = []
  299. def register_place(place, is_bee_entrance):
  300. self.places[place.name] = place
  301. if is_bee_entrance:
  302. place.entrance = hive
  303. self.bee_entrances.append(place)
  304. register_place(self.hive, False)
  305. create_places(self.queen, register_place)
  306.  
  307. def simulate(self):
  308. """Simulate an attack on the ant colony (i.e., play the game)."""
  309. while len(self.queen.bees) == 0 and len(self.bees) > 0:
  310. self.hive.strategy(self) # Bees invade
  311. self.strategy(self) # Ants deploy
  312. for ant in self.ants: # Ants take actions
  313. if ant.armor > 0:
  314. ant.action(self)
  315. for bee in self.bees: # Bees take actions
  316. if bee.armor > 0:
  317. bee.action(self)
  318. self.time += 1
  319. if len(self.queen.bees) > 0:
  320. print('The ant queen has perished. Please try again.')
  321. else:
  322. print('All bees are vanquished. You win!')
  323.  
  324. def deploy_ant(self, place_name, ant_type_name):
  325. """Place an ant if enough food is available.
  326.  
  327. This method is called by the current strategy to deploy ants.
  328. """
  329. constructor = self.ant_types[ant_type_name]
  330. if self.food < constructor.food_cost:
  331. print('Not enough food remains to place ' + ant_type_name)
  332. else:
  333. self.places[place_name].add_insect(constructor())
  334. self.food -= constructor.food_cost
  335.  
  336. def remove_ant(self, place_name):
  337. """Remove an Ant from the Colony."""
  338. place = self.places[place_name]
  339. if place.ant is not None:
  340. place.remove_insect(place.ant)
  341.  
  342. @property
  343. def ants(self):
  344. return [p.ant for p in self.places.values() if p.ant is not None]
  345.  
  346. @property
  347. def bees(self):
  348. return [b for p in self.places.values() for b in p.bees]
  349.  
  350. @property
  351. def insects(self):
  352. return self.ants + self.bees
  353.  
  354. def __str__(self):
  355. status = ' (Food: {0}, Time: {1})'.format(self.food, self.time)
  356. return str([str(i) for i in self.ants + self.bees]) + status
  357.  
  358. def ant_types():
  359. """Return a list of all implemented Ant classes."""
  360. all_ant_types = []
  361. new_types = [Ant]
  362. while new_types:
  363. new_types = [t for c in new_types for t in c.__subclasses__()]
  364. all_ant_types.extend(new_types)
  365. return [t for t in all_ant_types if t.implemented]
  366.  
  367. def interactive_strategy(colony):
  368. """A strategy that starts an interactive session and lets the user make
  369. changes to the colony.
  370.  
  371. For example, one might deploy a ThrowerAnt to the first tunnel by invoking:
  372. colony.deploy_ant('tunnel_0_0', 'Thrower')
  373. """
  374. print('colony: ' + str(colony))
  375. msg = '<Control>-D (<Control>-Z <Enter> on Windows) completes a turn.\n'
  376. interact(msg)
  377.  
  378. def start_with_strategy(args, strategy):
  379. usage = """python3 [ants.py|ants_gui.py] [OPTIONS]
  380. Run the Ants vs. SomeBees project.
  381.  
  382. -h, --help Prints this help message
  383. -f, --full Loads a full layout and assault plan
  384. -w, --water Loads a full map with water.
  385. -i, --insane Loads an insane assault plan. Good luck!
  386. """
  387. if "-h" in args or "--help" in args:
  388. print(usage)
  389. return
  390. assault_plan = make_test_assault_plan()
  391. layout = test_layout
  392. if '-f' in args or '--full' in args:
  393. assault_plan = make_full_assault_plan()
  394. layout = dry_layout
  395. if '-w' in args or '--water' in args:
  396. layout = mixed_layout
  397. if '-i' in args or '--insane' in args:
  398. assault_plan = make_insane_assault_plan()
  399. AntColony(strategy, Hive(assault_plan), ant_types(), layout).simulate()
  400.  
  401.  
  402. ###########
  403. # Layouts #
  404. ###########
  405.  
  406. def mixed_layout(queen, register_place, length=8, tunnels=3, moat_frequency=3):
  407. """Register Places with the colony."""
  408. for tunnel in range(tunnels):
  409. exit = queen
  410. for step in range(length):
  411. if moat_frequency != 0 and (step + 1) % moat_frequency == 0:
  412. exit = Water('water_{0}_{1}'.format(tunnel, step), exit)
  413. else:
  414. exit = Place('tunnel_{0}_{1}'.format(tunnel, step), exit)
  415. register_place(exit, step == length - 1)
  416.  
  417. def test_layout(queen, register_place, length=8, tunnels=1):
  418. mixed_layout(queen, register_place, length, tunnels, 0)
  419.  
  420. def dry_layout(queen, register_place, length=8, tunnels=3):
  421. mixed_layout(queen, register_place, length, tunnels, 0)
  422.  
  423.  
  424. #################
  425. # Assault Plans #
  426. #################
  427.  
  428.  
  429. class AssaultPlan(dict):
  430. """The Bees' plan of attack for the Colony. Attacks come in timed waves.
  431.  
  432. An AssaultPlan is a dictionary from times (int) to waves (list of Bees).
  433.  
  434. >>> AssaultPlan().add_wave(4, 2)
  435. {4: [Bee(3, None), Bee(3, None)]}
  436. """
  437.  
  438. def __init__(self, bee_armor=3):
  439. self.bee_armor = bee_armor
  440.  
  441. def add_wave(self, time, count):
  442. """Add a wave at time with count Bees that have the specified armor."""
  443. bees = [Bee(self.bee_armor) for _ in range(count)]
  444. self.setdefault(time, []).extend(bees)
  445. return self
  446.  
  447. @property
  448. def all_bees(self):
  449. """Place all Bees in the hive and return the list of Bees."""
  450. return [bee for wave in self.values() for bee in wave]
  451.  
  452. def make_test_assault_plan():
  453. return AssaultPlan().add_wave(2, 1).add_wave(3, 1)
  454.  
  455. def make_full_assault_plan():
  456. plan = AssaultPlan().add_wave(2, 1)
  457. for time in range(3, 15, 2):
  458. plan.add_wave(time, 1)
  459. return plan.add_wave(15, 8)
  460.  
  461. def make_insane_assault_plan():
  462. plan = AssaultPlan(4).add_wave(1, 2)
  463. for time in range(3, 15):
  464. plan.add_wave(time, 1)
  465. return plan.add_wave(15, 20)
  466.  
  467.  
  468.  
  469. ##############
  470. # Extensions #
  471. ##############
  472.  
  473.  
  474. class Water(Place):
  475. """Water is a place that can only hold 'watersafe' insects."""
  476.  
  477. def add_insect(self, insect):
  478. """Add insect if it is watersafe, otherwise reduce its armor to 0."""
  479. "*** YOUR CODE HERE ***"
  480. Place.add_insect(self, insect)
  481. if insect.watersafe == False:
  482. insect.reduce_armor(insect.armor)
  483.  
  484.  
  485. class FireAnt(Ant):
  486. """FireAnt cooks any Bee in its Place when it expires."""
  487.  
  488. name = 'Fire'
  489. damage = 3
  490. food_cost = 4
  491. "*** YOUR CODE HERE ***"
  492. implemented = True
  493.  
  494. def reduce_armor(self, amount):
  495. "*** YOUR CODE HERE ***"
  496. if self.armor - amount <= 0:#if bee kills ant
  497. for bee in self.place.bees:
  498. bee.armor -= self.damage#inflicts damage
  499. new_bee_list = [] + self.place.bees #creates a copy of bee list in place
  500. for bee in new_bee_list:
  501. if bee.armor <= 0:#removes the bee in the original
  502. self.place.bees.remove(bee)
  503. Ant.reduce_armor(self, amount)#ant dies
  504.  
  505. class LongThrower(ThrowerAnt):
  506. """A ThrowerAnt that only throws leaves at Bees at least 3 places away."""
  507.  
  508. name = 'Long'
  509. min_range = 4
  510. max_range = 10
  511. food_cost = 3
  512. implemented = True
  513.  
  514. class ShortThrower(ThrowerAnt):
  515. """A ThrowerAnt that only throws leaves at Bees within 3 places."""
  516.  
  517. name = 'Short'
  518. min_range = 0
  519. max_range = 2
  520. food_cost = 3
  521. implemented = True
  522.  
  523. class WallAnt(Ant):
  524. """WallAnt is an Ant which has a large amount of armor."""
  525.  
  526. name = 'Wall'
  527. "*** YOUR CODE HERE ***"
  528. implemented = True
  529. food_cost = 4
  530.  
  531. def __init__(self):
  532. "*** YOUR CODE HERE ***"
  533. Ant.__init__(self)
  534. self.armor = 4
  535.  
  536.  
  537. class NinjaAnt(Ant):
  538. """NinjaAnt is an Ant which does not block the path and does 1 damage to
  539. all Bees in the exact same Place."""
  540.  
  541. name = 'Ninja'
  542. "*** YOUR CODE HERE ***"
  543. implemented = True
  544. food_cost = 6
  545. damage = 1
  546. blocks_path = False
  547.  
  548. def action(self, colony):
  549. "*** YOUR CODE HERE ***"
  550. for bee in self.place.bees:
  551. bee.armor -= self.damage
  552. new_bee_list = [] + self.place.bees
  553. for bee in new_bee_list:
  554. if bee.armor <= 0:
  555. self.place.bees.remove(bee)
  556.  
  557. class ScubaThrower(ThrowerAnt):
  558. """ScubaThrower is a ThrowerAnt which is watersafe."""
  559.  
  560. name = 'Scuba'
  561. food_cost = 5
  562. watersafe = True
  563. implemented = True
  564.  
  565.  
  566. class HungryAnt(Ant):
  567. """HungryAnt will take three "turns" to eat a Bee in the same space as it.
  568. While eating, the HungryAnt can't eat another Bee.
  569. """
  570. name = 'Hungry'
  571. time_to_digest = 3
  572. food_cost = 4
  573. implemented = True
  574.  
  575. def __init__(self):
  576. Ant.__init__(self)
  577. self.digesting = 0
  578.  
  579. def eat_bee(self, bee):
  580. bee.reduce_armor(bee.armor)#kills the bee instantly
  581. self.digesting = self.time_to_digest
  582.  
  583. def action(self, colony):
  584. if self.digesting > 0:#still digesting
  585. self.digesting = self.digesting - 1#decrements counter
  586. else:#it can eat
  587. bee = random_or_none(self.place.bees)#checks if there is a bee
  588. if bee != None:
  589. self.eat_bee(bee)
  590.  
  591. class BodyguardAnt(Ant):
  592. """BodyguardAnt provides protection to other Ants."""
  593. name = 'Bodyguard'
  594. "*** YOUR CODE HERE ***"
  595. implemented = True
  596. container = True
  597. food_cost = 4
  598. armor = 2
  599.  
  600. def __init__(self):
  601. Ant.__init__(self, 2)
  602. self.ant = None # The Ant hidden in this bodyguard
  603.  
  604. def contain_ant(self, ant):
  605. "*** YOUR CODE HERE ***"
  606. self.ant = ant
  607.  
  608. def reduce_armor(self, amount):
  609. "*** YOUR CODE HERE ***"
  610. if self.armor - amount <= 0:
  611. if self.ant != None:
  612. a = self.ant
  613. self.ant.place = self.place
  614. Ant.reduce_armor(self, amount)
  615. self.ant.place.add_insect(a)
  616. else:#in case bodyguard ant is just there by itself
  617. Ant.reduce_armor(self, amount)
  618. else:
  619. Ant.reduce_armor(self,amount)
  620.  
  621.  
  622. def action(self, colony):
  623. "*** YOUR CODE HERE ***"
  624. if self.ant != None:
  625. self.ant.action(colony)
  626.  
  627. class QueenPlace(object):
  628. """A special place that a QueenAnt is assigned. The game is over if a bee enters this place."""
  629. def __init__(self, name, place, colonyplace):
  630. self.name = name
  631. self.queen_place = place
  632. self.colony_place = colonyplace
  633.  
  634. @property
  635. def bees(self):
  636. return self.queen_place.bees + self.colony_place.bees
  637.  
  638.  
  639. class QueenAnt(ThrowerAnt):
  640. """The Queen of the colony. The game is over if a bee enters her place."""
  641.  
  642. name = 'Queen'
  643. "*** YOUR CODE HERE ***"
  644. implemented = True
  645. food_cost = 0
  646. queen_count = 0
  647. ants_behind = []
  648. true_queen = False
  649.  
  650. def __init__(self):
  651. ThrowerAnt.__init__(self, 1)
  652. "*** YOUR CODE HERE ***"
  653. QueenAnt.queen_count += 1
  654. if QueenAnt.queen_count == 1:
  655. self.true_queen = True
  656.  
  657. def action(self, colony):
  658. """A queen ant throws a leaf, but also doubles the damange of ants
  659. behind her. Imposter queens do only one thing: die."""
  660. "*** YOUR CODE HERE ***"
  661. #check if there's an imposter first
  662. if QueenAnt.queen_count >= 1 and self.true_queen == False:
  663. Ant.reduce_armor(self, self.armor)
  664. return
  665. #replace with QueenPlace
  666. colony.queen = QueenPlace('Queen Place', self.place, colony.queen)
  667. ThrowerAnt.action(self, colony)
  668. #finally cause every ant behind it to be 2x as powerful
  669. next_place = self.place.exit
  670. while next_place != None:
  671. ant = next_place.ant
  672. if ant != None:
  673. if not ant in self.ants_behind:
  674. ant.damage *= 2
  675. self.ants_behind += [ant]
  676. next_place = next_place.exit
  677.  
  678. #make sure can't be removed
  679.  
  680. class AntRemover(Ant):
  681. """Allows the player to remove ants from the board in the GUI."""
  682.  
  683. name = 'Remover'
  684. implemented = True
  685.  
  686. def __init__(self):
  687. Ant.__init__(self, 0)
  688.  
  689.  
  690. ##################
  691. # Status Effects #
  692. ##################
  693.  
  694. def make_slow(action):
  695. """Return a new action method that calls action every other turn.
  696.  
  697. action -- An action method of some Bee
  698. """
  699. "*** YOUR CODE HERE ***"
  700. def new_action(colony):
  701. if colony.time % 2 == 0:
  702. return action
  703. return new_action
  704.  
  705. def make_stun(action):
  706. """Return a new action method that does nothing.
  707.  
  708. action -- An action method of some Bee
  709. """
  710. "*** YOUR CODE HERE ***"
  711. def new_action(colony):
  712. return
  713. return new_action
  714.  
  715. def apply_effect(effect, bee, duration):
  716. """Apply a status effect to a Bee that lasts for duration turns."""
  717. "*** YOUR CODE HERE ***"
  718. original_action = bee.action
  719. new_action = effect(bee.action)
  720. duration_counter = 0
  721.  
  722. def function(b):
  723. nonlocal duration_counter
  724. if duration_counter > 0:
  725. b.action = new_action
  726. duration_counter -= 1
  727. else:
  728. b.action = original_action
  729.  
  730. return function(bee)
  731.  
  732.  
  733.  
  734. class SlowThrower(ThrowerAnt):
  735. """ThrowerAnt that causes Slow on Bees."""
  736.  
  737. name = 'Slow'
  738. "*** YOUR CODE HERE ***"
  739. implemented = False
  740. food_cost = 4
  741.  
  742. def throw_at(self, target):
  743. if target:
  744. apply_effect(make_slow, target, 3)
  745.  
  746.  
  747. class StunThrower(ThrowerAnt):
  748. """ThrowerAnt that causes Stun on Bees."""
  749.  
  750. name = 'Stun'
  751. "*** YOUR CODE HERE ***"
  752. implemented = False
  753. food_cost = 6
  754.  
  755. def throw_at(self, target):
  756. if target:
  757. apply_effect(make_stun, target, 1)
  758.  
  759. @main
  760. def run(*args):
  761. start_with_strategy(args, interactive_strategy)
  762.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:1: error: class, interface, or enum expected
"""
^
Main.java:1: error: unclosed string literal
"""
  ^
Main.java:7: error: unclosed string literal
"""
  ^
Main.java:9: error: '.' expected
import random
             ^
Main.java:10: error: ';' expected
import sys
      ^
Main.java:11: error: class, interface, or enum expected
from ucb import main, interact, trace
^
Main.java:11: error: '.' expected
from ucb import main, interact, trace
                    ^
Main.java:11: error: ';' expected
from ucb import main, interact, trace
                     ^
Main.java:11: error: class, interface, or enum expected
from ucb import main, interact, trace
                              ^
Main.java:11: error: class, interface, or enum expected
from ucb import main, interact, trace
                                ^
Main.java:15: error: illegal character: \35
################
^
Main.java:15: error: illegal character: \35
################
 ^
Main.java:15: error: illegal character: \35
################
  ^
Main.java:15: error: illegal character: \35
################
   ^
Main.java:15: error: illegal character: \35
################
    ^
Main.java:15: error: illegal character: \35
################
     ^
Main.java:15: error: illegal character: \35
################
      ^
Main.java:15: error: illegal character: \35
################
       ^
Main.java:15: error: illegal character: \35
################
        ^
Main.java:15: error: illegal character: \35
################
         ^
Main.java:15: error: illegal character: \35
################
          ^
Main.java:15: error: illegal character: \35
################
           ^
Main.java:15: error: illegal character: \35
################
            ^
Main.java:15: error: illegal character: \35
################
             ^
Main.java:15: error: illegal character: \35
################
              ^
Main.java:15: error: illegal character: \35
################
               ^
Main.java:16: error: illegal character: \35
# Core Classes #
^
Main.java:16: error: illegal character: \35
# Core Classes #
               ^
Main.java:17: error: illegal character: \35
################
^
Main.java:17: error: illegal character: \35
################
 ^
Main.java:17: error: illegal character: \35
################
  ^
Main.java:17: error: illegal character: \35
################
   ^
Main.java:17: error: illegal character: \35
################
    ^
Main.java:17: error: illegal character: \35
################
     ^
Main.java:17: error: illegal character: \35
################
      ^
Main.java:17: error: illegal character: \35
################
       ^
Main.java:17: error: illegal character: \35
################
        ^
Main.java:17: error: illegal character: \35
################
         ^
Main.java:17: error: illegal character: \35
################
          ^
Main.java:17: error: illegal character: \35
################
           ^
Main.java:17: error: illegal character: \35
################
            ^
Main.java:17: error: illegal character: \35
################
             ^
Main.java:17: error: illegal character: \35
################
              ^
Main.java:17: error: illegal character: \35
################
               ^
Main.java:20: error: '{' expected
class Place(object):
           ^
Main.java:24: error: unclosed string literal
        """Create a Place with the given exit.
          ^
Main.java:26: error: ';' expected
        name -- A string; the name of this Place.
                                  ^
Main.java:26: error: <identifier> expected
        name -- A string; the name of this Place.
                                     ^
Main.java:27: error: <identifier> expected
        exit -- The Place reached by exiting this Place (may be None).
            ^
Main.java:27: error: ';' expected
        exit -- The Place reached by exiting this Place (may be None).
                         ^
Main.java:27: error: ';' expected
        exit -- The Place reached by exiting this Place (may be None).
                                    ^
Main.java:27: error: <identifier> expected
        exit -- The Place reached by exiting this Place (may be None).
                                            ^
Main.java:27: error: ')' expected
        exit -- The Place reached by exiting this Place (may be None).
                                                               ^
Main.java:27: error: illegal start of type
        exit -- The Place reached by exiting this Place (may be None).
                                                                    ^
Main.java:27: error: <identifier> expected
        exit -- The Place reached by exiting this Place (may be None).
                                                                     ^
Main.java:27: error: ';' expected
        exit -- The Place reached by exiting this Place (may be None).
                                                                      ^
Main.java:28: error: unclosed string literal
        """
          ^
Main.java:29: error: illegal start of type
        self.name = name
            ^
Main.java:29: error: ';' expected
        self.name = name
             ^
Main.java:29: error: illegal start of type
        self.name = name
                  ^
Main.java:29: error: ';' expected
        self.name = name
                        ^
Main.java:30: error: <identifier> expected
        self.exit = exit
                 ^
Main.java:30: error: ';' expected
        self.exit = exit
                        ^
Main.java:31: error: <identifier> expected
        self.bees = []        # A list of Bees
                 ^
Main.java:31: error: illegal start of expression
        self.bees = []        # A list of Bees
                    ^
Main.java:31: error: illegal start of type
        self.bees = []        # A list of Bees
                     ^
Main.java:31: error: illegal character: \35
        self.bees = []        # A list of Bees
                              ^
Main.java:31: error: ';' expected
        self.bees = []        # A list of Bees
                               ^
Main.java:31: error: ';' expected
        self.bees = []        # A list of Bees
                                         ^
Main.java:32: error: ';' expected
        self.ant = None       # An Ant
            ^
Main.java:32: error: <identifier> expected
        self.ant = None       # An Ant
                ^
Main.java:32: error: illegal character: \35
        self.ant = None       # An Ant
                              ^
Main.java:32: error: ';' expected
        self.ant = None       # An Ant
                                      ^
Main.java:33: error: <identifier> expected
        self.entrance = None  # A Place
                     ^
Main.java:33: error: illegal character: \35
        self.entrance = None  # A Place
                              ^
Main.java:34: error: illegal character: \35
        # Phase 1: Add an entrance to the exit
        ^
Main.java:34: error: <identifier> expected
        # Phase 1: Add an entrance to the exit
               ^
Main.java:34: error: illegal start of type
        # Phase 1: Add an entrance to the exit
                 ^
Main.java:34: error: ';' expected
        # Phase 1: Add an entrance to the exit
                      ^
Main.java:34: error: ';' expected
        # Phase 1: Add an entrance to the exit
                                  ^
Main.java:34: error: ';' expected
        # Phase 1: Add an entrance to the exit
                                         ^
Main.java:34: error: <identifier> expected
        # Phase 1: Add an entrance to the exit
                                              ^
Main.java:36: error: illegal start of type
        if self.exit != None:
        ^
Main.java:36: error: ';' expected
        if self.exit != None:
               ^
Main.java:36: error: <identifier> expected
        if self.exit != None:
                    ^
Main.java:36: error: <identifier> expected
        if self.exit != None:
                            ^
Main.java:37: error: <identifier> expected
            self.exit.entrance = self
                              ^
Main.java:37: error: ';' expected
            self.exit.entrance = self
                                     ^
Main.java:39: error: <identifier> expected
    def add_insect(self, insect):
                       ^
Main.java:39: error: <identifier> expected
    def add_insect(self, insect):
                               ^
Main.java:39: error: ';' expected
    def add_insect(self, insect):
                                ^
Main.java:40: error: unclosed string literal
        """Add an Insect to this Place.
          ^
Main.java:47: error: unclosed string literal
        """
          ^
Main.java:49: error: illegal character: \35
            # Phase 2: Special handling for BodyguardAnt
            ^
Main.java:52: error: illegal character: \35
                if self.ant.can_contain(insect):#if it can contain an ant
                                                ^
Main.java:53: error: illegal character: \35
                    self.ant.contain_ant(insect)#then do so
                                                ^
Main.java:58: error: unclosed character literal
                    assert self.ant is None, 'Two ants in {0}'.format(self)
                                             ^
Main.java:58: error: not a statement
                    assert self.ant is None, 'Two ants in {0}'.format(self)
                                                           ^
Main.java:58: error: ';' expected
                    assert self.ant is None, 'Two ants in {0}'.format(self)
                                                            ^
Main.java:58: error: unclosed character literal
                    assert self.ant is None, 'Two ants in {0}'.format(self)
                                                             ^
100 errors
stdout
Standard output is empty