Summit Middle School classes for Andrew Busch
Andrew Busch - Summit
  • Home
  • Algebra 1
    • Alg 1B - Last Week
    • Alg1B 14 HW - Intro to Functions
    • Alg 1B 11 - Rational Expressions
    • Alg 1B 12 - Radical Expressions
    • Alg 1B 10 v2.0 - Quadratic Functions >
      • 10b Graphing with Pennies - Desmos Tutorial
      • 10i Snowboard Quadratic - Alg1B
      • 10 Quadratics Project
    • Alg 1B 10 Book - Factoring Quadratics
    • Alg 1B 9 - Exponential Functions
    • Alg 1B 8.5 - Representing Data
    • Alg 1B 13 - Inequalities
    • Alg 1B 8 - Best Fit Lines and Linear Regression
    • Alg 1B 7 - Linearity
  • Geometry
    • Geom Last Week
    • Geom 12 - Probability
    • Geom 11 - Circumference, Area, Volume
    • Geom 10-Circles
    • Geom 9 - Right Triangles and Trigonometry
    • Geom 8 - Similarity
    • Geom 7 - Quadrilaterals and Other Polygons
    • Geom 6 - Relationships Within Triangles
    • Geom 5 - Congruent Trianlges
    • Geom 4 - Transformations
    • Geometry 3.5 - Constructions
    • Geom 3 - Parallel and Perpendicular Lines
    • Geom 2 - Reasoning and Proofs
    • Geom 1 - Basics of Geometry
  • Programming
    • Directions for Sharing Programs with Me
    • Hour of Code
    • Intro to Python >
      • Installing and Using Portable Python
      • Introduction to Programming
      • Interactive Storyteller
      • Sophisticated Calculator
      • Getting Started with Games
      • Word Length Frequency
      • Substitution Cipher
      • Simple Game of Paddleball
      • Animating Many Objects
      • Accelerator
      • Applying Trigonometry
      • GIFs
      • Programmatic Art
      • Battleship
      • Pong
      • CodeCademy.com Suggested Work
      • Python Resources
    • Advanced Python >
      • Python Installation
      • Review of Intro to Programming
      • Objects and Classes >
        • More on Classes: Functions, Methods, Inheritance
        • Quadrilaterals
      • tkinter >
        • Paddle Ball
        • Light Bike
        • Frogger
        • Snake Game
        • Breakout
      • Reading and Writing Files
      • Directories and Importing Modules
      • Raspberry Pi
      • API's
      • Python Puzzles
  • Clubs
  • Graphing Calculator
  • PARCC Practice

Battleship!

This lesson can be found at CodeCademy.com's resource page for Python.
If the links below don't work, the full URL for the lesson is:
http://www.codecademy.com/courses/python-beginner-en-4XuFm/0/1?curriculum_id=4f89dab3d788890003000096
I would reproduce the entire CodeCademy lesson here, but I'm pretty sure that would be considered a violation of copyright.
Picture

Battleship from CodeAcademy
Although I love CodeCademy.com, I don't particularly like it that you don't get to keep your code. Eventually, I would like you to build an AI (a gaming bot) for your Battleship program and have you pit your program against another student's Battleship program.

In order for this to happen, you need to have your code written down somewhere. Portable Python seems like the obvious choice for us.


Go through the lesson at CodeCademy but write down your code in a Portable Python module named "Battleship". You do not have to create a CodeCademy account to use the lesson. To advance to the next lesson at CodeCademy without logging in or writing code in their webpage's IDE (Interactive Development Environment), use the drop down menu on the upper-left portion of the page. It should say 1/19.


IMPORTANT: When you copy and paste your code from CodeCademy into Python you will get several errors.
  1. CodeCademy does not use parentheses with their print functions. We do. Put parentheses into each of your print() statements.
  2. CodeCademy uses raw_input() but in Python 3 it changed over to just input(). Delete the raw_ portion of the code.

Run your code in Portable Python to make sure it works!

Making the Game Awesomer.
1. Save a copy of your original Battleship game as Battleship_CodeCademy just in case we mess it up badly and want to start over. From here on out, we will modify our game of Battleship but not touch the Battleship_CodeCademy file.

2. Make your battleship have a length of 3. All the pieces of the ship must touch each other and be in either a vertical or horizontal line (no diagonals!).
  • Be careful! You don't want your boat going off the side of the board.
  • This involves getting the random numbers from the rand_int() function and then automatically placing the other coordinates of the boat next to the random ones.
  • You may want to change the either the definition of random_row or random_col in order to incorporate the extra length of the boat.
3. Modify the game so the game so it ends after you sink the ship, not just after 4 turns. Remember, you now have to make 3 correct guesses and keep track of them.

4. Make your game into a two-player game. Each player should have a randomly assigned battleship on their own board.
Extension (Making the Game Even More Awesomer):
1. Create a version with multiple ships of different sizes. (I suggest starting with ships of length 2 and 3).

2. Create an option where the player gets to determine the size of the board.

3. Have the player determine the number of ships and the size of the board.

4. Build a 1-player version of this game where the user plays against the computer. This means you will need to create a bot (AI) to play against. This bot should be able to make guesses about where to attack; whether your bot attacks with a strategy or not is up to you.

Powered by Create your own unique website with customizable templates.