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'])
|
||||
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):
|
||||
# Définition du mode
|
||||
# Choix du mode
|
||||
if 'ia' not in jeu:
|
||||
jeu['ia'] = dict()
|
||||
jeu['ia']['mode'] = 0
|
||||
print(type(res), res)
|
||||
if type(res) == int:
|
||||
if res == BN.COULE:
|
||||
# input("COULÉ")
|
||||
jeu['ia']['mode'] = 0
|
||||
elif res == BN.TOUCHE:
|
||||
print('Again')
|
||||
# input("TOUCHÉ")
|
||||
jeu['ia']['d_touche'] = jeu['ia']['d_coup']
|
||||
jeu['ia']['mode'] = 1
|
||||
|
||||
# Acteur
|
||||
if jeu['ia']['mode'] == 1: # Si en mode recherche
|
||||
print('DEBUG MODE RECHERCHE')
|
||||
while 1:
|
||||
x = randint(0, jeu['plateau']['larg'])
|
||||
y = randint(0, jeu['plateau']['larg'])
|
||||
# print('DEBUG MODE RECHERCHE', jeu['ia']['d_touche'])
|
||||
proxi = [(0, 1), (0, -1), (1, 0), (-1, 0)]
|
||||
for i in proxi:
|
||||
x = jeu['ia']['d_touche'][0] + i[0]
|
||||
y = jeu['ia']['d_touche'][1] + i[1]
|
||||
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
|
||||
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
|
||||
while 1:
|
||||
x = randint(0, jeu['plateau']['larg'])
|
||||
|
@ -93,7 +102,7 @@ def choisir_tir_3(jeu, res):
|
|||
coup = (x, y)
|
||||
if coup not in jeu['coups_joues']:
|
||||
break
|
||||
d_coup = coup
|
||||
jeu['ia']['d_coup'] = coup
|
||||
return coup
|
||||
|
||||
|
||||
|
|
Reference in a new issue