Bonjour!

Je dois créer un jeu de bataille navale sur python joueur contre ordinateur...
Mais je ne sais pas comment programmer le jeu de l'ordinateur..
J'ai certaines idées pour le placement des bateuax de l'ordi, mais je sèche pour le jeu de l'ordi...

Voici mon code:
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
 
from tkinter import *
 
bateaux_places=0
 
def set_color(button):
    def do_it():
        global bateaux_places
        if bateaux_places>=17:
             button['bg'] = 'light sky blue'
             bateaux_places=bateaux_places+1
        else:
            button['bg'] = 'black'
            bateaux_places=bateaux_places+1
 
    return do_it
 
 
def set_color2(button2):
    def do_it2():
        button2['bg'] = 'BLUE'
    return do_it2
 
def bateau_placés ():
 
    if bateaux_places>=17:
        B1.select()
        B2.select()
        B3.select()
        B4.select()
        B5.select()
        for x in range(10):
            for y in range(10):
                button2 = Button(F2,bd=5,width=7,height=3, bg=color2)
                button2['command']=set_color2(button2) 
                button2.grid(row=y, column=x)
    else:
        pasbon=Label(F3,text="Attention, tout les bateaux n'ont pas été placé!")
        pasbon.grid(row=12,column=1)
 
 
 
fen= Tk()
fen.resizable(width=NO,height=NO)
 
F3=Frame(fen)
F4=Frame(fen)
F1=Frame(fen)
F2=Frame(fen)
F5=Frame(fen)
 
color = 'light sky blue'
color2='light sky blue'
 
text1=Label(F3,text="Voici votre grille,veuillez placer vos bateaux")
text1.grid(row=1,column=1)
 
var1 = IntVar()
B1 = Checkbutton(F3, text = "Porte-avions(5 cases)", variable = var1)
B1.grid(row=2,sticky=W)
var2 = IntVar()
B2 = Checkbutton(F3, text = "croiseur(4cases)", variable = var2)
B2.grid(row=3,sticky=W)
var3 = IntVar()
B3 = Checkbutton(F3, text = "contre-torpilleurs(3 cases)", variable = var3)
B3.grid(row=4,sticky=W)
var4 = IntVar()
B4 = Checkbutton(F3, text = "sous-marin(3 cases)", variable = var4)
B4.grid(row=5,sticky=W)
var5 = IntVar()
B5 = Checkbutton(F3, text = "torpilleur(2 cases)", variable = var5)
B5.grid(row=6,sticky=W)
text2=Label(F3,text="Attention,veullez ne pas mettre vos bateau en diagonales, ni par petits bouts!")
text2.grid(row=7,column=1)
text3=Label(F3,text="Ne vous trompez pas, vous n'avez que le nombre de clics correspondant aux nombres de bateaux!")
text3.grid(row=8,column=1)
text4=Label(F3,text="Dans cette version, les bateaux peuvent se toucher.Bon jeu! ;)")
text4.grid(row=9,column=1)
text5=Label(F3,text="Cliquez sur jouer quand tout vos bateaux sont cochés!")
text5.grid(row=10,column=1)
 
 
 
text1=Label(F4,text="Voici la grille de votre adversaire.")
text1.grid(row=1,column=1)
text2=Label(F4,text="Quand ce serra a votre tour, vous pourrez cliquer sur la case de votre choix pour attaquer")
text2.grid(row=2,column=1)
text3=Label(F4,text="La case deviendra bleu si vous n'avez touché aucun bateau de l'adversiare.")
text3.grid(row=3,column=1)
text4=Label(F4,text="Elle deviedra noire si vous avez touché un de ses bateau.")
text4.grid(row=4,column=1)
 
lancer=Button(F3,text="jouer!",command=bateau_placés)
lancer.grid(row=11,column=1)
 
for x in range(10):
    for y in range(10):
        button = Button(F1,bd=5,width=7,height=3, bg=color)
        button['command']=set_color(button) 
        button.grid(row=y, column=x)
for x in range(12,13):
    for y in range (10):
        button3 = Button(F1,bd=0,width=7,height=3)
        button3.grid(row=y,column=x)
 
Rejouer=Button(F5,text="Rejouer!")
Rejouer.grid(row=1,column=1)
 
F3.grid(row=1,column=1)
F4.grid(row=1,column=2)
F2.grid(row=2,column=2)
F1.grid(row=2,column=1)
F5.grid(row=3,column=2)
fen.mainloop()
Merci de me donner des pistes!

Bonne journée!