Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- struct piece {
- int pos[2];
- int type;
- bool team;
- };
- vector<piece> pieces; //list of all pieces
- char typeVis[] = {' ', 'i', 'I', 'p', '+', 'Q', 'X'}; //Possible pieces
- int placePiece (int pos[2], int type, bool team) { // create a chess piece
- piece a;
- a.pos[0] = pos[0];
- a.pos[1] = pos[1];
- a.type = type;
- a.team = team;
- pieces.push_back(a);
- return 0;
- }
- bool isFull (int pos[2]) { //check if spot is occupied trough coords
- for (int i=0; i < pieces.size(); i++) {
- if (pieces[i].pos == pos) {
- return true;
- }
- }
- return false;
- }
- piece wichPiece (int pos[2]) { //find piece trough coords
- if (isFull(pos)) {
- for (int i=0; i < pieces.size(); i++) {
- if (pieces[i].pos == pos) {
- return pieces[i];
- }
- }
- }
- else { //incase no piece found
- piece a;
- a.pos[0] = 99;
- a.pos[1] = 99;
- a.type = 0;
- a.team = false;
- return a;
- }
- }
- int drawMap (int dim[2]) { //draw the chessboard
- char letters[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}; //border letters
- char drawPiece;
- cout << "+ ";
- for (int h=0; h < dim[0]; h++) {
- cout << letters[h] << " ";
- }
- cout << "+" << endl;
- for (int i=0; i < dim[1]; i++) {
- cout << i+1 << " ";
- if (i % 2 == 0) {
- for (int j=0; j < dim[0]; j++) {
- int b[2] = {j,i};
- if (isFull(b)) {
- drawPiece = typeVis[wichPiece(b).type];
- //cout << typeVis[wichPiece(b).type] << endl;
- if (j % 2 == 0) {
- cout << " " << drawPiece << " ";
- }
- else {
- cout << "[" << drawPiece << "]";
- }
- }
- else {
- if (j % 2 == 0) {
- cout << " ";
- }
- else {
- cout << "[ ]";
- }
- }
- }
- }
- else {
- for (int j=1; j < dim[0]+1; j++) {
- if (j % 2 == 0) {cout << " ";}
- else {cout << "[ ]";}
- }
- }
- cout << " " << i+1 << endl;
- }
- cout << "+ ";
- for (int h=0; h < dim[0]; h++) {
- cout << letters[h] << " ";
- }
- cout << "+" << endl;
- cout << pieces.size() << typeVis[pieces[0].type] << endl;
- return 0;
- }
- int main()
- {
- int dim[2] = {8,8}; //dimensions for checkerboard
- char a; // y/n answer
- //cout << "