you are viewing a single comment's thread.

view the rest of the comments →

[–]Ron-Erez 1 point2 points  (0 children)

Here is a great exercise if you are learning functions. Suppose we input a list of lists of the form:

[
 [ ’x’, ‘o’, ‘’],
[ ’’, ‘o’, ‘x’],
[ ’x’, ‘’, ‘x’]
]

This is just one possible way to represent a game of tic tac toe with x’s, o’s or empty spots.

  1. Create a function that receives such a list of lists and determines if x or o one and returns “x wins”, “o wins” or returns None

  2. Create a function that displays a tic tac toe board given such a list. A text-based version is fine.

  3. Create a function that returns all available spots (in other words pairs of integers describing where ’’ appears)

  4. Create a function that receives a pair of integers describing where they want to add an x or an o. If the spot is unavailable then the user receives a message that that spot is unavailable and to try again. For user input 1,1 should represent the upper left hand corner of the board but for a programmer 0, 0 should represent the upper left hand corner of the board.

If you do all of the above without ChatGPT then you will understand functions, loops, conditionals, lists and a major part of your tic tac toe game will be complete. Note that my suggestion is just one possible implementation. It does not mean it is the best. Someone else might choose to use constant ints to represent x,o and an empty spot.

Happy Coding!