Multicode! A collaborational game

Oh I was waiting for you :smiley: 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.

1 Like

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.

2 Likes
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()
1 Like

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

:scream:
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.

2 Likes

@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.

1 Like

interesting can I try something

Yes, you just have to join first! And wait your turnā€¦

1 Like

but I just wanna ask you to code smth :frowning:

Oh, ok! Hopefully no one joins after you and youā€™ll be able to give me a task.

1 Like

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)!

1 Like

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).

@NataliaKazakiev Itā€™s your turn now.

Here is your task:

1 Like

Oh yeah, sorry. I kinda forgot this was here.