Oh I was waiting for you Iāll cancel my task. Please give @Firepup650 a task please
@Firepup650 Make tic tac toe. bonus points (is that allowed?) if you can make an AI for it or make it multiplayer
yes, itās allowed. 0.5 points for AI, another 0.5 for multiplayer.
Fun. I think I already have a BASIC repl for this actually so thatās one down, lol.
Edit: Of course I canāt find it now. I have some other BASIC code for it, but I donāt think it runs on Replit, something to do with functions I think.
import tkinter as tk
import random
root = tk.Tk()
root.title("Tic Tac Toe")
# keep track of the current player
current_player = "X"
# function for when a button is clicked
def button_clicked(button):
global current_player
# check if the button has already been clicked
if button["text"] != "":
return
# update the button text to show the current player's symbol
button["text"] = current_player
# check if the game is over
if check_for_winner():
return
# change to the other player for the next turn
if current_player == "X":
current_player = "O"
else:
current_player = "X"
# if it's the AI's turn, choose a random move
if current_player == "O":
ai_move = choose_random_move()
ai_move["text"] = "O"
check_for_winner()
# switch back to the player's turn
current_player = "X"
# function for checking if there is a winner
def check_for_winner():
for i in range(3):
if (button_list[i][0]["text"] == button_list[i][1]["text"] == button_list[i][2]["text"] != "") or \
(button_list[0][i]["text"] == button_list[1][i]["text"] == button_list[2][i]["text"] != ""):
declare_winner(button_list[i][i]["text"])
return True
if (button_list[0][0]["text"] == button_list[1][1]["text"] == button_list[2][2]["text"] != "") or \
(button_list[0][2]["text"] == button_list[1][1]["text"] == button_list[2][0]["text"] != ""):
declare_winner(button_list[1][1]["text"])
return True
return False
# function for declaring a winner
def declare_winner(winner):
winner_label = tk.Label(root, text=f"{winner} wins!", font=("Arial", 16))
winner_label.grid(row=4, column=0, columnspan=3)
# function for choosing a random move for the AI
def choose_random_move():
available_moves = []
for row in button_list:
for button in row:
if button["text"] == "":
available_moves.append(button)
return random.choice(available_moves)
# create the two player labels
player1_label = tk.Label(root, text="Player 1 (X)", font=("Arial", 16))
player1_label.grid(row=0, column=0)
player2_label = tk.Label(root, text="AI (O)", font=("Arial", 16))
player2_label.grid(row=0, column=2)
# create the 3x3 grid of buttons
button_list = []
for row in range(3):
current_row = []
for column in range(3):
button = tk.Button(root, text="", font=("Arial", 16), width=5, height=2, command=lambda btn=button: button_clicked(btn))
button.grid(row=row+1, column=column)
current_row.append(button)
button_list.append(current_row)
root.mainloop()
thats for ai
now its for the multai pwayer
import tkinter as tk
root = tk.Tk()
root.title("Tic Tac Toe")
# keep track of the current player
current_player = "X"
# function for when a button is clicked
def button_clicked(button):
global current_player
# check if the button has already been clicked
if button["text"] != "":
return
# update the button text to show the current player's symbol
button["text"] = current_player
# change to the other player for the next turn
if current_player == "X":
current_player = "O"
else:
current_player = "X"
# create the two player labels
player1_label = tk.Label(root, text="Player 1 (X)", font=("Arial", 16))
player1_label.grid(row=0, column=0)
player2_label = tk.Label(root, text="Player 2 (O)", font=("Arial", 16))
player2_label.grid(row=0, column=2)
# create the 3x3 grid of buttons
button_list = []
for row in range(3):
current_row = []
for column in range(3):
button = tk.Button(root, text="", font=("Arial", 16), width=5, height=2, command=lambda btn=button: button_clicked(btn))
button.grid(row=row+1, column=column)
current_row.append(button)
button_list.append(current_row)
root.mainloop()
random moves because minimaxed algs gonna take some timeeeee and it means I dont have timeee to work on my fat,cute,new game called pikimin adventore
Umm @Idkwhttph itās not your turnā¦ You didnāt even vote on the poll to joinā¦
Thatās cheating btw
I FORGOT OMG IM GONNA CRY I GET MINUS 20 POINTS AHH
Not if you didnāt even join the game. Iād delete your posts if I were you BTW.
@Firepup650 As your Last seen date is 8 minutes ago, and you have not submitted an answer to @QwertyQwerty88ās task within 48 hours, you lose 5 points.
interesting can I try something
Yes, you just have to join first! And wait your turnā¦
but I just wanna ask you to code smth
Oh, ok! Hopefully no one joins after you and youāll be able to give me a task.
when will you guys be done (I kinda just wanna see how this social experiment is)
Well, I have to give a task to someone now (thanks for reminding me)!
so I can ask someone a question after your done?
No, after they and whoeverās after them are done, then you will have to do your task, and then you can ask someone.
(Donāt worry, it canāt take that long, I have a 48-hour time limit).
Oh yeah, sorry. I kinda forgot this was here.