Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
return "Draw"
|
19 |
-
return None
|
20 |
-
|
21 |
-
def make_move(i):
|
22 |
-
if board[i] or winner[0]:
|
23 |
-
return update_game()
|
24 |
-
board[i] = current_player[0]
|
25 |
-
result = check_winner(board)
|
26 |
-
if result:
|
27 |
-
winner[0] = result
|
28 |
else:
|
29 |
-
|
30 |
-
return update_game()
|
31 |
-
|
32 |
-
def update_game():
|
33 |
-
status = f"Winner: {winner[0]}" if winner[0] else f"Turn: {current_player[0]}"
|
34 |
-
return board, status
|
35 |
-
|
36 |
-
def reset_game():
|
37 |
-
for i in range(9): board[i] = ""
|
38 |
-
current_player[0] = "X"
|
39 |
-
winner[0] = None
|
40 |
-
return update_game()
|
41 |
|
42 |
-
|
43 |
-
gr.Markdown("## 🎮 Tic Tac Toe (Hugging Face Version)")
|
44 |
-
btns = [gr.Button("", elem_id=f"btn{i}") for i in range(9)]
|
45 |
-
status = gr.Markdown("Turn: X")
|
46 |
-
reset = gr.Button("Reset Game")
|
47 |
|
48 |
-
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
|
52 |
|
53 |
-
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import random
|
3 |
+
|
4 |
+
choices = ["Rock", "Paper", "Scissors"]
|
5 |
+
|
6 |
+
def play_rps(user_choice):
|
7 |
+
bot_choice = random.choice(choices)
|
8 |
+
result = ""
|
9 |
+
|
10 |
+
if user_choice == bot_choice:
|
11 |
+
result = "It's a draw!"
|
12 |
+
elif (
|
13 |
+
(user_choice == "Rock" and bot_choice == "Scissors") or
|
14 |
+
(user_choice == "Paper" and bot_choice == "Rock") or
|
15 |
+
(user_choice == "Scissors" and bot_choice == "Paper")
|
16 |
+
):
|
17 |
+
result = "You win! 🎉"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
else:
|
19 |
+
result = "You lose 😢"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
|
21 |
+
return f"You chose: {user_choice}\nBot chose: {bot_choice}\n\n{result}"
|
|
|
|
|
|
|
|
|
22 |
|
23 |
+
iface = gr.Interface(
|
24 |
+
fn=play_rps,
|
25 |
+
inputs=gr.Radio(choices, label="Choose your move"),
|
26 |
+
outputs="text",
|
27 |
+
title="Rock-Paper-Scissors Game",
|
28 |
+
description="Play against a bot. Make your move!"
|
29 |
+
)
|
30 |
|
31 |
+
iface.launch()
|
32 |
|
|