-
Notifications
You must be signed in to change notification settings - Fork 0
/
movement.cpp
57 lines (45 loc) · 967 Bytes
/
movement.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "movement.h"
#include "pieces.h"
#include <ctype.h>
pieces pi;
void movement::convert(int x,int &a,int &b){
a=x/10;
b=x%10;
}
void movement::clearPos(int x){
int m,n;
convert(x,m,n);
board[m][n]=' ';
}
bool movement::checkGoPos(int x){
int a,b;
convert(x,a,b);
if(board[a][b]==' ')
return true;
else
return false;
}
bool movement::moveIt(int in,int out){
int thA,thB,inA,inB;
convert(out,thA,thB); convert(in,inA,inB);
char pi=board[inA][inB];
if(/*checkGoPos(out) &&*/checkIt(pi,in,out)){
clearPos(in);
board[thA][thB]=pi;
return true;
}
return false;
}
bool movement::checkIt(char x,int from,int to){
bool yn;
char y = tolower(x);
switch(y){
case 'k': yn = pi.king(from,to);break;
case 'q': yn = pi.queen(from,to);break;
case 'b': yn = pi.bishop(from,to);break;
case 'n': yn = pi.knight(from,to);break;
case 'r': yn = pi.rook(from,to);break;
case 'p': yn = pi.pawn(from,to);break;
}
return yn;
}