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
8c8d5d58
Commit
8c8d5d58
authored
Oct 28, 2020
by
Radia EL HAMDOUNI
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added basic legal moves for pieces
parent
f32479bd
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
127 additions
and
0 deletions
+127
-0
legal_move.c
legal_move.c
+127
-0
No files found.
legal_move.c
0 → 100644
View file @
8c8d5d58
/* Move generation */
int
legal_move
(
int
sq
,
int
side
){
if
(
!
side
)
// white side
{
// moving pawns
if
(
(
sq
+
17
&
0x88
)
==
0
&&
board
[
sq
+
17
]
==
P
)
{
return
1
;
}
if
(
(
sq
+
15
&
0x88
)
==
0
&&
board
[
sq
+
15
]
==
P
)
{
return
1
;
}
}
else
{
if
(
(
sq
-
17
&
0x88
)
==
0
&&
board
[
sq
-
17
]
==
p
)
{
return
1
;
}
if
(
(
sq
-
15
&
0x88
)
==
0
&&
board
[
sq
-
15
]
==
p
)
{
return
1
;
}
}
// moving knights
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
int
target_square
=
sq
+
moves_knight
[
i
];
int
target_piece
=
board
[
target_square
];
if
(
!
(
target_square
&
0x88
))
{
if
(
!
side
?
target_piece
==
N
:
target_piece
==
n
)
return
1
;
}
}
// moving bishop
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
int
target_square
=
sq
+
moves_bishop
[
i
];
while
(
!
(
target_square
&
0x88
))
{
int
target_piece
=
board
[
target_square
];
if
(
!
side
?
(
target_piece
==
B
||
target_piece
==
Q
)
:
(
target_piece
==
b
||
target_piece
==
q
))
return
1
;
if
(
target_piece
)
break
;
target_square
+=
moves_bishop
[
i
];
}
}
// Moving king
for
(
int
i
=
0
;
i
<
8
;
i
++
)
{
int
target_square
=
sq
+
moves_king
[
i
];
int
target_piece
=
board
[
target_square
];
if
(
!
(
target_square
&
0x88
))
{
if
(
!
side
?
target_piece
==
K
:
target_piece
==
k
)
return
1
;
}
}
// moving the queen and the rook
for
(
int
i
=
0
;
i
<
4
;
i
++
)
{
int
target_square
=
sq
+
moves_rook
[
i
];
while
(
!
(
target_square
&
0x88
))
{
int
target_piece
=
board
[
target_square
];
if
(
!
side
?
(
target_piece
==
R
||
target_piece
==
Q
)
:
(
target_piece
==
r
||
target_piece
==
q
))
return
1
;
if
(
target_piece
)
break
;
target_square
+=
moves_rook
[
i
];
}
}
return
0
;
}
void
print_possible_moves
(
int
side
){
for
(
int
i
=
0
;
i
<
8
;
i
++
){
//loop over the ranks
for
(
int
j
=
0
;
j
<
16
;
j
++
){
// loop over the files
int
square
=
16
*
i
+
j
;
if
(
j
==
0
){
printf
(
"%d "
,
8
-
i
);
// print ranks
}
// print the board's valid quares
if
(
!
(
square
&
0x88
)){
printf
(
" %c "
,
legal_move
(
square
,
side
)
?
'x'
:
'.'
);
}
}
printf
(
"
\n
"
);
}
printf
(
"
\n
a b c d e f g h
\n\n\n
"
);
// print files
}
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