Created
August 17, 2022 23:58
-
-
Save racecraftr/c027f1e4d059589f8d8447893da75553 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Variables and Lists | |
# =================== | |
board = [ | |
[" ", " ", " "], | |
[" ", " ", " "], | |
[" ", " ", " "] | |
] | |
playing = True | |
# Functions | |
# ========= | |
# Name: print_gameboard | |
# Purpose: This function nicely prints the gameboard as a 3x3 square. | |
# Input: gameboard (a list of lists) | |
# Output: returns nothing, prints out the gameboard | |
def print_gameboard(gameboard): | |
# Name: check_winner | |
# Purpose: uses the gameboard to check whether or not a player has won. | |
# Input: gameboard (a list of lists) | |
# Output: returns 'X' or 'O' if either player has won and returns ' ' if neither player has won. | |
def check_winner(gameboard): | |
# Name: check_tied | |
# Purpose: used to determine whether the game is tied (all 9 spaces are filled but no one has won) | |
# Input: gameboard (a list of lists) | |
# Output: returns True if there is a tie and False if there is not a tie. | |
def check_tied(gameboard): | |
# Name: make_move | |
# Purpose: To fill the gameboard with the current player's move. Prompts the user by their name for a row and then for a column. Then, it places their symbol in the indicated spot on the gameboard. If an illegal spot is selected, the user will be prompted to make a new selection. | |
# Input: gameboard (a list of lists), name (a string representing the current player's name), symbol (a string representing their game symbol ('X' or 'O')) | |
# Output: returns nothing, updates the gameboard | |
def make_move(gameboard, name, symbol): | |
# The Game | |
# ======== | |
# welcome the user to the tic-tac-toe game | |
# ask players X and O for their names | |
# repeat playing the game until a player wins |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#Updated check_winner function description
Name: check_winner
Purpose: uses the gameboard to check whether or not a player has won.
Input: gameboard (a list of lists)
Output:
returns 3 if winner is x
returns -3 if winner is o
returns 0 if there is no winner