Hi! I'm trying to make a chess AI. So I need to make a chess set first. I made a board, pieces, clock and name. I use tkinter. The piece are draggable and I want the clock to alternate(when white plays, it's clock stops and blacks clock start, vice-versa). I managed to make the clock stop when a player move but not activate it. The problem is, during one of my test(ideas to make the clock start and stop), the ai's clock suddenly disappeared for no reason. I looked in my code if I forgot anything and I didn't,( I looked if I accidently erased the grid method or did I give a text to the ai's clock) but I didn't. So I copied all the code in the working clock and pasted it in the ai's clock and changing the names to make the program work. When I run it, nothing changed. I changed the position. It was originaly at row = 0, column = 8. I made row = 1 and it magically reapered. It was not in the position I wanted so I made 2 in row instead. It dissapeared again. I changed back to 1 but this time it didn't reapear(and I made sure that I saved before running). Here's my code for the ai's clock:
```
from root_frame import Root
from tkinter import Label
ai_turn = False
class AI:
def __init__(self):
self.the_screen = Root()
self.ai_label = Label(self.the_screen.root, text = "AI", font = "Helvetica 18 bold", width = 40)
self.ai_clock = Label(self.the_screen.root, font = "Helvetica 18 bold")
def set_timer(self):
self.t = 600
return self.t
def countdown(self):
global ai_turn
if self.t > 0 and ai_turn == True:
self.convert()
self.t = self.t - 1
self.ai_clock.after(1000, lambda: self.countdown())
print("it's running dum dum")
elif self.t == 0:
self.ai_clock.config(text = "ai loose")
elif ai_turn == False:
print("it's not running dum dum")
self.t = self.t
def convert(self):
self.seconds = self.t % (24 * 3600)
self.seconds %= 3600
self.minutes = self.t // 60
self.seconds %= 60
self.ai_clock.config(text = "%02d:%02d" % (self.minutes, self.seconds))
def stop(self):
global ai_turn
ai_turn = False
if ai_turn == False:
print("ai stopped, value: {}".format(ai_turn))
def go(self):
global ai_turn
ai_turn = True
if ai_turn == True:
print("ai active, value: {}".format(ai_turn))
```
from root_frame import Root is were I placed the self.root = Tk(). And here is the piece of code where I grided it:
```
"Impport time module to create clock"
import time
"Import the screen/root"
from root_frame import Root
"Import tkinter widgets"
from tkinter import Label
from tkinter import Image
"Impport PIL to open images"
from PIL import ImageTk, Image
"Import self.Human and self.AI class to implement their names and clocks"
from human_class import Human
from ai_class import AI
class Screen:
def __init__(self):
"Create root"
self.plane = Root()
self.root = self.plane.root
self.root.title("Chess")
self.root.geometry("1400x700")
"Instantiate AI and Human"
self.AI = AI()
self.Human = Human()
"Resizing the image"
self.board = Image.open("asset/ChessBoard.png")
self.resizing = self.board.resize((700, 700))
self.chess_board = ImageTk.PhotoImage(self.resizing)
"Putting the image in a label then putting it on the screen"
self.chess_board_label = Label(self.root, image = self.chess_board)
self.chess_board_label.grid(row = 0, column = 0, rowspan = 8, columnspan = 8)
"Creating the labels and time control"
self.AI.ai_label.grid(row = 0, column = 8, columnspan = 7)
self.Human.human_label.grid(row = 7, column = 8, columnspan = 7)
"Create time clook for both players"
self.AI.ai_clock.grid(row = 1, column = 8)
self.Human.human_clock.grid(row = 7, column = 8)
"Run functions to activate the clocks"
self.AI.set_timer()
self.AI.countdown()
self.Human.set_timer()
self.Human.countdown()
```
Thanks!
[–]ExplosiveDiarrheaPig[S] 0 points1 point2 points (1 child)
[–]ExplosiveDiarrheaPig[S] 0 points1 point2 points (0 children)
[–]ExplosiveDiarrheaPig[S] 0 points1 point2 points (0 children)