Virtual Cockfight Assignment

From Knowledge Kitchen
Jump to navigation Jump to search


Overview

Your assignment is to make a prize-winning virtual chicken. Your chicken will fight other chickens, one-at-a-time in a chicken-fighting tournament.

Based on the virtual chicken fight example, create a sub-class of FuriousChicken that contains an overridden make_your_move() function, just as JitteryChicken does. Whereas JitteryChicken decides what to do randomly, your chicken should be more deliberate and thoughtful.


Function reference

Here is a reference to all the functions available to you:

Get information about a chicken

  • get_health(body_part)
    • argument: a string representing a body part (e.g. "left eye")
    • returns: an int representing the health of that body part (e.g 90)
  • get_average_health()
    • returns: a float representing the chickens average health (e.g. 79.9)
  • get_opponent()
    • returns: the opponent chicken, as an object
  • get_body_parts()
    • returns: a list of all of the chicken's body parts (this is only for advanced students who understand lists)

Example:

def make_your_move(self):

    #get the opponent chicken in a variable
    o = self.get_opponent

    #get each chicken's overall health
    mh = self.get_average_health()
    oh = o.get_average_health()
 
    #get the health score of the opponent chicken's eyes
    ole = o.get_health("left eye")
    ore = o.get_health("right eye")

Have a chicken perform an action

  • recuperate()
  • defend(body_part)
    • argument: a string representing a body part to defend (e.g. "left eye")
  • attack(body_part)
    • argument: a string representing a body part to attack (e.g. "left eye")
    #...continued from above

    #have your chicken do one of the actions
    if mh < 50:
        self.recuperate()
    elif ole > 75:
        self.attack("left eye")
    else:
        self.defend("left eye")

Strategy

This make_your_move() function is automatically called once every round. So, within this function, your chicken will need to decide what to do with every round. The options are:

  • recuperate - to rest and gain back some health points
  • attack - to attack the opposing chicken at a specific body part
  • defend - to defend against an attack from the opposing chicken on a specific body part

Opponent information

Each chicken has an opponent in the fight.

  • Each chicken has a function get_opponent(), which returns the opponent chicken object. This can be useful if you want to find out what the opponent chicken is up to from within your chicken's code.
  • Comparing the opponent chicken's status with your personal chicken's status might be an important part of your strategy.
opponent = self.get_opponent()

Health

Each chicken starts off with 100% health on each of its body part. When any chicken reaches 0% health on all body parts, the match is over.

  • you can find out each chicken's health of any given body part by calling its get_health() function, with a specific body part as the argument. The function returns the health of that body part as an int
  • if you want to find out the overall average health of a chicken's body parts, you can call its get_average_health() function, which returns the average health as an int
  • note that the chicken with the better health decides what move to make first 80% of the time

Attacking

If your chicken decides to attack, it must decide which body part of the opposing chicken to attack.

  • you can tell your chicken to attack the other chicken by calling its attack() function, with a string value argument representing which body part of the opponent chicken to attack
  • successfully injuring the opponent chicken can cause that chicken to lose 25% health points on that body part

Defending

If your chicken decides to defend, it must decide which body part of its own to defend against attack. Use the functions available to you from FuriousChicken to help make your decision.

  • you can tell your chicken to defend itself, by calling its defend() function, with a string value argument representing which body part to defend

Recuperating

If your chicken has a low health rating, recuperating is a good way to earn back some health points. But it comes at the sacrifice of not being able to attack or defend at the same time.

  • you can tell your chicken to recuperate, by calling its recuperate() function
  • recuperating earns 5 health points on all body parts

Body parts

Each chicken starts out life with the following body parts:

  • "left leg" and "right leg"
  • "left foot" and "right foot"
  • "left breast" and "right breast"
  • "left wing" and "right wing"
  • "left eye" and "right eye"
  • "beak"
  • "wattle"
  • "comb"


To get a list of the currently available body parts, each chicken has a get_body_parts() function, which returns this list.

Requirements

  • pick a unique name for your class
  • override only the make_your_move() function of FuriousChicken, but leave all other functions as-is
  • put logic into the make_your_move() function that allows your chicken to decide what to do at any given moment (attack, defend, or recuperate)
  • use the various functions mentioned above (and only those functions) to help you program your chicken's decision-making
  • you are not allowed to read or set any of the properties (a.k.a variables) in each the chicken objects directly, but must rather use the methods mentioned here
  • test out the performance of your chicken by replacing JitteryChicken with your chicken class in the chicken_fight.py code. Perhaps try one of your chickens against a Jittery chicken to see if yours performs better than a chicken that makes random decisions.


What links here