TP3A choisir_tir_3 stratégie finie
Ne fonctionne pas, car scores souvent > 100
This commit is contained in:
parent
7114d9bf44
commit
f7900b705c
|
@ -64,28 +64,37 @@ def choisir_tir_2(jeu, res):
|
||||||
y = randint(0, jeu['plateau']['haut'])
|
y = randint(0, jeu['plateau']['haut'])
|
||||||
return (x, y)
|
return (x, y)
|
||||||
|
|
||||||
|
def en_bonds(esp, c):
|
||||||
|
return not (c[0] > esp['larg'] or c[0] <= 0 or c[1] <= 0 or c[1] > esp['haut'])
|
||||||
|
|
||||||
def choisir_tir_3(jeu, res):
|
def choisir_tir_3(jeu, res):
|
||||||
# Définition du mode
|
# Choix du mode
|
||||||
if 'ia' not in jeu:
|
if 'ia' not in jeu:
|
||||||
jeu['ia'] = dict()
|
jeu['ia'] = dict()
|
||||||
jeu['ia']['mode'] = 0
|
jeu['ia']['mode'] = 0
|
||||||
print(type(res), res)
|
|
||||||
if type(res) == int:
|
if type(res) == int:
|
||||||
if res == BN.COULE:
|
if res == BN.COULE:
|
||||||
|
# input("COULÉ")
|
||||||
jeu['ia']['mode'] = 0
|
jeu['ia']['mode'] = 0
|
||||||
elif res == BN.TOUCHE:
|
elif res == BN.TOUCHE:
|
||||||
print('Again')
|
# input("TOUCHÉ")
|
||||||
|
jeu['ia']['d_touche'] = jeu['ia']['d_coup']
|
||||||
jeu['ia']['mode'] = 1
|
jeu['ia']['mode'] = 1
|
||||||
|
|
||||||
# Acteur
|
# Acteur
|
||||||
if jeu['ia']['mode'] == 1: # Si en mode recherche
|
if jeu['ia']['mode'] == 1: # Si en mode recherche
|
||||||
print('DEBUG MODE RECHERCHE')
|
# print('DEBUG MODE RECHERCHE', jeu['ia']['d_touche'])
|
||||||
while 1:
|
proxi = [(0, 1), (0, -1), (1, 0), (-1, 0)]
|
||||||
x = randint(0, jeu['plateau']['larg'])
|
for i in proxi:
|
||||||
y = randint(0, jeu['plateau']['larg'])
|
x = jeu['ia']['d_touche'][0] + i[0]
|
||||||
|
y = jeu['ia']['d_touche'][1] + i[1]
|
||||||
coup = (x, y)
|
coup = (x, y)
|
||||||
if coup not in jeu['coups_joues']:
|
# print('COUP', coup)
|
||||||
|
if coup not in jeu['coups_joues'] and en_bonds(jeu['plateau'], coup):
|
||||||
break
|
break
|
||||||
|
if i == proxi[-1]: # Si sans succès, on essaye autre chose
|
||||||
|
# (arrive quand 2 navires sont cote à cote)
|
||||||
|
jeu['ia']['mode'] = 0
|
||||||
else: # Si en mode aléatoire
|
else: # Si en mode aléatoire
|
||||||
while 1:
|
while 1:
|
||||||
x = randint(0, jeu['plateau']['larg'])
|
x = randint(0, jeu['plateau']['larg'])
|
||||||
|
@ -93,7 +102,7 @@ def choisir_tir_3(jeu, res):
|
||||||
coup = (x, y)
|
coup = (x, y)
|
||||||
if coup not in jeu['coups_joues']:
|
if coup not in jeu['coups_joues']:
|
||||||
break
|
break
|
||||||
d_coup = coup
|
jeu['ia']['d_coup'] = coup
|
||||||
return coup
|
return coup
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue