Commit fd2dbde5 authored by Radia EL HAMDOUNI's avatar Radia EL HAMDOUNI

Update chess_engine.c

parent ab34bfc8
/* --------------------------------------------------------- (^')ފpjx.j
============================================================ \ No newline at end of file
Chess Engine in C Language
==========================
8 |_|#|_|#|_|#|_|#|
7 |#|_|#|_|#|_|#|_|
6 |_|#|_|#|_|#|_|#|
5 |#|_|#|_|#|_|#|_|
4 |_|#|_|#|_|#|_|#|
3 |#|_|#|_|#|_|#|_|
2 |_|#|_|#|_|#|_|#|
1 |#|_|#|_|#|_|#|_|
a b c d e f g h
-----------------------------------------------------------
BY
Radia EL HAMDOUNI
MLOD - Mini-Projet
,....,
,::::::<
,::/^\"``.
,::/, ` e`.
,::; | '.
,::| \___,-. c)
;::| \ '-'
;::| \
;::| _.=`\
`;:|.=` _.=`\
'|_.=` __\
`\_..==`` /
.'.___.-'.
/ \
('--......--')
/'--......--'\
`"--......--"
====================================================
---------------------------------------------------*/
/*
Compile and run the program
$gcc chess_engine.c -o chess_engine && ./chess_engine
*/
// Libraries
#include<stdio.h>
// Upper Case letters => White pieces .
// Lower Case letters => Black pieces .
// for the mapping
enum{
e, // empty square
P, // white pond
N, // white knight
B, // white bishop
R, // white rook
Q, // white queen
K, // white king
p, // black pond
n, // black knight
b, // black bishop
r, // black rook
q, // black queen
k, // black king
o, // board limit
};
// unicode pieces
char* chess_pieces[] = {" . "," ♙ "," ♘ "," ♗ "," ♖ "," ♕ "," ♔ "," ♟︎ "," ♞ "," ♝ "," ♜ "," ♛ "," ♚ "};
// chess board representation 0x88
int board[128] = {
r , n , b , q , k , b , n , r , o , o , o , o , o , o , o , o ,
p , p , p , p , p , p , p , p , o , o , o , o , o , o , o , o ,
e , e , e , e , e , e , e , e , o , o , o , o , o , o , o , o ,
e , e , e , e , e , e , e , e , o , o , o , o , o , o , o , o ,
e , e , e , e , e , e , e , e , o , o , o , o , o , o , o , o ,
e , e , e , e , e , e , e , e , o , o , o , o , o , o , o , o ,
P , P , P , P , P , P , P , P , o , o , o , o , o , o , o , o ,
R , N , B , Q , K , B , N , R , o , o , o , o , o , o , o , o ,
};
// Print the board to the console
void show_board(){
// pint new line
printf("\n\n\n");
// A rank is a line
// A file is a column
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("%s" ,chess_pieces[board[square]]);
}
}
printf("\n");
}
printf("\n a b c d e f g h \n\n\n"); // print files
}
// Main
int main(){
show_board();
return 1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment