{"id":2122,"date":"2019-10-04T15:25:18","date_gmt":"2019-10-04T13:25:18","guid":{"rendered":"http:\/\/entropie.org\/3615\/?p=2122"},"modified":"2025-09-04T23:19:59","modified_gmt":"2025-09-04T21:19:59","slug":"puissance-4-en-python-competition-entre-intelligences-artificielles","status":"publish","type":"post","link":"https:\/\/entropie.org\/3615\/index.php\/2019\/10\/04\/puissance-4-en-python-competition-entre-intelligences-artificielles\/","title":{"rendered":"Puissance 4 en Python : Comp\u00e9tition entre intelligences artificielles"},"content":{"rendered":"<p>Dans un premier temps, l\u2019objectif est de mettre au point une intelligence artificielle (IA) la meilleure possible pour jouer \u00e0 Puissance 4, sans avoir \u00e0 descendre en profondeur dans un arbre comme avec l\u2019algorithme minimax ou alpha-b\u00eata. Viendra ensuite le temps des arbres, puis de l&rsquo;apprentissage&#8230;<\/p>\n<p><strong>Pr\u00e9sentation des IA<\/strong>\u00a0:<\/p>\n<p><u>Codage de la strat\u00e9gie<\/u>\u00a0:<\/p>\n<p><strong><span style=\"color:#00ff00;\">H<\/span><\/strong> veut dire <strong><span style=\"color:#00ff00;\">H<\/span>asard<\/strong><br \/>\n<strong><span style=\"color:#00ff00;\">P<\/span><\/strong> veut dire <strong><span style=\"color:#00ff00;\">P<\/span>oids des cases<\/strong> (il y a plus de possibilit\u00e9s d&rsquo;alignements pour certaines cases)<br \/>\n<strong><span style=\"color:#00ff00;\">AX<\/span><\/strong> veut dire <strong><span style=\"color:#00ff00;\">A<\/span>lignement de <span style=\"color:#00ff00;\">X<\/span> pions<\/strong> (l\u2019IA essaye d&rsquo;aligner X pions\u00a0; les alignements \u00ab\u00a0trou\u00e9s\u00a0\u00bb de 2 ou 3 pions ne sont pas encore pris en compte)<br \/>\n<strong><span style=\"color:#00ff00;\">BX<\/span><\/strong> veut dire <strong><span style=\"color:#00ff00;\">B<\/span>locage de <span style=\"color:#00ff00;\">X<\/span> pions<\/strong> (l\u2019IA essaye d&#8217;emp\u00eacher l&rsquo;adversaire d&rsquo;aligner X pions\u00a0; les alignements \u00ab\u00a0trou\u00e9s\u00a0\u00bb de 2 ou 3 pions ne sont pas encore pris en compte)<\/p>\n<p>IA0\u00a0: Priorit\u00e9 <span style=\"color:#00ff00;\">H<\/span><br \/>\nIA1\u00a0: Priorit\u00e9 <span style=\"color:#00ff00;\">P<\/span><br \/>\nIA2\u00a0: Priorit\u00e9s <span style=\"color:#00ff00;\">A4P \/ A3P \/ A2P \/ P<\/span><br \/>\nIA3\u00a0: Priorit\u00e9s <span style=\"color:#00ff00;\">B4P \/ B3P \/ B2P \/ P<\/span><br \/>\nIA4\u00a0: Priorit\u00e9s <span style=\"color:#00ff00;\">A4P \/ B4P \/ A3P \/ B3P \/ A2P \/ B2P \/ P<\/span><br \/>\nIA5\u00a0: Priorit\u00e9s <span style=\"color:#00ff00;\">A4P \/ B4P \/ A3P \/ B3P \/ B2P \/ A2P \/ P<\/span><br \/>\nIA6\u00a0: Priorit\u00e9s <span style=\"color:#00ff00;\">A4P \/ B4P \/ B3P \/ A3P \/ A2P \/ B2P \/ P<\/span><br \/>\nIA7\u00a0: Priorit\u00e9s <span style=\"color:#00ff00;\">A4P \/ B4P \/ B3P \/ A3P \/ B2P \/ A2P \/ P<\/span><br \/>\nIA8 : Priorit\u00e9s <span style=\"color:#00ff00;\">A4P \/ B4P \/ A2P \/ B2P \/ P<\/span><br \/>\nIA9 : Priorit\u00e9s <span style=\"color:#00ff00;\">A4P \/ B4P \/ B2P \/ A2P \/ P<\/span><\/p>\n<p><u>Pr\u00e9sentation des r\u00e9sultats<\/u> :<\/p>\n<p>Sur 1 million de parties (ou 10 000 pour des m\u00e9caniques r\u00e9p\u00e9titives bien que 2 suffiraient), les r\u00e9sultats bruts sont :<\/p>\n<p>IA0 \/ IA0 \/ Nulles : 498 180 \/ 499 269 \/ 2 551<br \/>\n<span style=\"color:#ffff00;\">IA1<\/span> \/ IA0 \/ Nulles : <span style=\"color:#ffff00;\">878 082<\/span> \/ 121 899 \/ 19<br \/>\n<span style=\"color:#ffff00;\">IA2<\/span> \/ IA0 \/ Nulles : <span style=\"color:#ffff00;\">971 125<\/span> \/ 28 874 \/ 1<br \/>\n<span style=\"color:#ffff00;\">IA3<\/span> \/ IA0 \/ Nulles : <span style=\"color:#ffff00;\">962 081<\/span> \/ 26 922 \/ 10 997<br \/>\n<span style=\"color:#ffff00;\">IA4<\/span> \/ IA0 \/ Nulles : <span style=\"color:#ffff00;\">987 349<\/span> \/ 12 637 \/ 14<br \/>\n<span style=\"color:#ffff00;\">IA5<\/span> \/ IA0 \/ Nulles : <span style=\"color:#ffff00;\">984 923<\/span> \/ 14 995 \/ 82<br \/>\n<span style=\"color:#ffff00;\">IA6<\/span> \/ IA0 \/ Nulles : <span style=\"color:#ffff00;\">989 355<\/span> \/ 10 538 \/ 107<br \/>\n<span style=\"color:#ffff00;\">IA7<\/span> \/ IA0 \/ Nulles : <span style=\"color:#ffff00;\">986 549<\/span> \/ 13 043 \/ 408<br \/>\n<span style=\"color:#ffff00;\">IA8<\/span> \/ IA0 \/ Nulles : <span style=\"color:#ffff00;\">971 554<\/span> \/ 28 431 \/ 15<br \/>\n<span style=\"color:#ffff00;\">IA9<\/span> \/ IA0 \/ Nulles : <span style=\"color:#ffff00;\">948 080<\/span> \/ 51 821 \/ 99<\/p>\n<p>IA1 \/ IA1 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne en 10 coups)<br \/>\n<span style=\"color:#ffff00;\">IA2<\/span> \/ IA1 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\n<span style=\"color:#ffff00;\">IA3<\/span> \/ IA1 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\nIA4 \/ IA1 \/ Nulles :  5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne)<br \/>\n<span style=\"color:#ffff00;\">IA5<\/span> \/ IA1 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\nIA6 \/ IA1 \/ Nulles :  5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne)<br \/>\n<span style=\"color:#ffff00;\">IA7<\/span> \/ IA1 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\n<span style=\"color:#ffff00;\">IA8<\/span> \/ IA1 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\nIA9 \/ IA1 \/ Nulles : 5 000 \/ 0 \/ 5 000 (quand IA9 commence, IA9 gagne)<\/p>\n<p>IA2 \/ IA2 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne en 4 coups)<br \/>\nIA3 \/ IA2 \/ Nulles : 0 \/ 5 000 \/ 5 000 (quand IA2 commence, IA2 gagne)<br \/>\n<span style=\"color:#ffff00;\">IA4<\/span> \/ IA2 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\n<span style=\"color:#ffff00;\">IA5<\/span> \/ IA2 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\n<span style=\"color:#ffff00;\">IA6<\/span> \/ IA2 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\n<span style=\"color:#ffff00;\">IA7<\/span> \/ IA2 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\nIA8 \/ IA2 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne)<br \/>\nIA9 \/ <span style=\"color:#ff0000;\">IA2<\/span> \/ Nulles : 0 \/ <span style=\"color:#ff0000;\">10 000<\/span> \/ 0<\/p>\n<p>IA3 \/ IA3 \/ <span style=\"color:#ffa500;\">Nulles<\/span> : 0 \/ 0 \/ <span style=\"color:#ffa500;\">10 000 *<\/span><br \/>\nIA4 \/ IA3 \/ Nulles : 0 \/ 5 000 \/ 5 000 (quand IA4 commence, IA3 gagne)<br \/>\n<span style=\"color:#ffff00;\">IA5<\/span> \/ IA3 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\nIA6 \/ <span style=\"color:#ff0000;\">IA3<\/span> \/ Nulles : 0 \/ <span style=\"color:#ff0000;\">10 000<\/span> \/ 0<br \/>\nIA7 \/ IA3 \/ Nulles : 0 \/ 5 000 \/ 5 000 (quand IA7 commence, IA3 gagne)<br \/>\nIA8 \/ IA3 \/ Nulles : 5 000 \/ 0 \/ 5 000 (quand IA8 commence, IA8 gagne)<br \/>\nIA9 \/ IA3 \/ <span style=\"color:#ffa500;\">Nulles<\/span> : 0 \/ 0 \/ <span style=\"color:#ffa500;\">10 000 *<\/span><\/p>\n<p>IA4 \/ IA4 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence perd en 17 coups)<br \/>\n<span style=\"color:#ffff00;\">IA5<\/span> \/ IA4 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\nIA6 \/ IA4 \/ <span style=\"color:#ffa500;\">Nulles<\/span> : 0 \/ 0 \/ <span style=\"color:#ffa500;\">10 000 *<\/span><br \/>\nIA7 \/ IA4 \/ Nulles : 5 000 \/ 0 \/ 5 000 (quand IA7 commence, IA7 gagne)<br \/>\nIA8 \/ <span style=\"color:#ff0000;\">IA4<\/span> \/ Nulles : 0 \/ <span style=\"color:#ff0000;\">10 000<\/span> \/ 0<br \/>\nIA9 \/ <span style=\"color:#ff0000;\">IA4<\/span> \/ Nulles : 0 \/ <span style=\"color:#ff0000;\">10 000<\/span> \/ 0<\/p>\n<p>IA5 \/ IA5 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne en 13 coups)<br \/>\nIA6 \/ <span style=\"color:#ff0000;\">IA5<\/span> \/ Nulles : 0 \/ <span style=\"color:#ff0000;\">10 000<\/span> \/ 0<br \/>\nIA7 \/ <span style=\"color:#ff0000;\">IA5<\/span> \/ Nulles : 0 \/ <span style=\"color:#ff0000;\">10 000<\/span> \/ 0<br \/>\nIA8 \/ IA5 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence perd)<br \/>\nIA9 \/ <span style=\"color:#ff0000;\">IA5<\/span> \/ Nulles : 0 \/ <span style=\"color:#ff0000;\">10 000<\/span> \/ 0<\/p>\n<p>IA6 \/ IA6 \/ <span style=\"color:#ffa500;\">Nulles<\/span> : 0 \/ 0 \/ <span style=\"color:#ffa500;\">10 000 *<\/span><br \/>\n<span style=\"color:#ffff00;\">IA7<\/span> \/ IA6 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\nIA8 \/ IA6 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne)<br \/>\nIA9 \/ IA6 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne)<\/p>\n<p>IA7 \/ IA7 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence perd en 19 coups)<br \/>\n<span style=\"color:#ffff00;\">IA8<\/span> \/ IA7 \/ Nulles : <span style=\"color:#ffff00;\">10 000<\/span> \/ 0 \/ 0<br \/>\nIA9 \/ IA7 \/ Nulles : 0 \/ 5 000 \/ 5 000 (quand IA7 commence, IA7 gagne)<\/p>\n<p>IA8 \/ IA8 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne en 8 coups)<br \/>\nIA9 \/ IA8 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne)<\/p>\n<p>IA9 \/ IA9 \/ Nulles : 5 000 \/ 5 000 \/ 0 (l&rsquo;IA qui commence gagne en 11 coups)<\/p>\n<p><u>Bilan<\/u> (Nombre de victoires franches) :<\/p>\n<p>IA0 : 0<br \/>\nIA1 : 1<br \/>\nIA2 : 3<br \/>\nIA3 : 3<br \/>\nIA4 : 4<br \/>\nIA5 : 8<br \/>\nIA6 : 2<br \/>\nIA7 : 4<br \/>\nIA8 : 3<br \/>\nIA9 : 1<\/p>\n<p>Sur les parties entre IA4, IA5, IA6 et IA7 : IA5 \u00e9crase les autres IA.<\/p>\n<p>Si on compare les strat\u00e9gies IA4 et IA5 (une seule inversion), B2P doit \u00eatre avant A2P pour gagner. Si on compare les strat\u00e9gies IA6 et IA7 (une seule inversion), B2P doit \u00eatre avant A2P pour gagner. Si on compare les strat\u00e9gies IA5 et IA7 (une seule inversion), A3P doit \u00eatre avant B3P pour gagner. Si on compare les strat\u00e9gies IA4 et IA6 (une seule inversion), A3P avant B3P n&rsquo;apporte aucun gain (match nul).<\/p>\n<p>Dans tous les cas, B2P doit \u00eatre avant A2P pour gagner. A3P avant B3P ne prend tout son potentiel que si B2P est avant A2P. Supprimons A3P et B3P pour voir&#8230; (IA8 et IA9)<\/p>\n<hr>\n<p>Petite r\u00e9flexion pour le futur : Si on d\u00e9compose une strat\u00e9gie en micro-strat\u00e9gies, cela nous am\u00e8ne comme ici \u00e0 un codage (une sorte d&rsquo;ADN de la strat\u00e9gie). Je verrais bien comme d\u00e9veloppement futur quelque chose avec les algorithmes g\u00e9n\u00e9tiques&#8230;<\/p>\n<hr>\n<p><span style=\"color:#00ff00;\">Quel est ce paradoxe ? IA5 \u00e9crase IA4, IA4 \u00e9crase IA8 et pourtant on n&rsquo;arrive pas \u00e0 d\u00e9partager IA5 et IA8. => Non transitif. C&rsquo;est un peu comme si des micro-logiques internes s&rsquo;interp\u00e9n\u00e9traient jusqu&rsquo;\u00e0 s&rsquo;an\u00e9antir&#8230; un peu comme le mangeur de planeurs dans le jeu de la vie.<\/span><\/p>\n<p>Code source sur <a href=\"https:\/\/github.com\/eserandour\/Puissance_4\" rel=\"noopener noreferrer\" target=\"_blank\">GitHub<\/a>.<\/p>\n<p><span style=\"color:#ffa500;\">* Extrait de <\/span><a style=\"color:#ffa500;\" href=\"https:\/\/www.youtube.com\/watch?v=gWo8zSlKUAI\" rel=\"noopener noreferrer\" target=\"_blank\"><span style=\"color:#ffa500;\">WarGames<\/span><\/a><span style=\"color:#ffa500;\"> (1983) :<\/span><\/p>\n<p><span style=\"color:#ffa500;\">GREETINGS PROFESSOR FALKEN<\/span><\/p>\n<p><span style=\"color:#ffa500;\">HELLO<\/span><\/p>\n<p><span style=\"color:#ffa500;\">A STRANGE GAME.<\/span><br \/>\n<span style=\"color:#ffa500;\">THE ONLY WINNING MOVE IS<\/span><br \/>\n<span style=\"color:#ffa500;\">NOT TO PLAY.<\/span><\/p>\n<p><span style=\"color:#ffa500;\">HOW ABOUT A NICE GAME OF CHESS?<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Dans un premier temps, l\u2019objectif est de mettre au point une intelligence artificielle (IA) la meilleure possible pour jouer \u00e0 Puissance 4, sans avoir \u00e0 descendre en profondeur dans un arbre comme avec l\u2019algorithme minimax ou alpha-b\u00eata. Viendra ensuite le temps des arbres, puis de l&rsquo;apprentissage&#8230; Pr\u00e9sentation des IA\u00a0: Codage de la strat\u00e9gie\u00a0: H veut &hellip; <a href=\"https:\/\/entropie.org\/3615\/index.php\/2019\/10\/04\/puissance-4-en-python-competition-entre-intelligences-artificielles\/\" class=\"more-link\">Continuer la lecture<span class=\"screen-reader-text\"> de &laquo;&nbsp;Puissance 4 en Python : Comp\u00e9tition entre intelligences artificielles&nbsp;&raquo;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34,33,21],"tags":[],"class_list":["post-2122","post","type-post","status-publish","format-standard","hentry","category-intelligence-artificielle","category-puissance-4","category-python"],"_links":{"self":[{"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/posts\/2122"}],"collection":[{"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/comments?post=2122"}],"version-history":[{"count":208,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/posts\/2122\/revisions"}],"predecessor-version":[{"id":7199,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/posts\/2122\/revisions\/7199"}],"wp:attachment":[{"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/media?parent=2122"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/categories?post=2122"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/entropie.org\/3615\/index.php\/wp-json\/wp\/v2\/tags?post=2122"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}