#๐ tic tac toe makes me win in one move
85 messages ยท Page 1 of 1 (latest)
@neat wigeon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
i just completed this tic tac toe project and it was working just fine. until it wasnt.
!pastebin
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
here is the code
what happend is that, when a player won,it was repeating win condition, so i had to make some adjustments and then decided to make a winner variable and assigned it None. then when the player completed the horizontal vertical or diagonal layout. it wins and the program closes
but now, before i ever use the input to assign a position, it says the first user won.
if check_diagonal(board) or check_horizontal(board) or check_vertical(board) != "-":
what is this line supposed to check
none of the functions ever return anything
if the positions taken by the users dont satisfy win condition and are filled without any "-" its a tie
do you know about function calls and function returns
check_diagonal(board) will always return None since you never return anything urself
this basically transfers to:
if None == True or None == True or None != "-":
and since None is not equal to "-"
it will pass
no wait, i miss tolf you something
this is the win function
yes, im aware of that
damn, my bad
it doesnt change the fact that this will always be the same
but whats wrong in that?
ur never returning anything from the functions ur calling
so u cant compare anything to them
you mean board[0] == None?
!e
def function():
pass
print(function())
if function() == "Hello":
print("function says Hello")
:white_check_mark: Your 3.12 eval job has completed with return code 0.
None
like what i see in my code is that, if certain position of the board has "X" or "O" in it and is not "-" then it declares the winner variable as the currentplayer
again, ur never returning anything from the functions
mm
so how can it equal something else than None?
!e
def function():
pass
print(function())
:white_check_mark: Your 3.12 eval job has completed with return code 0.
None
when u dont return anything, the return value will always be None
!e
def function():
return "-"
print(function())
:white_check_mark: Your 3.12 eval job has completed with return code 0.
-
okay, so what should be the solution?
in the functions you are calling, if someone has won and after you set the winner, write return True
and change the if statement to this
if check_diagonal(board) or check_horizontal(board) or check_vertical(board):
that still doesnt do anything
i changed all the functions to return True
and changed the if ststement
so all ur functions look like this?
def check_horizontal(board):
global winner
if (board[0] == board[1] == board[2] and board[0] != "-") or (board[3] == board[4] == board[5] and board[3] != 3) or (board[6] == board[7] == board[8] and board[0] != "-"):
winner = currentplayer
return True
def check_vertical(board):
global winner
if (board[0] == board[3] == board[6] and board[0] != "-") or (board[1] == board[4] == board[7] and board[1] != "-") or (board[2] == board[5] == board[8] and board[0]) != "-":
winner = currentplayer
return True
def check_diagonal(board):
global winner
if (board[0] == board[4] == board[8] and board[0] != "-") and (board[0] or board[6] == board[4] == board[5] and board[2] != "-"):
winner = currentplayer
return True
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
def check_horizontal(board):
global winner
if (board[0] == board[1] == board[2] and board[0] != "-") or (board[3] == board[4] == board[5] and board[3] != 3) or (board[6] == board[7] == board[8] and board[0] != "-"):
winner = currentplayer
return True
look over this function real quick
do you see anything off?
yes
all of your check_ functions has errors
look through all of those
(check_horizontal, check_vertical, check_diagonal)
IT WORKKKSSSSSSSSSSSSSSSSSSSSSSSSSS
OMG
the errors made the wole function shit in just one command hunh
wow
wait
i removed the erros, but something isnt right
what is it
can you run this one time and tell me why i am not able to put an icon on the 3rd row?
like when i put "X" anywhere on the third row it just declares win
if (board[0] == board[4] == board[8] and board[0] != "-") and (board[0] or board[6] == board[4] == board[5] and board[2] != "-"):
theres something wrong here
ah, i see it
bruh
can you look it one last time please
๐ญ
it still hasnt changed
umm
@marsh fjord you there?
๐ญ
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.