-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcell.cpp
84 lines (73 loc) · 1.87 KB
/
cell.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "piece.h"
#include "cell.h"
#include "playerEnum.h"
#include "config.h"
#include "statusEnum.h"
#include <iostream>
Cell::Cell() {
this->index = -1;
}
Cell::Cell(const Cell& other) {
std::copy(std::begin(other.stack), std::end(other.stack), std::begin(this->stack));
this->index = other.index;
}
bool Cell::canPush(const Piece &piece) {
if (piece.getSize() == NONE) {
return false; //On ne peut pas ajouter une pièce sans taille
}
else if (this->index == -1) {
return true; //Aucune pièce n'est présente
}
else if (piece.getSize() == SMALL) {
if (this->stack[this->index].getSize() == NONE ) {
return true;
}
else {return false;}
}
else if (piece.getSize() == MEDIUM) {
if (this->stack[this->index].getSize() == NONE || this->stack[this->index].getSize() == SMALL ) {
return true;
}
else {return false;}
}
else if (piece.getSize() == LARGE) {
if (this->stack[this->index].getSize() != LARGE ) {
return true;
}
else {return false;}
}
}
void Cell::push(const Piece& piece) {
this->index ++;
this->stack[this->index] = piece;
}
bool Cell::canPop() {
if (this->index == -1) {
return false;
}
else {
return true;
}
}
Piece& Cell::pop() {
Piece* pt;
Piece piece = Piece(this->stack[this->index]);
pt = &(piece);
Piece empty_piece = Piece();
this->stack[this->index] = empty_piece;
this->index --;
return *pt;
}
Piece& Cell::peek(){
if (this->index == -1 ) {
return this->stack[this->index+1 ];
}
else {
return this->stack[this->index];
}
}
Cell& Cell::operator=(const Cell& other){
std::copy(std::begin(other.stack), std::end(other.stack), std::begin(this->stack));
this->index = other.index;
return *this;
}