GeminiAi commited on
Commit
e0c3bdd
·
verified ·
1 Parent(s): 8148851

Rename app.py to variables.py

Browse files
Files changed (2) hide show
  1. app.py +0 -96
  2. variables.py +34 -0
app.py DELETED
@@ -1,96 +0,0 @@
1
- import gradio as gr
2
- import random
3
-
4
- # Initialize the board, pieces, and game state
5
- class CheckersGame:
6
- def __init__(self):
7
- self.board = self.create_board()
8
- self.turn = 'white' # White goes first
9
- self.game_over = False
10
-
11
- def create_board(self):
12
- board = [['' for _ in range(8)] for _ in range(8)]
13
- # Initialize the pieces
14
- for row in range(3):
15
- for col in range(row % 2, 8, 2):
16
- board[row][col] = 'red'
17
- for row in range(5, 8):
18
- for col in range(row % 2, 8, 2):
19
- board[row][col] = 'white'
20
- return board
21
-
22
- def make_move(self, model_1, model_2):
23
- # AI logic: Random move for the sake of simplicity
24
- if self.game_over:
25
- return self.render_board(), "Game Over! Restart to play again."
26
-
27
- valid_moves = self.get_valid_moves(self.turn)
28
- if valid_moves:
29
- move = random.choice(valid_moves)
30
- self.board[move[2]][move[3]] = self.board[move[0]][move[1]]
31
- self.board[move[0]][move[1]] = ''
32
- self.turn = 'white' if self.turn == 'red' else 'red'
33
- return self.render_board(), f"{self.turn.capitalize()} moved using {model_1 if self.turn == 'white' else model_2}."
34
- else:
35
- self.game_over = True
36
- return self.render_board(), f"Game Over! {self.turn.capitalize()} has no moves left."
37
-
38
- def get_valid_moves(self, color):
39
- valid_moves = []
40
- for row in range(8):
41
- for col in range(8):
42
- if self.board[row][col] == color:
43
- # Check all directions for valid moves (simplified)
44
- directions = [(-1, -1), (-1, 1), (1, -1), (1, 1)]
45
- for dr, dc in directions:
46
- new_row, new_col = row + dr, col + dc
47
- if 0 <= new_row < 8 and 0 <= new_col < 8 and self.board[new_row][new_col] == '':
48
- valid_moves.append((row, col, new_row, new_col))
49
- return valid_moves
50
-
51
- def render_board(self):
52
- board_repr = ''
53
- for row in self.board:
54
- board_repr += ' '.join([cell[0].upper() if cell else '.' for cell in row]) + '\n'
55
- return board_repr
56
-
57
- # Initialize the Checkers game instance
58
- game = CheckersGame()
59
-
60
- # Function to handle the game move and display
61
- def play_checkers(model_1, model_2):
62
- board, status = game.make_move(model_1, model_2)
63
- return board, status
64
-
65
- # Gradio interface
66
- def create_ui():
67
- with gr.Blocks() as demo:
68
- gr.Markdown("## AI vs AI - Watch the Game!")
69
-
70
- with gr.Row():
71
- # Display the board and game status
72
- board_display = gr.Textbox(label="Game Board", interactive=False, value=game.render_board(), lines=8, max_lines=8)
73
- game_status = gr.Textbox(label="Game Status", interactive=False, value="Game is running...", lines=2)
74
-
75
- with gr.Row():
76
- model_dropdown_1 = gr.Dropdown(
77
- choices=["GPT-2", "DistilGPT-2", "BERT"],
78
- label="AI Model for Player 1 (White)",
79
- value="GPT-2"
80
- )
81
- model_dropdown_2 = gr.Dropdown(
82
- choices=["GPT-2", "DistilGPT-2", "BERT"],
83
- label="AI Model for Player 2 (Red)",
84
- value="DistilGPT-2"
85
- )
86
-
87
- # Button to simulate a move and update the board
88
- play_button = gr.Button("AI makes a move")
89
- play_button.click(play_checkers, inputs=[model_dropdown_1, model_dropdown_2], outputs=[board_display, game_status])
90
-
91
- return demo
92
-
93
- # Launch the Gradio app
94
- if __name__ == "__main__":
95
- ui = create_ui()
96
- ui.launch(share=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
variables.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # physical properties of the game
3
+
4
+ # this will create a board of dimension ( dimension * dimension pixels)
5
+ dimension = 720
6
+
7
+ # this will create a board with units (unit * unit)
8
+ units = 8
9
+ unit_size = dimension//units
10
+
11
+ # Colors
12
+ dark_block = (0, 0, 0)
13
+ light_block = (255, 255, 255)
14
+
15
+ dark_piece = (255, 100, 0)
16
+ dark_king = (255, 0, 100)
17
+
18
+ light_piece = (0, 100, 255)
19
+ light_king = (0, 255, 0)
20
+
21
+ # Game Flow
22
+
23
+ # chancing
24
+ chance = [1,3]
25
+ next = [2,4]
26
+
27
+
28
+ # hovering the grabbed piece
29
+ hover_piece = 0
30
+ took_from = 0
31
+ avails = []
32
+
33
+ d = [1,3]
34
+ u = [2,4]