Created
April 19, 2017 00:13
-
-
Save ahmetilgin/9b63d9613204656d321eacb9d58c6c83 to your computer and use it in GitHub Desktop.
Find the Knight Moves in chess
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#define gercekTahtaBoyu 12 | |
#define fazlalik 4 | |
#define sinirX 1 | |
#define sinirY 10 | |
void printTable(char **x); | |
void tahtayiSifirla(char **x); | |
void kullanicidanKoordinatAl(int *x,int *y); | |
void tahtayaAtiYerlestir(char **x, int a , int b); | |
void atinGidebilecegiYerleriBelirle(char **x,int atPosX, int atPosY); | |
int main() | |
{ | |
char **tahta; | |
int atPosX; | |
int atPosY; | |
int i =0; | |
// Burda bellekte yer ayırtılıyor tek boyutlu char için 12*12 adet | |
tahta=(char **)malloc(gercekTahtaBoyu*sizeof(char *)); | |
for (i=0;i<gercekTahtaBoyu;i++) | |
{ | |
// ilk boyuttaki 8 liye bağlı 8 er eleman daha ayrıldı | |
tahta[i]=(char*)malloc(gercekTahtaBoyu*sizeof(char)); | |
} | |
kullanicidanKoordinatAl(&atPosX,&atPosY); | |
tahtayiSifirla(tahta); | |
tahtayaAtiYerlestir(tahta,atPosX,atPosY); | |
atinGidebilecegiYerleriBelirle(tahta,atPosX,atPosY); | |
printTable(tahta); | |
return 0; | |
} | |
void tahtayiSifirla(char **x){ | |
int i =0 ,j; | |
for(i = 0; i < 12; i++){ | |
for(j = 0; j < 12; j++){ | |
x[i][j] = 'x'; | |
} | |
} | |
printf("Tahta Sifirlandi..\n"); | |
} | |
void printTable(char **x){ | |
int i = 0,j=0; | |
for(i = 2; i <= 9;i++){ | |
for (j = 2; j <= 9; j++) | |
{ | |
printf("%c ",x[i][j]); | |
} | |
printf("\n"); | |
} | |
} | |
void kullanicidanKoordinatAl(int *x,int *y){ | |
printf("Lütfen Atin bulunduğu koordinatları giriniz.\n"); | |
int a,b; | |
scanf("%d %d",&a,&b); | |
*x = a+2; | |
*y = b+2; | |
printf("Atin bulunduğu koordinat %d %d", *x,*y); | |
} | |
void tahtayaAtiYerlestir(char **x,int a , int b){ | |
x[a][b] = 'K'; | |
} | |
void atinGidebilecegiYerleriBelirle(char **x, int atPosX,int atPosY){ | |
int i,j; | |
int maske[5][5]={ | |
{0,1,0,1,0}, | |
{1,0,0,0,1}, | |
{0,0,2,0,0}, | |
{1,0,0,0,1}, | |
{0,1,0,1,0} | |
}; | |
//for(i = atPosX - 2; i < atPosX + 3; i++ ){ | |
// for(j = atPosY - 2; j < atPosY + 3; j++){ | |
// printf("%c ",x[i][j]); | |
// } | |
// printf("\n"); | |
//} | |
int a = 0, b = 0; | |
for(i = atPosX - 2; i <atPosX + 3; i++ ){ | |
for(j = atPosY - 2; j < atPosY + 3; j++){ | |
if(maske[a][b]==1){ | |
x[i][j] = 'o'; | |
} | |
b++; | |
} | |
b = 0; | |
a++; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment