-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEtatPlateau.cpp
More file actions
50 lines (46 loc) · 1.43 KB
/
EtatPlateau.cpp
File metadata and controls
50 lines (46 loc) · 1.43 KB
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
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <cstdlib>
#include <iomanip>
using namespace std;
typedef vector<vector<int> > Plateau;
#include "Jeu2048.h"
bool estTermine(Plateau plateau){
for(int i = 0; i < plateau.size(); i++){
for(int j = 0; j < plateau[i].size(); j++){
if(plateau[i][j] == 0){
return false;
}
if(j <= 2 and plateau[i][j] == plateau[i][j+1]){
return false;
}
if(i <= 2 and plateau[i][j] == plateau[i+1][j]){
return false;
}
}
} return true;
}
bool estGagnant(Plateau plateau){
for (int i = 0; i < plateau.size(); i++){
for (int j = 0; j < plateau.size(); j++){
if(plateau[i][j] == 2048){
return true;
}
}
} return false;
}
string dessine(Plateau plateau){
stringstream ligne;
for(int i = 0; i < plateau.size(); i++){
for(int j = 0; j < plateau[i].size(); j++){
if(j < plateau[i].size()-1){
ligne << setw(4) << "*" << setw(4) << plateau[i][j];
} else if (j == plateau[i].size()-1){
ligne << setw(4) << "*" << setw(4) << plateau[i][j] << setw(4) << "*" << endl << "\n *********************************\n";
}
}
}
return "\n *********************************\n" + ligne.str();
}