aboutsummaryrefslogtreecommitdiffstats
path: root/src/chess_piece.cpp
blob: 44dfaa5f0fb23d29ca77f91db115d73a10f36cca (plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "../include/chess_ai.hpp"

chess_ai::chess_piece::chess_piece(piece_type type, piece_colour colour) :
    type(type), colour(colour) {
    if(colour == black) {
        y = 0;
    } else {
        y = 7;
    }
    
    if(type == king) {
        x = 4;
    } else {
        x = 3;
    }
}

chess_ai::chess_piece::chess_piece(
                                   piece_type type,
                                   piece_colour colour,
                                   unsigned x,
                                   unsigned y
                                   ) : type(type), colour(colour), x(x), y(y) {}

void chess_ai::chess_piece::set_type(piece_type type) {
    this->type = type;
}

void chess_ai::chess_piece::set_colour(piece_colour colour) {
    this->colour = colour;
}

void chess_ai::chess_piece::set_x(unsigned x) {
    this->x = x;
}

void chess_ai::chess_piece::set_y(unsigned y) {
    this->y = y;
}

void chess_ai::chess_piece::set(piece_type type, piece_colour colour,
                                unsigned x, unsigned y) {
    set_type(type);
    set_colour(colour);
    set_x(x);
    set_y(y);
}

chess_ai::chess_piece& chess_ai::chess_piece::operator==(const chess_piece&
                                                         piece) {
    if(this != &piece) {
        this->set(piece.type, piece.colour, piece.x, piece.y);
    }
    return *this;
}

chess_ai::chess_piece& chess_ai::chess_piece::operator++() {
    if(type == pawn) {
        if(colour == white)
            --y;
        else
            ++y;
    }
    return *this;
}

chess_ai::chess_piece chess_ai::chess_piece::operator++(int) {
    chess_piece tmp(*this);
    operator++();
    return tmp;
}

std::string chess_ai::chess_piece::str() {
    if(type == empty)
        return " ";
    else if(type == pawn)
        return "p";
    else if(type == rook)
        return "r";
    else if(type == knight)
        return "n";
    else if(type == bishop)
        return "b";
    else if(type == queen)
        return "q";
    return "k";
}