Skip to content

Lab Exercise 2 Patch Notes

Updated as of 02/11, 8:45pm

Important

  • Note that Lab Exercise 2 is take home, so you are expected to do this Lab Exercise regardless of whether you were present/absent/excused last February 6.

  • Pyright strict mode compliance

    All deliverables for the Python portion of CS 12 will require Pyright strict mode compliance. Any Pyright error present will invalidate your submission (i.e., merit a grade of \(0\)).

  • The model part of your program must have 100% statement and branch coverage. There is no need for unit tests for the other parts of your code.

    All unit tests must be in a file named test_model.py in the root of the repository.

    Your tests will be executed using the following command:

    coverage run --branch -m pytest && coverage html

    There is no need to push the htmlcov folder or any of the Pytest artifacts.

    While the quality of unit tests will not be checked for this lab, you are responsible for ensuring you have enough test cases to sufficiently cover edge cases and the like.

    Aiming for 100% test coverage should naturally guide you through which aspects of your model should have tests.

    Not obtaining 100% coverage will merit deductions.

  • grids, is_game_over, and winner in BattleshipController should be methods, not properties

    Ensure that the .run() method of BattleshipController is implemented like this:

    def run(self):
        model = self._model
        view = self._view
    
        while not model.is_game_over():
            if model.turn == 0:
                view.show_grids(model.grids())
                i, j = view.ask_for_location(model.n)
            else:
                i, j = model.get_random_ij()
                view.show_shot(i, j)
    
            model.shoot(i, j)
            model.go_to_next_turn()
    
        view.show_grids(model.grids())
        view.show_end_message(model.winner())
    

    In particular, there should be parentheses at the end of model.is_game_over(), model.grids(), and model.winner().

  • Changed meaning of winner

    • Old: "Returns an int denoting who the winner of the game is."
    • New: "Returns an int denoting whether you win or not."
    • If you do not win, you may return any other integer.

Clarifications

GitHub

  • Use the GitHub account you submitted via the student info form.
  • If you are getting a Repository Access Issue, kindly check your email to see if you have received an invite for the assignment.

Editing files

  • You may use anything (good) you learned from any of the lectures so far.
  • You may use additional files, as long as the game is runnable via python3 battleship.py.
  • You may add additional functions and classes to both utils.py and battleship.py.
  • You may edit (make changes/add stuff to) the BattleshipView and BattleshipController, but you may only do so if you are going beyond Phase 2.

Game loop

  • During their turn, each player can only do exactly one of (1) shooting an opponent's grid, (2) moving one of their ships (if they still can), and (3) using the square scan.

Ships, Moving ships

  • The ship sizes are fixed \((4, 3, 2, 2)\).
  • If an enemy moves a ship to a cell that you have shot before, that part of the ship will be revealed.

Opponents

  • For Phase 4, there should be at least two opponents. Besides that, the actual number of opponents is up to you.
  • Opponents should also be able to move ships. Whether they can do square scans, and whether they do something with the information they would be able get if so, is up to you.
  • We expect the opponents to make their moves automatically (i.e., they're bots).
  • You may make the opponents smarter.
  • If one opponent loses all of their ships, they may still be attacked.


Sorry for the inconvenience!