title
Python Tic Tac Toe game ⭕
description
python tic tac toe game tutorial example explained
#python #tictactoe #game
# ********************************************************
# Python Tic Tac Toe game
# ********************************************************
from tkinter import *
import random
def next_turn(row, column):
global player
if buttons[row][column]['text'] == "" and check_winner() is False:
if player == players[0]:
buttons[row][column]['text'] = player
if check_winner() is False:
player = players[1]
label.config(text=(players[1]+" turn"))
elif check_winner() is True:
label.config(text=(players[0]+" wins"))
elif check_winner() == "Tie":
label.config(text="Tie!")
else:
buttons[row][column]['text'] = player
if check_winner() is False:
player = players[0]
label.config(text=(players[0]+" turn"))
elif check_winner() is True:
label.config(text=(players[1]+" wins"))
elif check_winner() == "Tie":
label.config(text="Tie!")
def check_winner():
for row in range(3):
if buttons[row][0]['text'] == buttons[row][1]['text'] == buttons[row][2]['text'] != "":
buttons[row][0].config(bg="green")
buttons[row][1].config(bg="green")
buttons[row][2].config(bg="green")
return True
for column in range(3):
if buttons[0][column]['text'] == buttons[1][column]['text'] == buttons[2][column]['text'] != "":
buttons[0][column].config(bg="green")
buttons[1][column].config(bg="green")
buttons[2][column].config(bg="green")
return True
if buttons[0][0]['text'] == buttons[1][1]['text'] == buttons[2][2]['text'] != "":
buttons[0][0].config(bg="green")
buttons[1][1].config(bg="green")
buttons[2][2].config(bg="green")
return True
elif buttons[0][2]['text'] == buttons[1][1]['text'] == buttons[2][0]['text'] != "":
buttons[0][2].config(bg="green")
buttons[1][1].config(bg="green")
buttons[2][0].config(bg="green")
return True
elif empty_spaces() is False:
for row in range(3):
for column in range(3):
buttons[row][column].config(bg="yellow")
return "Tie"
else:
return False
def empty_spaces():
spaces = 9
for row in range(3):
for column in range(3):
if buttons[row][column]['text'] != "":
spaces -= 1
if spaces == 0:
return False
else:
return True
def new_game():
global player
player = random.choice(players)
label.config(text=player+" turn")
for row in range(3):
for column in range(3):
buttons[row][column].config(text="",bg="#F0F0F0")
window = Tk()
window.title("Tic-Tac-Toe")
players = ["x","o"]
player = random.choice(players)
buttons = [[0,0,0],
[0,0,0],
[0,0,0]]
label = Label(text=player + " turn", font=('consolas',40))
label.pack(side="top")
reset_button = Button(text="restart", font=('consolas',20), command=new_game)
reset_button.pack(side="top")
frame = Frame(window)
frame.pack()
for row in range(3):
for column in range(3):
buttons[row][column] = Button(frame, text="",font=('consolas',40), width=5, height=2,
command= lambda row=row, column=column: next_turn(row,column))
buttons[row][column].grid(row=row,column=column)
window.mainloop()
# ********************************************************
Bro Code merch store 👟 :
===========================================================
https://teespring.com/stores/bro-code-5
===========================================================
music credits 🎼 :
===========================================================
Up In My Jam (All Of A Sudden) by - Kubbi https://soundcloud.com/kubbi
Creative Commons — Attribution-ShareAlike 3.0 Unported— CC BY-SA 3.0
Free Download / Stream: http://bit.ly/2JnDfCE
Music promoted by Audio Library https://youtu.be/tDexBj46oNI
===========================================================
detail
{'title': 'Python Tic Tac Toe game ⭕', 'heatmap': [{'end': 426.281, 'start': 374.886, 'weight': 0.822}, {'end': 905.891, 'start': 888.024, 'weight': 0.772}], 'summary': 'A comprehensive tutorial on coding a basic tic-tac-toe game in python is covered, including creating the game grid, implementing game logic, modifying the game, and setting up commands and buttons for the game. the tutorial explains creating a 3x3 grid using nested for loops and adding buttons, and demonstrates game logic such as checking for a winner, handling ties, and modifying the game by changing button colors for winning and tie combinations.', 'chapters': [{'end': 251.992, 'segs': [{'end': 52.538, 'src': 'embed', 'start': 21.746, 'weight': 0, 'content': [{'end': 25.488, 'text': "Alright, ladies and gentlemen, let's create a game of tic-tac-toe.", 'start': 21.746, 'duration': 3.742}, {'end': 28.77, 'text': "To begin, we'll need to import tkinter as well as random.", 'start': 25.568, 'duration': 3.202}, {'end': 32.671, 'text': "And let's begin by defining all of the different functions that we'll need.", 'start': 29.21, 'duration': 3.461}, {'end': 36.114, 'text': "Let's define a function named nextTurn.", 'start': 33.012, 'duration': 3.102}, {'end': 38.756, 'text': "For the time being, we'll just write pass.", 'start': 37.235, 'duration': 1.521}, {'end': 39.997, 'text': "We'll fill this in later on.", 'start': 38.816, 'duration': 1.181}, {'end': 43.499, 'text': "We'll need a function named checkWinner.", 'start': 40.857, 'duration': 2.642}, {'end': 52.538, 'text': 'A function named empty spaces to check if there are any empty spaces left.', 'start': 46.835, 'duration': 5.703}], 'summary': 'Creating a tic-tac-toe game using tkinter and defining essential functions.', 'duration': 30.792, 'max_score': 21.746, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE21746.jpg'}, {'end': 175.647, 'src': 'embed', 'start': 76.699, 'weight': 1, 'content': [{'end': 77.5, 'text': "Let's set the title.", 'start': 76.699, 'duration': 0.801}, {'end': 85.187, 'text': "Window.title Let's set this to tick-tack-toe.", 'start': 78.301, 'duration': 6.886}, {'end': 88.85, 'text': "We'll need a list of players.", 'start': 87.249, 'duration': 1.601}, {'end': 92.193, 'text': 'Players equals x.', 'start': 89.171, 'duration': 3.022}, {'end': 95.449, 'text': 'comma O.', 'start': 93.328, 'duration': 2.121}, {'end': 100.371, 'text': "And with the way that we're writing this program, we can swap these symbols with a different character.", 'start': 95.449, 'duration': 4.922}, {'end': 107.674, 'text': "For example, we could say $ is playing against the at symbol too, but I'll demonstrate that later.", 'start': 100.911, 'duration': 6.763}, {'end': 109.895, 'text': "Let's keep it as X and O for now.", 'start': 107.894, 'duration': 2.001}, {'end': 114.577, 'text': 'Now we need to select a random player to begin.', 'start': 111.716, 'duration': 2.861}, {'end': 122.49, 'text': 'player equals random.choice and pass in our list of players.', 'start': 115.117, 'duration': 7.373}, {'end': 124.551, 'text': "Now we'll need nine buttons.", 'start': 123.07, 'duration': 1.481}, {'end': 128.372, 'text': "I'm going to create a 2D list of buttons named buttons.", 'start': 124.631, 'duration': 3.741}, {'end': 130.774, 'text': 'And this will be the first row.', 'start': 129.613, 'duration': 1.161}, {'end': 133.715, 'text': 'This will be the second row.', 'start': 132.434, 'duration': 1.281}, {'end': 142.219, 'text': "For the time being, I'm just going to initialize these with zero for everything and put these all within a list.", 'start': 134.435, 'duration': 7.784}, {'end': 145.02, 'text': 'So we have a 2D list named buttons.', 'start': 142.599, 'duration': 2.421}, {'end': 149.922, 'text': "And to better visualize this, I'm going to place each row on a new line.", 'start': 146.041, 'duration': 3.881}, {'end': 152.042, 'text': "So that's what our board is going to look like.", 'start': 150.422, 'duration': 1.62}, {'end': 155.003, 'text': 'We have a 2D list named buttons.', 'start': 152.602, 'duration': 2.401}, {'end': 157.923, 'text': "We'll need a label to display whose turn it is.", 'start': 155.703, 'duration': 2.22}, {'end': 160.004, 'text': 'Label equals label.', 'start': 158.423, 'duration': 1.581}, {'end': 169.226, 'text': "I'll set the text equal to player plus the word turn.", 'start': 161.804, 'duration': 7.422}, {'end': 173.346, 'text': "And I'll set the font to font equals.", 'start': 170.646, 'duration': 2.7}, {'end': 175.647, 'text': 'Pick whatever font that you want.', 'start': 174.007, 'duration': 1.64}], 'summary': 'Creating tick-tack-toe game with x and o players, initializing buttons and label.', 'duration': 98.948, 'max_score': 76.699, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE76699.jpg'}], 'start': 0.149, 'title': 'Coding and creating tic-tac-toe game in python', 'summary': "Covers coding a basic tic-tac-toe game in python with functions for nextturn, checkwinner, empty spaces, and new game, as well as creating a window and setting the title. it also discusses creating the game, including selecting a random player to begin, creating a 2d list of buttons, a label to display the current player's turn, and a reset button with a new game function.", 'chapters': [{'end': 109.895, 'start': 0.149, 'title': 'Coding tic-tac-toe game in python', 'summary': 'Demonstrates coding a basic game of tic-tac-toe using python, including functions for nextturn, checkwinner, empty spaces, and new game, as well as creating a window and setting the title.', 'duration': 109.746, 'highlights': ['The chapter demonstrates coding a basic game of tic-tac-toe using Python, including functions for nextTurn, checkWinner, empty spaces, and new game.', "The program creates a window using tkinter and sets the title to 'tick-tack-toe'.", 'The chapter emphasizes the need to import tkinter and random to begin coding the tic-tac-toe game.', 'The program defines the list of players as X and O, with the ability to swap these symbols with different characters.']}, {'end': 251.992, 'start': 111.716, 'title': 'Creating tic-tac-toe game in python', 'summary': "Discusses the process of creating a tic-tac-toe game in python, including selecting a random player to begin, creating a 2d list of buttons, creating a label to display the current player's turn, and creating a reset button with a new game function.", 'duration': 140.276, 'highlights': ["Creating a 2D list of buttons named 'buttons' to represent the Tic-tac-toe board, initializing it with zeros, and visualizing it for better understanding.", "Selecting a random player to begin the game using the 'random.choice' function and a list of players.", "Creating a label to display whose turn it is, setting the text to include the current player's name and the word 'turn', and packing the label to display it on the interface.", "Creating a reset button with the text 'restart', setting the font size to 20, assigning a command to call the 'new game' function, and packing the button to display it on the interface."]}], 'duration': 251.843, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE149.jpg', 'highlights': ['The chapter demonstrates coding a basic game of tic-tac-toe using Python, including functions for nextTurn, checkWinner, empty spaces, and new game.', "Creating a 2D list of buttons named 'buttons' to represent the Tic-tac-toe board, initializing it with zeros, and visualizing it for better understanding.", "The program creates a window using tkinter and sets the title to 'tick-tack-toe'.", "Selecting a random player to begin the game using the 'random.choice' function and a list of players."]}, {'end': 365.823, 'segs': [{'end': 334.989, 'src': 'embed', 'start': 253.013, 'weight': 0, 'content': [{'end': 259.261, 'text': 'Alright, so we have our turn order, a label that will display whose turn it is, as well as our reset button.', 'start': 253.013, 'duration': 6.248}, {'end': 267.482, 'text': "Now we'll need to create all of the buttons to add to our 2D list named buttons, but I'm going to place these all within a frame.", 'start': 260.154, 'duration': 7.328}, {'end': 269.725, 'text': 'Frame equals frame.', 'start': 268.043, 'duration': 1.682}, {'end': 275.412, 'text': "We're adding our frame to our window, and I'm going to pack this frame.", 'start': 270.326, 'duration': 5.086}, {'end': 283.012, 'text': "Frame.pack Now we'll take our 2D list of buttons and add a button to each spot.", 'start': 276.032, 'duration': 6.98}, {'end': 286.795, 'text': 'And I think the best way to do this would be to use nested for loops.', 'start': 283.212, 'duration': 3.583}, {'end': 289.897, 'text': "We'll have an outer for loop in charge of the rows.", 'start': 287.295, 'duration': 2.602}, {'end': 293.2, 'text': 'For row in range three.', 'start': 290.418, 'duration': 2.782}, {'end': 297.003, 'text': 'Remember, we only have three rows and three columns.', 'start': 294.281, 'duration': 2.722}, {'end': 300.385, 'text': 'The inner for loop will be in charge of the columns.', 'start': 297.563, 'duration': 2.822}, {'end': 303.708, 'text': 'For column in range three.', 'start': 300.685, 'duration': 3.023}, {'end': 307.951, 'text': "And inside the inner for loop, we're going to create a new button.", 'start': 304.568, 'duration': 3.383}, {'end': 314.891, 'text': "We'll say buttons at index row and column.", 'start': 309.707, 'duration': 5.184}, {'end': 318.575, 'text': 'We have two indexes because we have a 2D list.', 'start': 315.192, 'duration': 3.383}, {'end': 326.862, 'text': 'So buttons at row whatever, column whatever, depending on what iteration we are within our for loops.', 'start': 319.595, 'duration': 7.267}, {'end': 332.006, 'text': "We'll create a new button and we'll set the text.", 'start': 327.502, 'duration': 4.504}, {'end': 333.928, 'text': 'Oh, first add this to the frame.', 'start': 332.807, 'duration': 1.121}, {'end': 334.989, 'text': 'Almost forgot about that.', 'start': 334.128, 'duration': 0.861}], 'summary': 'Creating a 3x3 grid of buttons within a frame for a turn-based game', 'duration': 81.976, 'max_score': 253.013, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE253013.jpg'}], 'start': 253.013, 'title': 'Creating tic-tac-toe grid', 'summary': 'Explains the process of creating a 3x3 grid for a tic-tac-toe game using nested for loops and adding buttons to each spot within the grid.', 'chapters': [{'end': 365.823, 'start': 253.013, 'title': 'Creating tic-tac-toe grid', 'summary': 'Explains creating a 3x3 grid for a tic-tac-toe game using nested for loops and adding buttons to each spot within the grid.', 'duration': 112.81, 'highlights': ['Nested for loops are used to create a 3x3 grid of buttons for the Tic-Tac-Toe game.', 'The buttons are added to a frame, and the frame is then added to the window.', "A 2D list named 'buttons' is used to store the buttons for the grid."]}], 'duration': 112.81, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE253013.jpg', 'highlights': ['Nested for loops create 3x3 grid of buttons for Tic-Tac-Toe game.', 'Buttons added to frame, then frame added to window.', "2D list 'buttons' stores the buttons for the grid."]}, {'end': 694.07, 'segs': [{'end': 426.281, 'src': 'heatmap', 'start': 366.423, 'weight': 0, 'content': [{'end': 367.844, 'text': "Okay, we'll need a command.", 'start': 366.423, 'duration': 1.421}, {'end': 373.806, 'text': "Command equals, and I'm going to set this equal to a lambda function, so we need some arguments.", 'start': 368.484, 'duration': 5.322}, {'end': 376.747, 'text': "Actually, I think I'll pass in some keyword arguments.", 'start': 374.886, 'duration': 1.861}, {'end': 380.929, 'text': 'Row equals row, and column equals column.', 'start': 376.927, 'duration': 4.002}, {'end': 382.589, 'text': 'Then our expression is..', 'start': 381.689, 'duration': 0.9}, {'end': 388.976, 'text': 'next turn and we will pass in row and column.', 'start': 384.375, 'duration': 4.601}, {'end': 392.237, 'text': 'Now we also need to add our buttons to our frame.', 'start': 389.556, 'duration': 2.681}, {'end': 398.018, 'text': 'Buttons at index of row and column.', 'start': 392.977, 'duration': 5.041}, {'end': 401.959, 'text': "We'll use the grid function for this.", 'start': 399.598, 'duration': 2.361}, {'end': 409.28, 'text': 'Grid row equals row and column equals column.', 'start': 402.359, 'duration': 6.921}, {'end': 414.419, 'text': "And it's always a good idea to test your program after making any major changes.", 'start': 410.655, 'duration': 3.764}, {'end': 419.945, 'text': 'So we should have our label, our reset button, and our grid of buttons.', 'start': 414.839, 'duration': 5.106}, {'end': 426.281, 'text': "Now that the main body of our program is complete, let's head to the nextTurn function.", 'start': 421.058, 'duration': 5.223}], 'summary': 'Setting up lambda function, adding buttons to frame, testing program.', 'duration': 59.858, 'max_score': 366.423, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE366423.jpg'}, {'end': 515.417, 'src': 'embed', 'start': 484.951, 'weight': 3, 'content': [{'end': 489.293, 'text': "our player's character, whatever it is X or O or whatever we decide.", 'start': 484.951, 'duration': 4.342}, {'end': 499.708, 'text': "So within here, Let's check to see if player is equal to players at index 0.", 'start': 490.354, 'duration': 9.354}, {'end': 506.692, 'text': "That is our first player, and remember that we created a list of players, and we're planning on swapping these later.", 'start': 499.708, 'duration': 6.984}, {'end': 515.417, 'text': 'We could say if player is equal to x, but that would make our program less flexible if we want to pick a different character instead of an x.', 'start': 507.013, 'duration': 8.404}], 'summary': 'Checking if player is equal to the first player in a list.', 'duration': 30.466, 'max_score': 484.951, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE484951.jpg'}, {'end': 656.241, 'src': 'embed', 'start': 576.883, 'weight': 4, 'content': [{'end': 587.448, 'text': "So what we did here is that we're checking to see if, after placing our text of our player on that button that we click, if there is no winner,", 'start': 576.883, 'duration': 10.565}, {'end': 589.109, 'text': "then we're going to swap players.", 'start': 587.448, 'duration': 1.661}, {'end': 595.651, 'text': "Player equals our next player and we're configuring our label so that it displays the next player's turn.", 'start': 589.489, 'duration': 6.162}, {'end': 598.553, 'text': 'Players at index one turn.', 'start': 596.232, 'duration': 2.321}, {'end': 600.734, 'text': 'Now, what if there is a winner?', 'start': 599.573, 'duration': 1.161}, {'end': 629.287, 'text': "Let's say else if check winner is true, then we will take our label dot config and set the text equal to players at index zero plus the word wins.", 'start': 601.314, 'duration': 27.973}, {'end': 631.349, 'text': "now let's add another else.", 'start': 629.287, 'duration': 2.062}, {'end': 645.719, 'text': "if statement else, if there's a tie, let's say check winner is equal to the word tie because we are already using false and true.", 'start': 631.349, 'duration': 14.37}, {'end': 656.241, 'text': "then let's change our label, and i'm just going to copy this text equals the word tie?", 'start': 645.719, 'duration': 10.522}], 'summary': 'Checking for winner, swapping players, and displaying results.', 'duration': 79.358, 'max_score': 576.883, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE576883.jpg'}], 'start': 366.423, 'title': 'Python tic-tac-toe program and game logic', 'summary': 'Demonstrates the implementation of a python program for a tic-tac-toe game, including setting up commands and adding buttons to the frame. it also covers the game logic, such as checking for a winner, swapping players, and handling tie scenarios.', 'chapters': [{'end': 484.951, 'start': 366.423, 'title': 'Python tic-tac-toe program', 'summary': 'Demonstrates the implementation of a python program for a tic-tac-toe game, including setting up commands, adding buttons to the frame, and implementing the nextturn function.', 'duration': 118.528, 'highlights': ['Implementing a Python program for a Tic-Tac-Toe game The chapter provides a demonstration of creating a Python program for a Tic-Tac-Toe game, involving setting up commands, adding buttons to the frame, and implementing the nextTurn function.', 'Setting up commands using lambda function with keyword arguments The program sets up commands using a lambda function with keyword arguments, such as row and column, to initialize the game board for the Tic-Tac-Toe program.', 'Adding buttons to the frame using the grid function The demonstration includes the addition of buttons to the frame using the grid function, with specific row and column assignments to populate the game board for the Tic-Tac-Toe program.']}, {'end': 694.07, 'start': 484.951, 'title': 'Tic tac toe game logic', 'summary': 'Covers the logic for a tic-tac-toe game, including checking for a winner, swapping players, and updating the display, enabling flexibility in selecting player symbols and handling tie scenarios.', 'duration': 209.119, 'highlights': ["The logic checks if the player's symbol is equal to the symbol at index 0 in the list of players, allowing flexibility in choosing different characters instead of a fixed 'x'.", "After placing the player's symbol on the button, the program checks for a winner; if none, it switches players and updates the display to show the next player's turn.", "In case of a tie, the program sets the label to display the word 'tie', providing a condition for handling tie scenarios."]}], 'duration': 327.647, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE366423.jpg', 'highlights': ['Demonstrates the implementation of a Python program for a Tic-Tac-Toe game, including setting up commands and adding buttons to the frame.', 'Setting up commands using lambda function with keyword arguments for initializing the game board.', 'Adding buttons to the frame using the grid function with specific row and column assignments.', "The logic checks if the player's symbol is equal to the symbol at index 0 in the list of players.", "Program checks for a winner, switches players, and updates the display to show the next player's turn.", "In case of a tie, the program sets the label to display the word 'tie' for handling tie scenarios."]}, {'end': 964.632, 'segs': [{'end': 730.017, 'src': 'embed', 'start': 695.371, 'weight': 5, 'content': [{'end': 697.373, 'text': 'Players at index 1 wins.', 'start': 695.371, 'duration': 2.002}, {'end': 700.161, 'text': 'And that is it.', 'start': 699.401, 'duration': 0.76}, {'end': 703.002, 'text': 'Now our next turn function is now complete.', 'start': 700.762, 'duration': 2.24}, {'end': 711.526, 'text': "Let's head down to the check winner function and we need to check all of the different win conditions and return true if somebody won,", 'start': 703.162, 'duration': 8.364}, {'end': 715.827, 'text': "false if there is yet no winner, and the word tie if it's a tie.", 'start': 711.526, 'duration': 4.301}, {'end': 719.268, 'text': "So let's check all of the horizontal win conditions.", 'start': 716.307, 'duration': 2.961}, {'end': 721.409, 'text': 'So we can do this using a for loop.', 'start': 719.709, 'duration': 1.7}, {'end': 730.017, 'text': 'For row in range three, we need to check the text of each button in each row.', 'start': 721.969, 'duration': 8.048}], 'summary': 'At index 1, players win. turn and win conditions are checked in the code.', 'duration': 34.646, 'max_score': 695.371, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE695371.jpg'}, {'end': 790.023, 'src': 'embed', 'start': 761.367, 'weight': 1, 'content': [{'end': 764.529, 'text': 'Let me move this a little bit to a space.', 'start': 761.367, 'duration': 3.162}, {'end': 770.493, 'text': 'So if that is the case, that means somebody won.', 'start': 767.631, 'duration': 2.862}, {'end': 777.738, 'text': "So if all of these buttons are the same and they are not equal to an empty space, that means they're all the same.", 'start': 770.893, 'duration': 6.845}, {'end': 779.9, 'text': "So let's return true.", 'start': 778.058, 'duration': 1.842}, {'end': 781.341, 'text': 'That means that somebody won.', 'start': 780.04, 'duration': 1.301}, {'end': 790.023, 'text': 'Now we need to check the vertical win conditions if anybody has the same character all the way down a single column.', 'start': 782.679, 'duration': 7.344}], 'summary': 'Checking for vertical win conditions in a game, returning true if someone won.', 'duration': 28.656, 'max_score': 761.367, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE761367.jpg'}, {'end': 860.844, 'src': 'embed', 'start': 821.788, 'weight': 0, 'content': [{'end': 835.713, 'text': 'If the text of that button is equal to buttons at indexes of 1, 1 is equal to the indexes of button 2, 2.', 'start': 821.788, 'duration': 13.925}, {'end': 844.014, 'text': 'And if all of this does not equal an empty space, Then return true, so there is a winner.', 'start': 835.713, 'duration': 8.301}, {'end': 847.978, 'text': 'And we have one last win condition to check.', 'start': 845.757, 'duration': 2.221}, {'end': 850.579, 'text': 'That is the other diagonal win condition.', 'start': 848.158, 'duration': 2.421}, {'end': 853.561, 'text': 'So we just need to change some of these indexes around.', 'start': 851.06, 'duration': 2.501}, {'end': 860.844, 'text': 'So we have 0, 2, 1, 1, and 2, 0.', 'start': 854.061, 'duration': 6.783}], 'summary': 'By checking the indexes and conditions, we determine the winner in the game.', 'duration': 39.056, 'max_score': 821.788, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE821788.jpg'}, {'end': 934.94, 'src': 'heatmap', 'start': 888.024, 'weight': 3, 'content': [{'end': 890.666, 'text': 'Else there is no winner and no tie.', 'start': 888.024, 'duration': 2.642}, {'end': 893.308, 'text': 'So we will return false.', 'start': 891.186, 'duration': 2.122}, {'end': 897.771, 'text': 'And that is it for the check winner function.', 'start': 894.609, 'duration': 3.162}, {'end': 898.812, 'text': "Let's test this.", 'start': 898.111, 'duration': 0.701}, {'end': 905.891, 'text': "So this doesn't account for a tie quite yet, but we can fill in some of these spaces.", 'start': 901.468, 'duration': 4.423}, {'end': 909.453, 'text': 'Looks like X wins and we can no longer fill in buttons.', 'start': 906.651, 'duration': 2.802}, {'end': 912.334, 'text': 'And we cannot start a new game quite yet either.', 'start': 910.333, 'duration': 2.001}, {'end': 921.6, 'text': "Within the empty spaces function, let's create a local variable named spaces and set this equal to nine whenever we call this function.", 'start': 913.415, 'duration': 8.185}, {'end': 934.94, 'text': "for row in range three and we'll create a nested for loop for column in range three.", 'start': 923.151, 'duration': 11.789}], 'summary': "The function does not account for a tie yet, and creates a local variable named 'spaces' set to nine in the empty spaces function.", 'duration': 46.916, 'max_score': 888.024, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE888024.jpg'}], 'start': 695.371, 'title': 'Tic-tac-toe game logic', 'summary': 'Covers implementing game logic for a tic-tac-toe game, handling ties, filling empty spaces, and determining a winner through testing and local variable creation.', 'chapters': [{'end': 860.844, 'start': 695.371, 'title': 'Tic-tac-toe win conditions', 'summary': 'Covers the implementation of win conditions in a tic-tac-toe game with explanations on horizontal, vertical, and diagonal win checks, iterating through the game grid to determine the winner.', 'duration': 165.473, 'highlights': ['Explanation of horizontal win conditions using for loop to check the text of each button in each row, returning true if all buttons are the same and not equal to an empty space.', 'Description of vertical win conditions, checking if any column has the same character all the way down, utilizing a for loop to iterate through the columns.', 'Implementation of diagonal win conditions, checking both diagonal paths and returning true if all buttons are the same and not equal to an empty space.']}, {'end': 964.632, 'start': 860.844, 'title': 'Tic-tac-toe game logic', 'summary': 'Discusses changing the logic of a tic-tac-toe game to handle ties, fill in empty spaces, and determine a winner, while testing the functionality and creating local variables.', 'duration': 103.788, 'highlights': ['The logic is being changed to handle ties, fill in empty spaces, and determine a winner.', 'Testing the functionality of the game to account for a tie and determine a winner.', "Creating a local variable named 'spaces' and setting it equal to nine when calling the function.", "Iterating through the buttons to check for non-empty spaces and decrementing the 'spaces' variable accordingly."]}], 'duration': 269.261, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE695371.jpg', 'highlights': ['Explanation of horizontal win conditions using for loop to check the text of each button in each row, returning true if all buttons are the same and not equal to an empty space.', 'Description of vertical win conditions, checking if any column has the same character all the way down, utilizing a for loop to iterate through the columns.', 'Implementation of diagonal win conditions, checking both diagonal paths and returning true if all buttons are the same and not equal to an empty space.', 'The logic is being changed to handle ties, fill in empty spaces, and determine a winner.', "Creating a local variable named 'spaces' and setting it equal to nine when calling the function.", 'Testing the functionality of the game to account for a tie and determine a winner.', "Iterating through the buttons to check for non-empty spaces and decrementing the 'spaces' variable accordingly."]}, {'end': 1267.394, 'segs': [{'end': 1040.935, 'src': 'embed', 'start': 965.032, 'weight': 0, 'content': [{'end': 976.076, 'text': 'If spaces, as in spaces remaining, is equal to zero, that means we will return false and there are no spaces left.', 'start': 965.032, 'duration': 11.044}, {'end': 983.247, 'text': 'Else, we will return True.', 'start': 978.117, 'duration': 5.13}, {'end': 986.131, 'text': "Okay, let's test it.", 'start': 983.267, 'duration': 2.864}, {'end': 988.755, 'text': "So this time I'm trying to get a tie.", 'start': 987.032, 'duration': 1.723}, {'end': 998.067, 'text': "Yep, looks like it's a tie.", 'start': 996.905, 'duration': 1.162}, {'end': 1004.793, 'text': "This next part's optional, but I would like to change the color of each button for the winning combination.", 'start': 999.571, 'duration': 5.222}, {'end': 1019.398, 'text': "So, within our checkWinner function underneath the first win condition, I'm going to take buttons at index of row and index of zero.", 'start': 1005.413, 'duration': 13.985}, {'end': 1027.141, 'text': "use the config method and set the background color equal to, let's say, green.", 'start': 1019.398, 'duration': 7.743}, {'end': 1033.532, 'text': "And I'm going to repeat this process for the other buttons within this win condition.", 'start': 1029.471, 'duration': 4.061}, {'end': 1040.935, 'text': 'So that is row 0, row 1, and row 2.', 'start': 1034.153, 'duration': 6.782}], 'summary': 'If spaces are zero, return false; else, return true. tested for a tie. optional: change button colors for winning combination.', 'duration': 75.903, 'max_score': 965.032, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE965032.jpg'}, {'end': 1148.803, 'src': 'embed', 'start': 1080.967, 'weight': 1, 'content': [{'end': 1085.149, 'text': "now, if there's a tie, let's change all of the buttons to, let's say, yellow.", 'start': 1080.967, 'duration': 4.182}, {'end': 1088.865, 'text': "So I'm going to write nested for loops for this.", 'start': 1086.604, 'duration': 2.261}, {'end': 1094.547, 'text': 'For row in range three.', 'start': 1089.345, 'duration': 5.202}, {'end': 1099.708, 'text': 'for column in range three.', 'start': 1094.547, 'duration': 5.161}, {'end': 1112.032, 'text': 'take our buttons at row and column and change the background color to yellow or some other color of your choosing.', 'start': 1099.708, 'duration': 12.324}, {'end': 1116.49, 'text': "So if there's a tie, They should all be yellow.", 'start': 1113.333, 'duration': 3.157}, {'end': 1119.812, 'text': "I'm trying not to win here.", 'start': 1118.891, 'duration': 0.921}, {'end': 1122.253, 'text': "It's actually more complex than what I thought.", 'start': 1119.832, 'duration': 2.421}, {'end': 1127.656, 'text': "Yep, it looks like it's all a tie.", 'start': 1126.055, 'duration': 1.601}, {'end': 1133.06, 'text': 'And the last thing that we need to do is to fill in the new game function so that we can begin a new game.', 'start': 1128.497, 'duration': 4.563}, {'end': 1135.732, 'text': "So let's say global player.", 'start': 1134.031, 'duration': 1.701}, {'end': 1143.378, 'text': 'We would like access to our player from inside this function and set player equal to a new random choice.', 'start': 1135.893, 'duration': 7.485}, {'end': 1148.803, 'text': 'Random.choice and pass in our list of players.', 'start': 1143.939, 'duration': 4.864}], 'summary': 'Programming a tie scenario with yellow background for buttons and implementing a new game function.', 'duration': 67.836, 'max_score': 1080.967, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE1080967.jpg'}, {'end': 1253.823, 'src': 'embed', 'start': 1197.794, 'weight': 3, 'content': [{'end': 1201.777, 'text': 'So the default color for buttons is actually hexadecimal.', 'start': 1197.794, 'duration': 3.983}, {'end': 1205.02, 'text': 'F0, F0, F0.', 'start': 1202.438, 'duration': 2.582}, {'end': 1208.182, 'text': 'So this function will begin a new game for us.', 'start': 1205.66, 'duration': 2.522}, {'end': 1210.124, 'text': "And let's test it to be sure.", 'start': 1208.883, 'duration': 1.241}, {'end': 1212.306, 'text': "I'm gonna start a new game.", 'start': 1210.144, 'duration': 2.162}, {'end': 1215.268, 'text': 'Reset Reset.', 'start': 1212.546, 'duration': 2.722}, {'end': 1217.55, 'text': "I'll actually try and win this time.", 'start': 1216.209, 'duration': 1.341}, {'end': 1219.657, 'text': 'And reset.', 'start': 1219.176, 'duration': 0.481}, {'end': 1223.241, 'text': 'Okay, so it looks like the new game function is working.', 'start': 1220.478, 'duration': 2.763}, {'end': 1228.307, 'text': 'Now another thing that you can do too is that you can change the players around.', 'start': 1224.182, 'duration': 4.125}, {'end': 1233.112, 'text': "Let's say we would like to play as dollar sign and at sign.", 'start': 1228.747, 'duration': 4.365}, {'end': 1238.659, 'text': 'So this program is flexible enough so that you can change the icons of the players.', 'start': 1233.953, 'duration': 4.706}, {'end': 1244.616, 'text': "Alright everybody, so that's a basic game of tic-tac-toe for Python.", 'start': 1240.373, 'duration': 4.243}, {'end': 1249.06, 'text': 'If you would like a copy of this code, I will post all of this to the comments section down below.', 'start': 1244.716, 'duration': 4.344}, {'end': 1253.823, 'text': "But yeah, that's how to code a basic game of tic-tac-toe for Python.", 'start': 1249.56, 'duration': 4.263}], 'summary': 'Creating a basic tic-tac-toe game in python with customizable player icons and default button color f0, f0, f0.', 'duration': 56.029, 'max_score': 1197.794, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE1197794.jpg'}], 'start': 965.032, 'title': 'Modifying and coding a tic tac toe game', 'summary': 'Discusses modifying a tic tac toe game by changing button colors for winning and tie combinations, implementing conditions to return true or false based on remaining spaces, and demonstrates how to code a basic game of tic-tac-toe in python, including creating a new game function, changing player icons, and testing the game functionality.', 'chapters': [{'end': 1119.812, 'start': 965.032, 'title': 'Tic tac toe game modifications', 'summary': 'Discusses modifying a tic tac toe game, including changing button colors for winning and tie combinations, and implementing conditions to return true or false based on remaining spaces.', 'duration': 154.78, 'highlights': ['The chapter explains how to change button colors for the winning combination, setting the background color to green for the buttons involved in the winning combination, such as row 0, row 1, and row 2.', 'It also covers changing the color of all buttons to yellow in case of a tie, achieved by implementing nested for loops for each row and column and setting the background color accordingly.', 'The chapter discusses conditions to return True or False based on remaining spaces, where if spaces remaining is zero, it returns false, indicating no spaces left.']}, {'end': 1267.394, 'start': 1119.832, 'title': 'Coding a basic tic-tac-toe game', 'summary': 'Demonstrates how to code a basic game of tic-tac-toe in python, including creating a new game function, changing player icons, and testing the game functionality.', 'duration': 147.562, 'highlights': ['The chapter demonstrates how to code a basic game of tic-tac-toe in Python The transcript provides a demonstration of coding a basic game of tic-tac-toe in Python.', 'creating a new game function The chapter explains the process of creating a new game function, which involves setting the player equal to a new random choice and resetting all the buttons.', 'changing player icons It is mentioned that the program is flexible enough to allow changing the icons of the players, such as playing as dollar sign and at sign.', 'testing the game functionality The functionality of the new game function is tested, ensuring that it resets the game and allows for playing with different player icons.']}], 'duration': 302.362, 'thumbnail': 'https://coursnap.oss-ap-southeast-1.aliyuncs.com/video-capture/V9MbQ2Xl4CE/pics/V9MbQ2Xl4CE965032.jpg', 'highlights': ['The chapter explains how to change button colors for the winning combination, setting the background color to green for the buttons involved in the winning combination, such as row 0, row 1, and row 2.', 'It also covers changing the color of all buttons to yellow in case of a tie, achieved by implementing nested for loops for each row and column and setting the background color accordingly.', 'The chapter discusses conditions to return True or False based on remaining spaces, where if spaces remaining is zero, it returns false, indicating no spaces left.', 'The chapter demonstrates how to code a basic game of tic-tac-toe in Python The transcript provides a demonstration of coding a basic game of tic-tac-toe in Python.', 'creating a new game function The chapter explains the process of creating a new game function, which involves setting the player equal to a new random choice and resetting all the buttons.', 'changing player icons It is mentioned that the program is flexible enough to allow changing the icons of the players, such as playing as dollar sign and at sign.', 'testing the game functionality The functionality of the new game function is tested, ensuring that it resets the game and allows for playing with different player icons.']}], 'highlights': ['Nested for loops create 3x3 grid of buttons for Tic-Tac-Toe game.', 'The chapter demonstrates coding a basic game of tic-tac-toe using Python, including functions for nextTurn, checkWinner, empty spaces, and new game.', 'The chapter explains how to change button colors for the winning combination, setting the background color to green for the buttons involved in the winning combination, such as row 0, row 1, and row 2.', "Creating a 2D list of buttons named 'buttons' to represent the Tic-tac-toe board, initializing it with zeros, and visualizing it for better understanding.", "The program creates a window using tkinter and sets the title to 'tick-tack-toe'.", 'Demonstrates the implementation of a Python program for a Tic-Tac-Toe game, including setting up commands and adding buttons to the frame.', 'Explanation of horizontal win conditions using for loop to check the text of each button in each row, returning true if all buttons are the same and not equal to an empty space.', 'Setting up commands using lambda function with keyword arguments for initializing the game board.', 'Description of vertical win conditions, checking if any column has the same character all the way down, utilizing a for loop to iterate through the columns.', "The logic checks if the player's symbol is equal to the symbol at index 0 in the list of players.", 'Implementation of diagonal win conditions, checking both diagonal paths and returning true if all buttons are the same and not equal to an empty space.', 'The logic is being changed to handle ties, fill in empty spaces, and determine a winner.', 'Adding buttons to the frame using the grid function with specific row and column assignments.', "Program checks for a winner, switches players, and updates the display to show the next player's turn.", "In case of a tie, the program sets the label to display the word 'tie' for handling tie scenarios.", 'The chapter discusses conditions to return True or False based on remaining spaces, where if spaces remaining is zero, it returns false, indicating no spaces left.']}