Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
chess_programming
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Radia EL HAMDOUNI
chess_programming
Commits
0b3b7479
Commit
0b3b7479
authored
Oct 30, 2020
by
Radia EL HAMDOUNI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added play_chess.c
parent
62ec320e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
play_chess.c
play_chess.c
+61
-0
No files found.
play_chess.c
0 → 100644
View file @
0b3b7479
void
play_chess
(){
// storing user input (format: e2e4, queening is automatical)
int
side
=
WHITE
;
// user starts first with the color white
char
move
[
5
];
show_board
();
while
(
1
)
{
memset
(
&
move
[
0
],
0
,
sizeof
(
move
));
if
(
!
fgets
(
move
,
5
,
stdin
))
continue
;
if
(
move
[
0
]
==
'\n'
)
continue
;
for
(
int
square
=
0
;
square
<
128
;
square
++
)
// loop over board squares
{
if
(
!
(
square
&
0x88
))
// if square is onboard
{
if
(
!
strncmp
(
move
,
algebraic_board
[
square
],
2
))
source
=
square
;
if
(
!
strncmp
(
move
+
2
,
algebraic_board
[
square
],
2
))
destination
=
square
;
}
}
// make user move
board
[
destination
]
=
board
[
source
];
board
[
source
]
=
0
;
// if pawn promotion
if
(((
board
[
destination
]
==
9
)
&&
(
destination
>=
0
&&
destination
<=
7
))
||
((
board
[
destination
]
==
18
)
&&
(
destination
>=
112
&&
destination
<=
119
)))
board
[
destination
]
|=
7
;
show_board
();
side
=
24
-
side
;
// change side
int
score
=
alpha_beta_search
(
side
,
depth
,
-
10000
,
10000
);
// make AI move
board
[
best_dst
]
=
board
[
best_src
];
board
[
best_src
]
=
0
;
// if pawn promotion
if
(((
board
[
best_dst
]
==
9
)
&&
(
best_dst
>=
0
&&
best_dst
<=
7
))
||
((
board
[
best_dst
]
==
18
)
&&
(
best_dst
>=
112
&&
best_dst
<=
119
)))
board
[
best_dst
]
|=
7
;
side
=
24
-
side
;
show_board
();
if
(
score
==
10000
||
score
==
-
10000
)
{
printf
(
"Checkmate!
\n
"
);
break
;}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment