This video teaches how to implement the Hungry Ant class in Python for the CS 61A Ants problem, covering class inheritance from the Ant class, defining class attributes (name='hungry', implemented=True, food_cost=4, chew_cooldown=3), creating instance attributes (cooldown=0) in the init method, and implementing the action method that checks if the ant is chewing (decrementing cooldown) or eats a random bee (reducing bee's health to zero and resetting cooldown).
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
[CS 61A SU26] Ants Problem Getting Started
Added:welcome to CS6 ants problem 7 we're told to implement the hungry ants which will select a random Bee from its place and deal damage to the bee equal to the bee's Health eating it whole after eating a bee a hungry ant must spend three turns chewing before being able to eat again while the hungry ant is chewing it is not able to eat or deal damage to any bees if there are no Bees in it place available to eat the hungry ant will do nothing we have not provided you with a class header so we're told to implement the hungry ant class from scratch and so given that we know that hungry ant is a class we can use the class keyword to create this hungry ant class and since we know that the hungry ant is an ant we can actually inherit from the existing ant class we are told to give this hungry ant Class A Class attribute name with the value hungry so the graphics work and also a class attribute implemented with the value true so we can use it in a game and so since these are class attributes we want to Define them directly inside this class and we can do so by doing this here so I set name oops sorry equal to hungry and implemented equal to true we're also given a hint that when a bee is eaten its Health should be reduced by its Health we're also given a table here that shows the class hungry ant the food cost four and the initial Health which is one and if we recall from the ant class the food cost is actually a class attribute so we can follow this pattern and also create food cost as a class attribute in the hungry ant class and set that equal to four we're also told to give hungry ant a chew cool down class attribute that stores a number of turns that it will take a Hungry ant to chew and we're told to set this to three so we can go ahead and create this two cool down class attribute and set it to three we're also told to give each hungry ant an instance attribute cool down that counts the number of turns it has left to chew initialize to zero since the hungry ant has not eaten anything at the beginning and so this would be an instance attribute as opposed to a class attribute so we would want to Define this in the init method to initialize the value to zero and we'll get onto that more later we can also think of cool down as the number of turns until a hungry ant can eat another bee we're also told to implement the action method of hungry ant which first checks if this hungry ant is chewing if so we decrement its cool down otherwise we eat a random bee in its place by reducing the bee's Health to zero make sure to set the cool down when a bee is eaten we're also given another hint that tells us other than the action method make sure you implement the init method too in order to Define any instance variables and make sure that hungry ant starts off with the appropriate amount of health and so this is related to the point that I made earlier about the difference between Class attributes and instance attributes so why don't we go ahead and get started with this init method and I'm just going to go ahead and write these methods in pseudo code just to make it a little easier to interpret so we know we want to start off with the appropriate amount of Health which is one and if we recall oop sorry if we recall we know that the ant class has an init method that also in initializes the health so we can try and use this method already defined in the ant class to initialize this health for us since the hungry ant inherits from the ant class so use ants in it method to initialize Health oops Health to one and we also want to set the instance attribute cool down to initialize that to zero and since this is an instance attribute we want to use the self keyword when initializing it so self do cooldown equal 0 and that's it for the init method now we can move on to the action method and so the first check that we're told to do in the action method is to check if the ant is chewing so if chewing then we want to decrement the cool down so decrement cool down uh specifically self. cooldown which we initialized earlier here else we want to eat a random bee in its place by reducing the bee's Health to zero and we're also told to make sure to set the cool down when a bee is eaten also if we recall from earlier in the state in this problem statement we're told that if there is no be in the place available to eat the hungry ant should do nothing so so let's start with this L statement so if this hungry ant is no longer chewing then we want to eat a random be so first we want to try and get this random B and we can do so by looking at the b class to see how we can use some of the functions there in order to get this random Fe and once we have this random B we want to make sure that there is a b available to eat so if uh random B exists then we want to proceed in order to eat this bee otherwise we want to do nothing so we can proceed now to eat this bee if it exists by reducing the be's Health to zero so here we want to reduce be Health to zero and once again we can do this by looking at the b class to find what methods there can help us reduce the be's Health specifically by its own health as given to us in this hint so reduce be Health to zero and I'll some add some notes you want to do this by Reduce by oops by own health and also we want to make sure to set the cool down when a be is eaten so we want to set this cool down by doing self. cooldown and we want to set this equal to this class attributes cool down which in this case is to cool down and so that is it for this getting started video I hope this helps you get started with the question and good luck
Related Videos

TOP 15 Data compression Interview Questions and Answers 2019 Part-2 | Data compression | Wisdom jobs
wisdomjobs
281 views•2019-06-28

CTS 158: 802.11w Management Frame Protection
ClearToSend
4K views•2019-02-04

NDSS 2019 Send Hardest Problems My Way: Probabilistic Path Prioritization for Hybrid Fuzzing
NDSSSymposium
496 views•2019-04-02

How realistic is Cities: Skylines?
CityBeautiful
159K views•2019-02-14

GUIs & TUIs: Choosing a User Interface for Your Python Project | Real Python Podcast
realpython
2K views•2025-04-04

The OSI Model - Explained by Example
hnasr
225K views•2019-05-12

Cloud Computing - Introduction
elithecomputerguy
98K views•2019-10-07

From Traveler's Dilemma to Dynamic Routing | Demystifying Networking
IITBombayJuly
5K views•2019-08-04
Trending

WOW! Judge TURNS THE TABLES on Trump in His OWN $10B LAWSUIT!!!
MeidasTouch
197K views•2026-07-23

Playstation NO DISC/NO BUY Fight Is Over...
DavidJaffeGames
4K views•2026-07-23

Steam and Xbox Just Dropped The Hammer On PlayStation
OhNoItsAlexx
9K views•2026-07-23

Americans Confused in Australia for 17 Minutes Straight
IWrocker
17K views•2026-07-23