123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- from Outils.Moteur_de_jeu import *
- from Outils.Moteur_de_jeu.Partie import *
- from Outils import alphabeta
- from Outils.alphabeta import *
- from Outils.Moteur_de_jeu import *
- from Outils.Moteur_de_jeu.Partie import *
- from Outils import IA_alphabeta
- from Outils.IA_alphabeta import *
- def fct_eval_basique(plateau, num) :
- return plateau.longueur_chemin(1 - num) - plateau.longueur_chemin(num)
- def fct_eval_heuristique_1 (plateau,num) :
- nIA = plateau.longueur_chemin(num)
- n_opponent = plateau.longueur_chemin(1-num)
- b_IA = plateau.barrieres_restantes[num]
- return -nIA + n_opponent + 0.001 * b_IA
- def fct_eval_heuristique_2 (plateau,num):
- def f(n) :
- t = [1000000000,1000000,40,38]
- a = len(t)
- if n< a : return t[n]
- else :
- return 40-n
- def g(b) :
- t = [6,4,2,0,-2,-4,-6,-8,-10,-12.9,-15.8]
- return t[10-b]
- def g2(b) :
- t = [0.5,0,-0.5,-1,-1.5,-2,-3,-4,-5,-7.9,-10.8]
- return t[10-b]
- nIA = plateau.longueur_chemin(num)
- n_opponent = plateau.longueur_chemin(1-num)
- b_IA = plateau.barrieres_restantes[num]
- b_opponent = plateau.barrieres_restantes[1-num]
-
- if IA_minmax_alpha_beta.dist == None or IA_minmax_alpha_beta.dist > 5 :
- return f(nIA) - f(n_opponent) + g(b_IA) - g(b_opponent)
-
- return f(nIA) - f(n_opponent) + g2(b_IA) - g2(b_opponent)
- def panzer (plateau,num) :
- if plateau.rangee_desiree(num) == 8 :
- b1 = Barriere ("h", 3, 5)
- b2 = Barriere ("h", 6, 5)
- tr = [b1,b2]
- bar = plateau.liste_barrieres_possibles()
- for k in tr :
- if k in plateau.liste_barrieres :
- suppr (tr,k)
- for k in bar :
- if k == b1 :
- return Coup("B", barriere = b1)
- elif k == b2 :
- return Coup("B", barriere = b2)
-
- if plateau.joueur_sur_case( 1 - num, 5, 6) :
- b1 = Barriere ("v", 5, 4)
- b2 = Barriere ("v", 3, 4)
- b3 = Barriere ("v", 4, 4)
- b4 = Barriere ("v", 6, 4)
- t = [b1,b2,b3,b4]
- for k in t :
- if k in plateau.liste_barrieres :
- suppr (t,k)
- if len(t)==4 :
- for k in bar :
- if k == b1 :
- return Coup("B", barriere = b1)
- for k in bar :
- if k == b2 :
- return Coup("B", barriere = b2)
- for k in bar :
- if k == b3 :
- return Coup("B", barriere = b3)
- for k in bar :
- if k == b4 :
- return Coup("B", barriere = b4)
- else :
- b1 = Barriere ("h", 3, 2)
- b2 = Barriere ("h", 6, 2)
- tr = [b1,b2]
- bar = plateau.liste_barrieres_possibles()
- for k in tr :
- if k in plateau.liste_barrieres :
- suppr (tr,k)
- for k in bar :
- if k == b1 :
- return Coup("B", barriere = b1)
- elif k == b2 :
- return Coup("B", barriere = b2)
-
- if plateau.joueur_sur_case( 1 - num, 5, 2) :
- b1 = Barriere ("v", 5, 3)
- b2 = Barriere ("v", 3, 3)
- b3 = Barriere ("v", 4, 3)
- b4 = Barriere ("v", 6, 3)
- t = [b1,b2,b3,b4]
- for k in t :
- if k in plateau.liste_barrieres :
- suppr (t,k)
- if len(t)==4 :
- for k in bar :
- if k == b1 :
- return Coup("B", barriere = b1)
- for k in bar :
- if k == b2 :
- return Coup("B", barriere = b2)
- for k in bar :
- if k == b3 :
- return Coup("B", barriere = b3)
- for k in bar :
- if k == b4 :
- return Coup("B", barriere = b4)
-
-
-
- return (Coup("B", barriere = Barriere ("v", 42, 42) ))
-
-
-
- class IA_Anti_Gaël(Joueur) :
- def __init__(self, nom, fct_eval, prof ) :
- """
- la fonction d'évaluation sera donnée en entrée, et évaluera les positions.
- prof indique la profondeur souhaitée
- """
- Joueur.__init__(self,"O",nom)
- self.fct_eval = fct_eval
- self.prof = prof
-
- def calculer_coup( self, plateau, liste_coup) :
- #1. : avoir l'arbre
- #2. : calculer le coup
- #3 : le ressortir (trouver son indexation dans la liste des coups)
- #etape 1
- coup = panzer(plateau, self.num)
- if not coup == Coup("B", barriere = Barriere ("v", 42, 42)) :
-
- for i in range(len(liste_coup)) :
- if liste_coup[i] == coup :
- return i
- return obtenir_coup(self.num, plateau, self.fct_eval, self.prof)
-
- def fct_eval_anti_gael(plateau, num) :
- nIA = plateau.longueur_chemin(num)
- n_opponent = plateau.longueur_chemin(1-num)
- b_IA = plateau.barrieres_restantes[num]
- b_opponent = plateau.barrieres_restantes[1-num]
-
- """
- if deux_chemins(plateau,num) : c = -4
- if deux_chemins (plateau,1-num) : d = 3
- """
- def f(n) :
- t = [1000000000,1000000,40,38]
- a = len(t)
- if n< a : return t[n]
- else :
- return 40-n
- def g(b) :
- t = [6,4,2,0,-2,-4,-6,-8,-10,-12.9,-15.8]
- return t[10-b]
- def g2(b) :
- t = [0.5,0,-0.5,-1,-1.5,-2,-3,-4,-5,-7.9,-10.8]
- return t[10-b]
- if IA_minmax_alpha_beta.dist == None or IA_minmax_alpha_beta.dist >5 :
- return f(nIA) - f(n_opponent) + g(b_IA) - g(b_opponent)
- return f(nIA) - f(n_opponent) + g2(b_IA) - g2(b_opponent)
|