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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
prog-sequencielle
tic_tac_toe_mini_max
Commits
3f995732
Commit
3f995732
authored
3 years ago
by
zabiulla.ahmadi
Browse files
Options
Downloads
Patches
Plain Diff
min_max changed to mini_max
parent
96eeeb95
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
+10
-9
10 additions, 9 deletions
play/play.c
play/play.h
+1
-1
1 addition, 1 deletion
play/play.h
with
11 additions
and
10 deletions
play/play.c
+
10
−
9
View file @
3f995732
...
...
@@ -263,6 +263,7 @@ bool board_is_full(board brd)
{
for
(
int
j
=
0
;
j
<
brd
->
col
;
j
++
)
{
// if at least one case is empty then the board is not full
if
(
case_is_available
(
brd
->
matrix
[
i
][
j
]))
{
return
false
;
...
...
@@ -279,6 +280,7 @@ int remaining_case(board brd)
{
for
(
int
j
=
0
;
j
<
brd
->
col
;
j
++
)
{
// count each empty case in the board
if
(
case_is_available
(
brd
->
matrix
[
i
][
j
]))
{
count
++
;
...
...
@@ -297,12 +299,13 @@ int max(int a, int b)
{
return
(
a
>
b
)
?
a
:
b
;
}
int
min_max
(
board
brd
,
bool
is_max
,
int
depth
)
int
mini_max
(
board
brd
,
bool
is_max
,
int
depth
)
{
if
(
brd
->
row
>=
4
)
{
if
(
depth
>
8
)
if
(
depth
>
=
7
)
{
return
0
;
}
...
...
@@ -336,7 +339,7 @@ int min_max(board brd, bool is_max, int depth)
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
PC
);
// calculate score of this move
best_score
=
max
(
best_score
,
min_max
(
brd
,
false
,
depth
+
1
));
best_score
=
max
(
best_score
,
min
i
_max
(
brd
,
false
,
depth
+
1
));
// undo move
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
char
)
0
);
}
...
...
@@ -359,12 +362,10 @@ int min_max(board brd, bool is_max, int depth)
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
PLAYER
);
// calculate score of this move
best_score
=
min
(
best_score
,
min_max
(
brd
,
true
,
depth
+
1
));
best_score
=
min
(
best_score
,
min
i
_max
(
brd
,
true
,
depth
+
1
));
// undo move
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
char
)
0
);
// min(score, best_score_score);
}
}
}
...
...
@@ -420,7 +421,7 @@ void best_move(board brd)
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
PC
);
// find max score
int
score
=
min_max
(
brd
,
false
,
0
);
int
score
=
min
i
_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
);
...
...
@@ -722,7 +723,7 @@ int min_max_double(board brd, bool is_max, int depth, bool turn)
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
turn
)
?
PC
:
PLAYER
);
// calculate score of this move
best_score
=
max
(
best_score
,
min_max
(
brd
,
false
,
depth
+
1
));
best_score
=
max
(
best_score
,
min
i
_max
(
brd
,
false
,
depth
+
1
));
// undo move
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
char
)
0
);
}
...
...
@@ -745,7 +746,7 @@ int min_max_double(board brd, bool is_max, int depth, bool turn)
add_to_board
(
brd
,
i
+
1
,
j
+
1
,
(
turn
)
?
PC
:
PLAYER
);
// calculate score of this move
best_score
=
min
(
best_score
,
min_max
(
brd
,
true
,
depth
+
1
));
best_score
=
min
(
best_score
,
min
i
_max
(
brd
,
true
,
depth
+
1
));
// 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 @
3f995732
...
...
@@ -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
min_max
(
board
brd
,
bool
is_max
,
int
depth
);
int
min
i
_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