2nd Semester Intro to Computer Science

What you will learn

Project

In this project we will be creating a basic implementation of Pokemon, and then create a game for them to battle. This project will have three steps. The Pokemon Classes, the User classes, and the game loop.

Overview

9 Pokemon

Each Pokemon comes from 1 of 3 types:

  1. Grass
  2. fire
  3. water

Classes

You will be given a base Pokemon class which the grass, fire, and water classes will inherit from.

Class: User

Class: Computer

Attacks

All Pokemon of the same type have the same set of attacks, one of the following:

  1. hp (hit points)
  2. pp(power points)
  3. name.

Game Loop

Before the battle begins, Ask the user:

  1. Name
  2. Computer Name

Battle Pairing

  1. Ask the user to pick 3 Pokemon for their hand
  2. Randomly select the computer’s Pokemon from the remaining Pokemon.
  3. Ask the user which Pokemon they would like to use in battle with currently
  4. Randomly select one for the Computer
  5. Battle begins.

Each Turn

The user will be given the option to

  1. attack
  2. heal
  3. switch.
  4. Computer will be randomly selected, but should more frequently be attack.

Attack

Gives the user the options

  1. attacks the Pokemon
  2. pick one to attack with

Attack Name

An attack has a name, and corresponds to a list of the power of the attack and the accuracy.

An Attack should

  1. be a random number in the range between the attack power(or the pp if that is lower than the attack power) - 20
  2. the attack power (or the pp if that is lower than the attack power)
  3. randomly fail according to the attack’s accuracy.
  4. decrease the enemy’s hp, and print out a useful description.
  5. The computer randomly selects an attack to use in the battle.

Heal

  1. Gives 20 HP back to the current Pokemon,
  2. Takes away the turn

Switch

  1. Lists the stats (HP, AP, Name) of all Pokemon in the hand, and then
  2. switches the current Pokemon
  3. takes away the turn.
  4. On the computer’s turn if this option is randomly selected, choose a random Pokemon to switch with
  5. If either the user’s or the computer’s current Pokemon is out of HP, they will be required to switch Pokemon
  6. If there are no available Pokemon, that player has lost.

Continue looping until one player has lost

Behaviour

Game Play
>>> Ash is attacking. Bulbosaur used Leaf Storm and did 20 damage.
Computer

Pokemon Attacks

All Pokemon of the same type have the same Attacks.

Grass Type

All grass type have the following attacks:

Fire Type

All fire type have the following attacks

Water Type

All fire type have the following attacks:

Implementation Details

Check Point 1

Implement the following:

Check Point 2

Implement the following:

Computer class

Check Point 3

Implement the following

Alternate Project

Created by Brian Weinfeld

In this project, you will use dictionaries, lists and objects with Python to create a program that generates mailing lists for advertisers.

Overview

Every company stores data on its users and a common use of this data is to send relevant advertisements. If the company can track your interests, they can email you when they are selling something they think you may want to purchase. This project consists of several common functions designed to identify which customers you want to send advertisements to.

Details

Behavior

What would you like to do? (add, count, send, display, exit) add
Enter name email and hobbies: Alice a_person@host.com horses,traveling
a_person@host.com is not in our list
a_person@host.com has been added to our list

What would you like to do? (add, count, send, display, exit) add
Enter name email and hobbies: Blake myemail@host.com school
myemail@host.com is not in our list
myemail@host.com has been added to our list

What would you like to do? (add, count, send, display, exit) display
a_person@host.com Alice ['horses', 'traveling']
myemail@host.com Blake ['school']

What would you like to do? (add, count, send, display, exit) add
Enter name email and hobbies: Alice a_person@host.com sleeping
a_person@host.com is already in our list
Added sleeping to a_person@host.com' hobbies

What would you like to do? (add, count, send, display, exit) display
a_person@host.com Alice ['horses', 'traveling', 'sleeping']
myemail@host.com Blake ['school']

What would you like to do? (add, count, send, display, exit) count
Hobby Results
{'horses': 1, 'traveling': 1, 'sleeping': 1, 'school': 1}

What would you like to do? (add, count, send, display, exit) send
Which hobby? horses
Mailing horses to: ['a_person@host.com']

What would you like to do? (add, count, send, display, exit) exit
Goodbye

Implementation Details

class Person:

  def __init__(self, name, email, hobbies):
    # finish

  def __str__(self):
   # finish
class Mailer:

  def __init__(self):
    self.people = []

  def __str__(self):
    return '\n'.join(str(p) for p in self.people)
  
  def send_hobby_mailer(self, hobby):
    # finish
  
  def count_hobbies(self):
    # finish
  
  def already_present(self, check):
    # finish

  def add_person(self, check):
    # finish

Below if an example of the functionality of the four functions.

> mailer = Mailer()
> mailer.add_person(Person('Alice', 'a_dog@host.com', ['dogs', 'animals']))

a_dog@host.com is not in our list
a_dog@host.com has been added to our list

> mailer.add_person(Person('Bob', 'knitting@host.com', ['knitting', 'surfing', 'painting']))

knitting@host.com is not in our list
knitting@host.com has been added to our list

> mailer.add_person(Person('Carlos', 'filmbuff@host.com', ['movies']))

filmbuff@host.com is not in our list
filmbuff@host.com has been added to our list

> mailer.add_person(Person('Daisy', 'soccerfan@host.com', ['soccer', 'tennis', 'dogs']))

soccerfan@host.com is not in our list
soccerfan@host.com has been added to our list

> mailer.add_person(Person('Eva', 'everything@host.com', ['surfing', 'movies', 'knitting', 'animals']))

