ISF DP Computer Science

Tic Tac Toe #

In this lab you will create an OOP representation of Tic Tac Toe.

[0] Class Relationships #

In this lab, you will make a simple version of Blackjack. For this, we use multiple classes.

  • Card()
  • Deck()
  • Hand()
  • Blackjack

๐Ÿ“– Here is the UML diagram for the class relationships. The filled diamonds represent an composition relationship. A Stack is a part of a TicTacToe and the TicTacToe cannot exist without the Stack.


classDiagram
    class Stack {
        - stack: list
        + \_\_init__()
        + \_\_str__()
        + push(element)
        + pop()
        + peek()
        + isEmpty()
    }

    class TicTacToe {
        - board: list[list[str]]
        - history: Stack
        - game_won: bool
        + \_\_init__()
        + \_\_str__()
        + fill_cell(row, col, value): none
        + check_valid_cell(row, col): bool
        + check_win(player): bool
        + computer_move(): none
        + player_move(): none
        + undo_rounds(num_rounds): none
        + play(): none
    }

    Stack --* TicTacToe: part of

[1] Set up #

๐Ÿ’ป Clone your repo in the correct folder. Be sure to replace yourgithubusername with your actual username.

cd ~/desktop/dpcs/unit02_oop
git clone https://github.com/isf-dp-cs/lab_tictactoe_yourgithubusername
๐Ÿ’ป In the Terminal, type the following command to open the lab folder.
cd lab_tictactoe_yourgithubusername

๐Ÿ’ป Enter the Poetry Shell to start the lab. As a reminder, we will run this command at the start of each lab, but only when we are inside a lab folder.

poetry shell
๐Ÿ‘พ ๐Ÿ’ฌ Exiting the poetry shell

When you want to exit the shell, you can type exit or ^D


[2] TicTacToe #

classDiagram
    class TicTacToe {
        - __board: list[list[str]]
        - __history: Stack
        - __game_won: bool
        + \_\_init__()
        + \_\_str__()
        + fill_cell(row, col, value): none
        + check_valid_cell(row, col): bool
        + check_win(player): bool
        + computer_move(): none
        + player_move(): none
        + undo_rounds(num_rounds): none
        + play(): none
    }  

[Testing Plan] #


Construct Methods #

๐Ÿ’ป You must construct the following methods in TicTacToe. These are the core functionalities of the game, without considering the games logic. Do not construct the play() function with the game logic until the next part of the lab.

  • fill_cell(row, col, value)
  • check_valid_cell(row, col)
  • check_win(player)
    • check for horizontal and both diagonal win conditions
  • player_move()
  • computer_move()
  • undo_rounds()

๐Ÿค” As you’re testing, consider what game state you need to ensure each method works.


Game Loop #

Now that you have all of the required functionalities of the game, it is up to you determine how you would like your game loop to operate. The only requirement is it must use all of the methods.

โœ๏ธ Before you start coding, draw a flowchart to illustrate your game loop. You may want to reference the textbook or inThinking to remind yourself of the flowchart requirements.

๐Ÿ’ป Construct the code for your implementation of the game loop by following your flow chart.


[6] Deliverables #

โšกโœจ Once you finish the lab, be sure to complete these two steps:

๐Ÿ“‹ Update Syllabus Checklist: Go to your Syllabus Content Checklist in your Google Drive and update it accordingly.

๐Ÿ’ป Push your work to Github

  • git status
  • git add -A
  • git status
  • git commit -m “describe your code here”
  • git push
  • remote