-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ajout du code source
- Loading branch information
Showing
249 changed files
with
14,479 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vous trouverez ici le code de la grille de puissance 4 ainsi que le fichier stratgies qui contient toutes les stratégies que j'ai utilisé | ||
|
||
je rappelle que ces codes ont été fait par Physic Gamer, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,320 @@ | ||
|
||
|
||
int progress = 0; | ||
int stage = 1; | ||
int info_exec = 0; | ||
int info_exec2 = 0; | ||
int info_exec3 = 0; | ||
|
||
//import | ||
import java.util.Vector; | ||
|
||
|
||
//stratégie | ||
int rotate = 0; | ||
|
||
int strat1(){ | ||
rotate ++; | ||
if(rotate > 6){ | ||
rotate = 0; | ||
} | ||
return(rotate); | ||
} | ||
|
||
int lepif(){ | ||
|
||
return(int(random(0,6))); | ||
} | ||
|
||
// alogrithme minimax | ||
int vision(int[][] data,int dist,int x, int y,int distA){ | ||
info_exec = 0; | ||
info_exec = -1; | ||
info_exec = 3; | ||
progress = 0; | ||
float[] proba = new float[x]; | ||
proba = calcC(data,dist,x,y,distA); | ||
|
||
float max=-40000; | ||
Vector<Integer> indexs = new Vector<Integer>(); | ||
for(int i = 0; i < x; i++){ | ||
if(max > proba[i]){ | ||
continue; | ||
} | ||
if(max == proba[i]){ | ||
indexs.add(i); | ||
}else{ | ||
indexs = new Vector(); | ||
indexs.add(i); | ||
max = proba[i]; | ||
} | ||
} | ||
println("execution totale : "+info_exec); | ||
println("execution totale : "+info_exec2); | ||
println("execution totale : "+info_exec3); | ||
|
||
//choisis aux hasard pour départager les probavilités égales | ||
int choix = 0; | ||
if(indexs.size() > 1){ | ||
choix = floor(random(indexs.size())); | ||
} | ||
println(proba); | ||
return(indexs.elementAt(choix)); | ||
} | ||
|
||
|
||
float[] calcC(int[][] dataset,int dist,int x, int y,int distA){ | ||
info_exec ++; | ||
float[] prob = new float[x]; | ||
|
||
|
||
if(dist != 0){ | ||
out : for(int j = 0; j < dataset.length;j++){ | ||
|
||
//verifie les victoires possible | ||
int yY = gety(j,dataset); | ||
if(yY != -1){ | ||
int[][] map = map(dataset); | ||
map[j][yY] = -1; | ||
if(check_align_focus(dataset.length,dataset[0].length,map,4,j,gety(j,dataset),-1)){ | ||
prob[j] = 100; | ||
break out; | ||
}else{ | ||
|
||
int perte = 7; | ||
float[] P2 = new float[x]; | ||
out2 : for(int k = 0; k < dataset.length;k++){ | ||
//verifie les défaites possible | ||
if(gety(k,map) != -1){ | ||
int[][] map2 = map(map); | ||
map2[k][gety(k,map)] = 1; | ||
if(check_align_focus(map2.length,map2[0].length,map2,4,k,gety(k,map),1)){ | ||
P2[k] = -100; | ||
break out2; | ||
}else{ | ||
P2[k] = max(calcC(map2,dist-1,x,y,distA-1)); | ||
} | ||
}else{ | ||
perte --; | ||
P2[k] = 1000; | ||
} | ||
|
||
} | ||
if(distA > 0){ | ||
prob[j] = min(P2); | ||
}else{ | ||
prob[j] = moyenne(P2,7)-((1000/7)*(7-perte)); | ||
} | ||
} | ||
}else{ | ||
prob[j] = -1000; | ||
} | ||
} | ||
|
||
}else{ | ||
for(int k = 0; k < dataset.length;k++){ | ||
prob[k] = 0; | ||
} | ||
} | ||
|
||
return(prob); | ||
} | ||
|
||
|
||
int gety(int col,int[][] data){ | ||
|
||
|
||
for(int i = 0; i < data[0].length; i++){ | ||
if(data[col][i] == 0){ | ||
return(i); | ||
} | ||
} | ||
return(-1); | ||
|
||
} | ||
|
||
|
||
int check_align(int x, int y, int[][] case_info, int align_needed, int Player){ | ||
|
||
int output = 0; | ||
// allignement horizontaux | ||
for(int i = 0; i <= x-align_needed; i++){ | ||
for(int j = 0; j < y; j ++){ | ||
int value = case_info[i][j]; | ||
if(value == 0){ | ||
continue; | ||
} | ||
boolean alligned = true; | ||
for(int k = 0; k < align_needed; k++){ | ||
if(case_info[i+k][j] != value){ | ||
alligned = false; | ||
break; | ||
} | ||
} | ||
if(alligned){ | ||
if(Player == value){ | ||
output += 1; | ||
}else{ | ||
output -= 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// allignement verticaux | ||
for(int i = 0; i <= y-align_needed; i++){ | ||
for(int j = 0; j < x; j ++){ | ||
int value = case_info[j][i]; | ||
if(value == 0){ | ||
continue; | ||
} | ||
boolean alligned = true; | ||
for(int k = 0; k < align_needed; k++){ | ||
if(case_info[j][i+k] != value){ | ||
alligned = false; | ||
break; | ||
} | ||
} | ||
if(alligned){ | ||
if(Player == value){ | ||
output += 1; | ||
}else{ | ||
output -= 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// alignement en diagonale en haut à droite | ||
for(int i = 0; i <= y-align_needed; i++){ | ||
for(int j = 0; j <= x-align_needed; j ++){ | ||
int value = case_info[j][i]; | ||
if(value == 0){ | ||
continue; | ||
} | ||
boolean alligned = true; | ||
for(int k = 0; k < align_needed; k++){ | ||
if(case_info[j+k][i+k] != value){ | ||
alligned = false; | ||
break; | ||
} | ||
} | ||
if(alligned){ | ||
if(Player == value){ | ||
output += 1; | ||
}else{ | ||
output -= 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
// alignement en diagonale en bas à droite | ||
for(int i = 0; i <= y-align_needed; i++){ | ||
for(int j = align_needed-1; j < x; j ++){ | ||
int value = case_info[j][i]; | ||
if(value == 0){ | ||
continue; | ||
} | ||
boolean alligned = true; | ||
for(int k = 0; k < align_needed; k++){ | ||
if(case_info[j-k][i+k] != value){ | ||
alligned = false; | ||
break; | ||
} | ||
} | ||
if(alligned){ | ||
if(Player == value){ | ||
output += 1; | ||
}else{ | ||
output -= 1; | ||
} | ||
} | ||
} | ||
} | ||
|
||
return(output); | ||
} | ||
|
||
|
||
|
||
// pour minimiser les calculs cette fonction ne verifie que les allignement d'une case car si il y a un nouvel alignement, il sera forcément la où le joueur vient de jouer sinon il aurait été détécter au ddernier tour | ||
boolean check_align_focus(int x, int y, int[][] case_info, int align_needed,int PX, int PY,int value){ | ||
|
||
|
||
info_exec3 += 1; | ||
//H | ||
|
||
int streak = 0; | ||
for(int i = PX-3;i <= PX + 3; i ++){ | ||
if(i >= 0 && i < x){ | ||
if(case_info[i][PY] == value){ | ||
streak += 1; | ||
}else{ | ||
streak = 0; | ||
} | ||
if(streak == 4){ | ||
return(true); | ||
} | ||
} | ||
} | ||
|
||
|
||
//V | ||
streak = 0; | ||
for(int i = PY-3;i <= PY + 3; i ++){ | ||
if(i >= 0 && i < y){ | ||
if(case_info[PX][i] == value){ | ||
streak += 1; | ||
}else{ | ||
streak = 0; | ||
} | ||
if(streak == 4){ | ||
return(true); | ||
} | ||
} | ||
} | ||
|
||
|
||
//D1 | ||
streak = 0; | ||
for(int i = -3;i <= 3; i ++){ | ||
if(PX+i >= 0 && PX+i < x && PY+i >= 0 && PY+i < y){ | ||
if(case_info[PX+i][PY+i] == value){ | ||
streak += 1; | ||
}else{ | ||
streak = 0; | ||
} | ||
if(streak == 4){ | ||
return(true); | ||
} | ||
} | ||
} | ||
|
||
//D2 | ||
streak = 0; | ||
for(int i = -3;i <= 3; i ++){ | ||
if(PX-i >= 0 && PX-i < x && PY+i >= 0 && PY+i < y){ | ||
if(case_info[PX-i][PY+i] == value){ | ||
streak += 1; | ||
}else{ | ||
streak = 0; | ||
} | ||
if(streak == 4){ | ||
return(true); | ||
} | ||
} | ||
} | ||
|
||
|
||
return(false); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
==================================================CONNECT 4================================================== | ||
|
||
ce programme est une réplique du jeu du puissance 4 avec un algorithme de type minimax ( https://fr.wikipedia.org/wiki/Algorithme_minimax ) | ||
|
||
rapel des règles du puissance 4 : | ||
les joueurs doivent chacun leur tour faire tomber un bille dans la grille, | ||
le premier joueur à aligner 4 billes ( en ligne , en collone ou en diagonale) a gagné. | ||
|
||
utilisation : | ||
le bouton new game permet de reset la grille | ||
le bouton PVP permet de changer le nombre de joueurs: | ||
(PVP : player vs player | ||
|PVE : player vs entity(IA) | ||
|IA ; IA vs IA ) | ||
les deux sliders permettent de changer l'intelligence des IA (l'IA 1 joue les rouge et l'IA 2 joue les verts ) | ||
niveau 0 : joue aléatoirement | ||
niveau 1 : prévoit son prochain coup puis le prochain coup de l'adversaire (2 coups) | ||
niveau 2 : prévoit ses deux prochains coups et les deux prochains coups de l'adversaire (4 coups) | ||
niveau 3 : prévoit ses trois prochains coups et les trois prochains coups de l'adversaire (6 coups) | ||
niveau 4 : prévoit ses quatre prochains coups et les quatre prochains coups de l'adversaire (8 coups) | ||
|
||
Ce programme a été réalisé en Java à l'aide processing ( https://processing.org/ ). | ||
les polices d'écriture viennent du site https://www.dafont.com/fr/ | ||
|
||
les icônes et l'intégralité du programme à été fait par Physic Gamer . | ||
merci d'indiquer que j'en suis le créateur si vous souhaitez réutiliser mon programme. | ||
|
||
=================================Physic Gamer || Connect 4 algo || brain factory©================================= |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[.ShellClassInfo] | ||
IconResource=C:\Users\utilisateur\Desktop\connect4\data\c4_1sT_icon.ico,0 | ||
[ViewState] | ||
Mode= | ||
Vid= | ||
FolderType=Generic |
Oops, something went wrong.