How to create a TIC TAC TOE Bot in Python | Beginner Friendly Tutorial (Minimax Algorithm) | Part 1
Ғылым және технология
Learn how to create a Tic Tac Toe bot in python. Hey everyone welcome to another video. In this first part to a 2 part series on creating this bot we create the basic tic tac toe game. Linked below is a copy of the complete file I make in this video if you just want to hop straight into the second video.
checkWin function:
def checkWin():
if (board[1] == board[2] and board[1] == board[3] and board[1] != ' '):
return True
elif (board[4] == board[5] and board[4] == board[6] and board[4] != ' '):
return True
elif (board[7] == board[8] and board[7] == board[9] and board[7] != ' '):
return True
elif (board[1] == board[4] and board[1] == board[7] and board[1] != ' '):
return True
elif (board[2] == board[5] and board[2] == board[8] and board[2] != ' '):
return True
elif (board[3] == board[6] and board[3] == board[9] and board[3] != ' '):
return True
elif (board[1] == board[5] and board[1] == board[9] and board[1] != ' '):
return True
elif (board[7] == board[5] and board[7] == board[3] and board[7] != ' '):
return True
else:
return False
Code repository: github.com/watsojar/tictactoe
On this channel we focus on all things Python. Whether it is a project tutorial/showcase, teaching different Python concepts, or just live coding this is one of the best channels for programmers. Check out my links down below and think about supporting me on Patreon 👇
Links:
Patreon: / codecoach
Discord: / discord
Github: github.com/watsojar
Пікірлер: 9
Second part coming out Thursday!
Hi, I have a minor problem with the checkWin() function, I'm trying to expand the playing field, but I don't know how. Any advice?
Hey i just wanted to help out a little in line [11] you put "print(" ") just for a little bit less writhing you can just put "print()"
@CodeCoachh
Жыл бұрын
Print by default created a new line at the end so yes you are correct.
Actually with just a few lines of code you could make beautiful modern looking GUI base tic-tac toe ( either with customtkinter or ttkbootstrap ) and I think its even takes less lines of code to do that instead of this harsh looking terminal base games that we build in 48k spectrum computers 44 years ago
you don't need to pass board to your functions , board is an mutable object of the global scope and functions have access to it
what are you using that is running python
@CodeCoachh
Жыл бұрын
I am using VS code in this video but I also use Atom and Pycharm depending on the project I am working on.
can you make a minimax chess ai