Bonjour, je me lance dans la vaste aventure de vouloir programmer un jeu d'échecs sans IA, juste deux humains qui s'affrontent. J'ai déjà commencé à écrire le code j'ai pas mal exploré les possibilités graphiques, et je me suis lancé sur du Tkinter. Mon idée initiale est de faire 64 cases en grille qui sont des boutons(ce qui sera donc le plateau), en suite je positionne sur ces boutons d'autres boutons qui seront donc les pièces, de façon à ce que le bouton pièce recouvre intégralement le bouton du plateau. La suite serait donc de cliquer sur une pièce, puis sur une case du plateau, ce qui ferait bouger la pièce si le déplacement est autorisé, mais je n'ai aucune idée de comment m'y prendre et si mon idée est initialement possible. Voici ce que j'ai écris :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from tkinter import *
root = Tk()
can = Canvas(root, width=2000, height=2000, background='ivory')
can.pack()
echecs = Frame(can, borderwidth=10, padx=100, pady=50)
echecs.pack(side=LEFT)
Colonnes = [-1,1,2,3,4,5,6,7,8,-1]
Lignes = [-1,1,2,3,4,5,6,7,8,-1]
tour_blanc = PhotoImage(file='tour.blanc.png')
tour_noir = PhotoImage(file='tour.noir.png')
cavalier_blanc = PhotoImage(file='cavalier.blanc.png')
cavalier_noir = PhotoImage(file='cavalier.noir.png')
fou_blanc = PhotoImage(file='fou.blanc.png')
fou_noir = PhotoImage(file='fou.noir.png')
roi_blanc = PhotoImage(file='roi.blanc.png')
roi_noir = PhotoImage(file='roi.noir.png')
reine_blanc = PhotoImage(file='reine.blanc.png')
reine_noir = PhotoImage(file='reine.noir.png')
pion_blanc = PhotoImage(file='pion.blanc.png')
pion_noir = PhotoImage(file='pion.noir.png')
color_red = ['red', 'blue']
color2=['black','white']
color1=['white','black']
j=1
i=1
c=1
cases=[]
def tbs(tb) :
	tb.grid(column=1, row=5, sticky='nesw')
while j < 9 :
	while i < 9 : 
		if (j == 1 or j == 8) and (i == 1 or i == 8):
			if i == 1 :
				tb = Button(echecs, image=tour_blanc, text= str(i)+str(j), bg='black', fg='white', relief=FLAT)
				a1=Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN, command=tbs(tb))
				a1.grid(column=Colonnes[j], row=Lignes[i])
 
			else :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=tour_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			c=1-c
			i+=1
		elif (j == 2 or j == 7) and (i == 1 or i == 8):
			if i == 1 :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=cavalier_blanc, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			else :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=cavalier_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			c=1-c
			i+=1
		elif (j == 3 or j == 6) and (i == 1 or i == 8):
			if i == 1 :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=fou_blanc, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			else :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=fou_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			c=1-c
			i+=1
		elif j == 4 and (i == 1 or i == 8):
			if i == 1 :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=roi_blanc, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			else :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=roi_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			c=1-c
			i+=1
		elif j == 5 and (i == 1 or i == 8):
			if i == 1 :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=reine_blanc, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			else :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=reine_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			c=1-c
			i+=1
		elif i == 2 or i == 7 :
			if i == 2 :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=pion_blanc, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			else :
				Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
				Button(echecs, image=pion_noir, bg=color1[c], fg=color2[c], relief=FLAT).grid(column=Colonnes[j], row=Lignes[i])
			c=1-c
			i+=1
		else :
			Button(echecs, text= str(i)+str(j), borderwidth=1, height=7, width=14, bg=color1[c], fg=color2[c], relief=SUNKEN).grid(column=Colonnes[j], row=Lignes[i])
			c=1-c
			i+=1
	i=1
	j+=1
	c=1-c
print(echecs.grid_slaves(column=1, row= 5))
#tb.grid_remove()
#tb.grid()
root.mainloop()
Dans le code je me sers du bouton 'tb' - > tour blanche pour testé deux trois trucs, peu probant.

D'autres problèmes se sont ajoutés comme le fait que je voulais que mon bouton 'tb' ne place la tour que quand je clique dessus (simple test) mais à la place il me l'affiche dès le lancement du programme. Je ne sais pas pourquoi. (c'est probablement évident mais pas pour moi). Puis le second problème est comment gérer les collisions et les déplacements hors de la grille ? No sé. Ainsi que comment réussir à faire mes boutons pièces et gérer leurs déplacement de sorte à ce qu'ils conservent la couleur de la case sur laquelle ils sont. Je ne vous demande bien évidemment pas de me faire mon programme, puisque ça n'aurait aucun intérêt, mais si vous avez des méthodes, des idées, une façon structuré de m'orienter pour y parvenir, je suis preneur. Merci d'avance.