everything@host.com is not in our list
everything@host.com has been added to our list

> print(mailer)

a_dog@host.com Alice ['dogs', 'animals']
knitting@host.com Bob ['knitting', 'surfing', 'painting']
filmbuff@host.com Carlos ['movies']
soccerfan@host.com Daisy ['soccer', 'tennis', 'dogs']
everything@host.com Eva ['surfing', 'movies', 'knitting', 'animals']

> mailer.add_person(Person('Bob', 'another_bob@host.com', ['cats', 'tennis']))

another_bob@host.com is not in our list
another_bob@host.com has been added to our list

> mailer.add_person(Person('Bob', 'knitting@host.com', ['surfing', 'animals', 'poetry']))

knitting@host.com is already in our list
Added animals to knitting@host.com' hobbies
Added poetry to knitting@host.com' hobbies

> print(mailer)

a_dog@host.com Alice ['dogs', 'animals']
knitting@host.com Bob ['knitting', 'surfing', 'painting', 'animals', 'poetry']
filmbuff@host.com Carlos ['movies']
soccerfan@host.com Daisy ['soccer', 'tennis', 'dogs']
everything@host.com Eva ['surfing', 'movies', 'knitting', 'animals']
another_bob@host.com Bob ['cats', 'tennis']

> mailer.count_hobbies()

Hobby Results
{'dogs': 2, 'animals': 3, 'knitting': 2, 'surfing': 2, 'painting': 1,
'poetry': 1, 'movies': 2, 'soccer': 1, 'tennis': 2, 'cats': 1}

> mailer.send_hobby_mailer('animals')

Mailing animals to: ['a_dog@host.com', 'knitting@host.com', 'everything@host.com']

> mailer.send_hobby_mailer('tennis')

Mailing tennis to: ['soccerfan@host.com', 'another_bob@host.com']

> mailer.send_hobby_mailer('unique')

Mailing unique to: []

Challenge

This section contains additional components you can add to the project. These should only be attempted after the project has been completed.

Super Challenge

The super challenge will require knowledge that has not been taught yet. You will need to do additional research on your own. Good luck!

A common problem that data engineers face is unclean data. That is, data that is not perfectly entered by the user. For example, capitialization does not matter in an email address. My_email@host.com and my_email@host.com will go to the same place. Punctuation like periods also does not matter. MyEmail@host.com and My.Email@host.com will go to the same place. Right now, your code cannot tell the difference between these two and will treat them as different people.

Part of a data engineer’s job is to clean all data inputs. Clean all of the emails in your program as they are entered. Standardize how they are stored so that you can now tell if unclean data entrees like those above are actually the same address. What other types of mistakes might a user make? Try to fix those as well!

Rubric

Student Name: ________ Date: ___________

The Student can create a class and an instance (7.01, 7.02)

3 2 1 0 Points
Student creates classes correctly Student usually creates classes correctly Student attempts to create classes No evidence that the student can create classes 3
Student correctly creates instances of a class Student usually creates and instance of a class correctly Student attempts to create a class No evidence that the student can create a instance of a class 3
Student instantiates a class with arguments __ Student attempts to instantiate a class with arguments No evidence the student can instantiate a class with arguments 3
Student always adds attributes to an instance correctly Student usually adds attributes to an instance correctly Student attempts to add attributes to an instance No evidence the student can add attributes to an instance 2
      Sub Total  

The student can create methods for classes

3 2 1 0 Points
Student always uses the self argument correctly Student usually uses the self argument correctly Student attempts to use the self argument There is no evidence Student can use the self argument 3
Student correctly uses the __str__ method   Student attempts to use the __str__ method No evidence Student can use the __str__ method 0
      Sub Total  

The student can correctly use inheritance

3 2 1 0 Points
Student uses inheritance correctly __ Student attempts to use inheritance No evidence that the student can use inheritance correctly 3
      Sub Total  

Student can decompose a problem to create a program from a brief

3 2 1 0 Points
Student program runs without error The students program has a few errors, but it does not impact the program’s functionality Student program has errors that impact the program’s functionality Student program is not functional 2
__ Students submitted documentation showing planning for most variables and functions. Students submitted documentation showing planning for a few variables and functions. No evidence of planning 2
      Sub Total  

Student uses naming/ syntax conventions and comments to increase readability

2 1 0 Points
Syntax conventions are generally used Sometimes syntax conventions are used No evidence of syntax conventions to aid in code readability 2
All variables have clear names Some variables have clear names No evidence of using variable names to aid in code read ability 2
__ Student comments aid code readability No evidence of using comments to aid in code readability. 1
    Sub Total  

Final Grade

Points Possible Points Earned x Weight total Points
28 __ X __  

Check your understanding

Pick an answer for each question. You can try again until you get it right.

1. Why should you do class design before you begin coding a project like this?

  • Planning removes the need for testing
  • Python requires a design document to run
  • Designs cannot change once written
  • Deciding which classes, attributes, and methods you need first helps you organize the code and avoid rework

Thinking through the classes up front makes the coding steps clearer and reduces rewrites.

2. When several types share the same attributes and methods, how can inheritance help?

  • Put the shared parts in a base class and let child classes inherit and customize them
  • Copy and paste the code into each class
  • Use one long list instead of classes
  • Give every class a different __init__ name

A parent class avoids repetition, and each child only adds or overrides what differs.

3. If a child class needs different behavior for one method than its parent, what should it do?

  • Rename the parent class
  • Edit the parent class so it breaks for everyone
  • Override the method in the child class
  • Avoid using that method

Overriding replaces the inherited behavior only for the child.

Downloads