-
Notifications
You must be signed in to change notification settings - Fork 0
/
knight.cpp
65 lines (46 loc) · 1.27 KB
/
knight.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
57
58
59
60
//
// knight.cpp
// Cheeses
//
// Created by ButterFly on 5/15/19.
// Copyright © 2019 ButterFly. All rights reserved.
//
#include "knight.hpp"
#include "Board.h"
#include "iostream"
using namespace std;
knight::knight(){};
knight::knight(int _x,int _y,Board *_plate,string _color,string _name)
{
name = _name;
flag = 1 ;
color = _color;
plate=_plate;
x=_x;
y=_y;
plate->setIndexexistPlate(x,y);
plate->setAddressPlate(x,y,this);
plate->setCharPlate(x, y, "knight-");
plate->setColorPlate(x,y,_color);
}
bool knight::isVaildMove(int _x,int _y)
{
bool value;
int temp,xChange=0,yChange=0;
if(x>_x){ temp = _x; _x = x; x = temp;xChange=1;}
if(y>_y){ temp = _y; _y = y; y = temp;yChange=1;}
value = (x == _x-2 && y==_y-1) || (x == _x-2 && y==_y+1) || (x == _x+2 && y==_y-1) || (x == _x+2 && y==_y-1) || (x == _x+2 && y==_y-1) || (x == _x-1 && y==_y-2) || (x == _x+1 && y==_y-2) || (x == _x+1 && y==_y+2) || (x == _x-1 && y==_y+2);
if(xChange)
{ temp = _x; _x = x; x = temp;}
if(yChange)
{ temp = _y; _y = y; y = temp;}
return value;
}
knight::~knight()
{
cout << "Destroying Object\n" << endl;
}
bool knight::isNoPieceThereInPath(int _x,int _y)
{
return true;
}