-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodeAnglais.txt
42 lines (41 loc) · 2.01 KB
/
CodeAnglais.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
struct Position {
int cells_player[12]; // each cell contains a certain number of seeds
int cells_computer[12];
bool computer_play; // boolean true if the computer has to play and false otherwise
int seeds_player; // seeds taken by the player
int seeds_computer; // seeds taken by the computer
};
int minMaxValue(Position* pos_current, computer_play, depth, depthMax){
// computer_play is true if the computer has to play and false otherwise
int tab_values[12];
Position pos_next; // In C : created on the stack: = very fast
if (finalPosition(pos_current, computer_play, depth)){
// WRITE the code: returns VALMAX (=96) if the computer wins, -96 if it loses; 0 if draw
}
if (depth == depthMax) {
return evaluation(pos_current, computer_play, depth);
// the simplest evealution fucntion is the difference of the taken seeds
}
for(int i=0;i<12;i++){
// we play the move i
// WRITE function validMove(pos_current, computer_play,i)
// it checks whether we can select the seeds in cell i and play (if there is no seed the function returns false)
if (validMove(pos_current, computer_play,i)){
// WRITE function playMove(&pos_next,pos_current, computer_play,i)
// we play the move i from pos_current and obtain the new position pos_next
playMove(&pos_next,pos_current, computer_play,i);
// pos_next is the new current poisition and we change the player
tab_values[i]=minMaxValue(&pos_next,!computer_play,depth+1,depthMax);
} else {
if (computer_play) tab_values[i]=-100.
else tab_values[i]=+100;
}
}
int res;
if (computer_play){
// WRITE the code: res contains the MAX of tab_values
} else {
// WRITE the code: res contains the MIN of tab_values
}
return res;
}