Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tic_tac_toe_mini_max
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
prog-sequencielle
tic_tac_toe_mini_max
Commits
a00744ca
Commit
a00744ca
authored
3 years ago
by
zabiulla.ahmadi
Browse files
Options
Downloads
Patches
Plain Diff
Revert "alpha beta pruning"
This reverts commit
df33147b
.
parent
df33147b
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
play/play.c
+29
-80
29 additions, 80 deletions
play/play.c
play/play.h
+1
-1
1 addition, 1 deletion
play/play.h
with
30 additions
and
81 deletions
play/play.c
+
29
−
80
View file @
a00744ca
...
...
@@ -300,16 +300,16 @@ int max(int a, int b)
return
(
a
>
b
)
?
a
:
b
;
}
int
mini_max
(
board
brd
,
bool
is_max
,
int
depth
,
int
*
alpha
,
int
*
beta
)
int
mini_max
(
board
brd
,
bool
is_max
,
int
depth
)
{
//
if (brd->row >= 4)
//
{
//
if (depth >=
10
)
//
{
//
return 0;
//
}
//
}
if
(
brd
->
row
>=
4
)
{
if
(
depth
>=
7
)
{
return
0
;
}
}
int
score
=
evaluate
(
brd
);
...
...
@@ -339,26 +339,9 @@ int mini_max(board brd, bool is_max, int depth, int *alpha, int *beta)
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
PC
);
// calculate score of this move
// best_score = max(best_score, mini_max(brd, false, depth + 1, alpha, beta));
best_score
=
mini_max
(
brd
,
!
is_max
,
depth
+
1
,
alpha
,
beta
);
best_score
=
max
(
best_score
,
mini_max
(
brd
,
false
,
depth
+
1
));
// undo move
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
char
)
0
);
// alpha Pruning
if
(
best_score
>=
*
beta
)
{
i
=
brd
->
row
;
j
=
brd
->
col
;
}
*
alpha
=
max
(
*
alpha
,
best_score
);
// *alpha = max(*alpha, best_score);
// if (*alpha >= *beta)
// {
// // custom break;
// // i = brd->row;
// j = brd->col;
// }
}
}
}
...
...
@@ -378,26 +361,11 @@ int mini_max(board brd, bool is_max, int depth, int *alpha, int *beta)
// make a move
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
PLAYER
);
// best_score = min(best_score, mini_max(brd, true, depth + 1, alpha, beta));
best_score
=
mini_max
(
brd
,
!
is_max
,
depth
+
1
,
alpha
,
beta
);
// calculate score of this move
best_score
=
min
(
best_score
,
mini_max
(
brd
,
true
,
depth
+
1
));
// undo move
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
char
)
0
);
if
(
best_score
<=
*
alpha
)
{
i
=
brd
->
row
;
j
=
brd
->
col
;
}
*
beta
=
min
(
*
beta
,
best_score
);
// beta cut-of Pruning
// *beta = min(*beta, best_score);
// if (*alpha >= *beta)
// {
// // custom break;
// // i = brd->row;
// j = brd->col;
// }
}
}
}
...
...
@@ -441,9 +409,6 @@ void best_move(board brd)
bst_move
.
row
=
-
1
;
bst_move
.
col
=
-
1
;
int
alpha
=
_MIN_INF_
;
int
beta
=
_MAX_INF_
;
// for available case add and undo -> to see best score
for
(
int
i
=
0
;
i
<
brd
->
row
;
i
++
)
{
...
...
@@ -456,8 +421,8 @@ void best_move(board brd)
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
PC
);
// find max score
int
score
=
mini_max
(
brd
,
false
,
0
,
&
alpha
,
&
beta
);
printf
(
"row: %d col: %d score :
%d , alpha %d, beta
%d
\n
"
,
i
,
j
,
score
,
alpha
,
beta
);
int
score
=
mini_max
(
brd
,
false
,
0
);
printf
(
"row: %d col: %d score : %d
\n
"
,
i
,
j
,
score
);
// undo move
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
char
)
0
);
// find the case with max probab
...
...
@@ -719,19 +684,21 @@ void player_vs_smart_ai_mini_max_player_start(board brd)
}
}
int
min_max_double
(
board
brd
,
bool
is_max
,
int
depth
,
bool
turn
,
int
*
alpha
,
int
*
beta
)
int
min_max_double
(
board
brd
,
bool
is_max
,
int
depth
,
bool
turn
)
{
//
if (brd->row >= 4)
//
{
//
if (depth > 8)
//
{
//
return 0;
//
}
//
}
if
(
brd
->
row
>=
4
)
{
if
(
depth
>
8
)
{
return
0
;
}
}
int
score
=
evaluate
(
brd
);
// if the board is full
// if maximizer has won
if
(
score
==
1
)
return
score
*
(
remaining_case
(
brd
)
+
1
);
...
...
@@ -756,18 +723,9 @@ int min_max_double(board brd, bool is_max, int depth, bool turn, int *alpha, int
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
turn
)
?
PC
:
PLAYER
);
// calculate score of this move
// best_score = max(best_score, min_max_double(brd, false, depth + 1, turn, alpha, beta));
best_score
=
mini_max
(
brd
,
true
,
depth
+
1
,
alpha
,
beta
);
best_score
=
max
(
best_score
,
mini_max
(
brd
,
false
,
depth
+
1
));
// undo move
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
char
)
0
);
// alpha Pruning
*
alpha
=
max
(
*
alpha
,
best_score
);
if
(
*
alpha
<=
*
beta
)
{
i
=
brd
->
row
;
j
=
brd
->
col
;
}
}
}
}
...
...
@@ -788,18 +746,12 @@ int min_max_double(board brd, bool is_max, int depth, bool turn, int *alpha, int
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
turn
)
?
PC
:
PLAYER
);
// calculate score of this move
//
best_score = min(best_score, min_max
_double
(brd, true, depth + 1
, turn, alpha, beta
));
best_score
=
mini_max
(
brd
,
true
,
depth
+
1
,
alpha
,
beta
);
best_score
=
min
(
best_score
,
min
i
_max
(
brd
,
true
,
depth
+
1
));
// undo move
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
char
)
0
);
// beta Pruning
*
beta
=
min
(
*
beta
,
best_score
);
if
(
*
beta
<=
*
alpha
)
{
i
=
brd
->
row
;
j
=
brd
->
col
;
}
// min(score, best_score_score);
}
}
}
...
...
@@ -814,9 +766,6 @@ void best_move_o(board brd, bool turn)
bst_move
.
row
=
-
1
;
bst_move
.
col
=
-
1
;
int
alpha
=
_MIN_INF_
;
int
beta
=
_MAX_INF_
;
// for available case add and undo -> to see best score
for
(
int
i
=
0
;
i
<
brd
->
row
;
i
++
)
{
...
...
@@ -829,7 +778,7 @@ void best_move_o(board brd, bool turn)
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
turn
)
?
PC
:
PLAYER
);
// find max score
int
score
=
min_max_double
(
brd
,
false
,
0
,
turn
,
&
alpha
,
&
beta
);
int
score
=
min_max_double
(
brd
,
false
,
0
,
turn
);
printf
(
"row: %d col: %d score : %d
\n
"
,
i
,
j
,
score
);
// undo move
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
char
)
0
);
...
...
This diff is collapsed.
Click to expand it.
play/play.h
+
1
−
1
View file @
a00744ca
...
...
@@ -31,7 +31,7 @@ int check_win(board brd);
bool
case_is_available
(
char
chr
);
void
case_to_coordinates
(
board
brd
,
int
cas
,
int
*
i
,
int
*
j
);
bool
board_is_full
(
board
brd
);
int
mini_max
(
board
brd
,
bool
is_max
,
int
depth
,
int
*
alpha
,
int
*
beta
);
int
mini_max
(
board
brd
,
bool
is_max
,
int
depth
);
void
best_move
(
board
brd
);
void
two_player
(
board
brd
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment