Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.14 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. struct piece {
  7. int pos[2];
  8. int type;
  9. bool team;
  10. };
  11.  
  12. vector<piece> pieces; //list of all pieces
  13. char typeVis[] = {' ', 'i', 'I', 'p', '+', 'Q', 'X'}; //Possible pieces
  14.  
  15. int placePiece (int pos[2], int type, bool team) { // create a chess piece
  16. piece a;
  17. a.pos[0] = pos[0];
  18. a.pos[1] = pos[1];
  19. a.type = type;
  20. a.team = team;
  21. pieces.push_back(a);
  22. return 0;
  23. }
  24.  
  25. bool isFull (int pos[2]) { //check if spot is occupied trough coords
  26. for (int i=0; i < pieces.size(); i++) {
  27. if (pieces[i].pos == pos) {
  28. return true;
  29. }
  30. }
  31. return false;
  32. }
  33.  
  34. piece wichPiece (int pos[2]) { //find piece trough coords
  35. if (isFull(pos)) {
  36. for (int i=0; i < pieces.size(); i++) {
  37. if (pieces[i].pos == pos) {
  38. return pieces[i];
  39. }
  40. }
  41. }
  42. else { //incase no piece found
  43. piece a;
  44. a.pos[0] = 99;
  45. a.pos[1] = 99;
  46. a.type = 0;
  47. a.team = false;
  48. return a;
  49. }
  50. }
  51.  
  52. int drawMap (int dim[2]) { //draw the chessboard
  53. 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
  54. char drawPiece;
  55. cout << "+ ";
  56. for (int h=0; h < dim[0]; h++) {
  57. cout << letters[h] << " ";
  58. }
  59. cout << "+" << endl;
  60. for (int i=0; i < dim[1]; i++) {
  61. cout << i+1 << " ";
  62. if (i % 2 == 0) {
  63. for (int j=0; j < dim[0]; j++) {
  64. int b[2] = {j,i};
  65. if (isFull(b)) {
  66. drawPiece = typeVis[wichPiece(b).type];
  67. //cout << typeVis[wichPiece(b).type] << endl;
  68. if (j % 2 == 0) {
  69. cout << " " << drawPiece << " ";
  70. }
  71. else {
  72. cout << "[" << drawPiece << "]";
  73. }
  74. }
  75. else {
  76. if (j % 2 == 0) {
  77. cout << " ";
  78. }
  79. else {
  80. cout << "[ ]";
  81. }
  82. }
  83. }
  84. }
  85. else {
  86. for (int j=1; j < dim[0]+1; j++) {
  87. if (j % 2 == 0) {cout << " ";}
  88. else {cout << "[ ]";}
  89. }
  90. }
  91. cout << " " << i+1 << endl;
  92. }
  93. cout << "+ ";
  94. for (int h=0; h < dim[0]; h++) {
  95. cout << letters[h] << " ";
  96. }
  97. cout << "+" << endl;
  98. cout << pieces.size() << typeVis[pieces[0].type] << endl;
  99. return 0;
  100. }
  101.  
  102. int main()
  103. {
  104. int dim[2] = {8,8}; //dimensions for checkerboard
  105. char a; // y/n answer
  106.  
  107. //cout << "33[33mbold red text33[0mn" << endl; me testing colours :p
  108. //cin >> dim[0];
  109. //cout << "Height?" << endl;
  110. //cin >> dim[1];
  111. cout << "Is [" << dim[0] << ", " << dim[1] << "] correct? <y/n>" << endl;
  112. cin >> a;
  113.  
  114. if (a == 'n') { return 0; }
  115. else {
  116. //drawMap (dim);
  117. int s[2] = {0,0};
  118. placePiece (s, 5, true);
  119. drawMap (dim);
  120. //cout << pieces[0].pos[0] << endl;
  121. }
  122. return 0;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement