Advertisement
Guest User

Untitled

a guest
May 27th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.01 KB | None | 0 0
  1. // WARCY.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <stdlib.h>
  7. using namespace std;
  8.  
  9. int flaga;
  10. int flaga_bot;
  11. class plansza {
  12.  
  13. public:
  14. int zaslonx, zaslony;
  15. int poglad[9][9];
  16. int gra[9][9];
  17. void resetuj() {
  18. int c = 1;
  19. for (int i = 0;i < 8;i++) {
  20. for (int j = 0; j < 8;j++) {
  21. if((i+j)%2==0){
  22. poglad[j][i] = c;
  23. c++;
  24. if (i < 3) {
  25. gra[j][i] = 1;
  26. }
  27. if (i > 4) {
  28. gra[j][i] = 2;
  29. }
  30. if (i == 3 || i == 4) {
  31. gra[j][i] = 0;
  32. }
  33. }
  34. else {
  35. poglad[j][i] = 0;
  36. gra[j][i] = 0;
  37. }
  38. }
  39. }
  40. }
  41. void wyswietl(){
  42.  
  43. cout << "plansza" << endl;
  44. for (int i = 0;i < 8;i++) {
  45. for (int j = 0; j < 8; j++) {
  46. cout << gra[j][i] << " ";
  47. }cout << endl;
  48. }
  49. cout << "poglad, liczby" << endl;
  50. for (int i = 0;i < 8;i++) {
  51. for (int j = 0; j < 8; j++) {
  52. if (poglad[j][i] < 10) {
  53. cout << poglad[j][i] << " ";
  54. }
  55. else{
  56. cout << poglad[j][i] << " ";
  57. }
  58. }cout << endl;
  59. }
  60. }
  61. void przestaw(int i, int j) {
  62. int s;
  63. s = j - i;
  64. int x1, x2, y1, y2;
  65. for (int x = 0;x < 8;x++) {
  66. for (int y = 0;y < 8;y++) {
  67. if (poglad[y][x] == i) {
  68. x1 = x;
  69. y1 = y;
  70. }
  71. if (poglad[y][x] == j) {
  72. x2 = x;
  73. y2 = y;
  74. }
  75. }
  76. }
  77. if (((gra[y1][x1] == 1 || gra[y1][x1]==3 )&& s < 0) || gra[y1][x1] == 0 || gra[y2][x2]!=0 || abs(x1-x2)>1 || abs(y2-y1)>1) {
  78. cout << endl << "niedozwolony ruch" << endl;
  79. }
  80. else {
  81. swap(gra[y1][x1], gra[y2][x2]);
  82. flaga = 1;
  83. }
  84. }
  85. bool czybic() {
  86. for (int x = 0;x < 8;x++) {
  87. for (int y = 0;y < 8;y++) {
  88. if ((gra[y][x] == 1 || gra[y][x]==3) && (((gra[y - 1][x - 1] == 2 || gra[y - 1][x - 1] == 4) && gra[y - 2][x - 2] == 0) || ((gra[y - 1][x + 1] == 2 || gra[y - 1][x + 1] == 4) && gra[y - 2][x + 2] == 0) || ((gra[y + 1][x - 1] == 2 || gra[y + 1][x - 1] == 4)&& gra[y + 2][x - 2]==0) || ((gra[y + 1][x + 1] == 2 || gra[y + 1][x + 1] == 4) && gra[y + 2][x + 2]==0))){
  89. zaslonx = x;
  90. zaslonx = y;
  91. return true;
  92. }
  93. }
  94. }return false;
  95. }
  96. void bicie(int i, int j) {
  97. int s;
  98. s = j - i;
  99. int x1, x2,x3, y1, y2, y3;
  100. for (int x = 0;x < 8;x++) {
  101. for (int y = 0;y < 8;y++) {
  102. if (poglad[y][x] == i) {
  103. x1 = x;
  104. y1 = y;
  105. }
  106. if (poglad[y][x] == j) {
  107. x2 = x;
  108. y2 = y;
  109. }
  110. }
  111. }
  112. x3 = (x2 + x1) / 2;
  113. y3 = (y2 + y1) / 2;
  114. if ((gra[y1][x1] != 1 && gra[y1][x1] !=3) || gra[y2][x2]!=0 || (gra[y3][x3]!=2 && gra[y3][x3]!=4)) {
  115. cout << endl << "niedozwolony ruch bicia" << endl;
  116. }
  117. else {
  118. gra[y3][x3] = 0;
  119. swap(gra[y1][x1], gra[y2][x2]);
  120. flaga = 1;
  121. }
  122. }
  123. void zamiana() {
  124. for (int y = 0;y < 8;y++) {
  125. if (gra[y][0] == 2) {
  126. gra[y][0] = 4;
  127. }
  128. if (gra[y][7] == 1) {
  129. gra[y][7] = 3;
  130. }
  131. }
  132. }
  133. };
  134. class przeciwnik {
  135. public:
  136. bool zaslon(plansza *p) {
  137. if (p->czybic()) {
  138. for (int x = 0;x < 8;x++) {
  139. for (int y = 0;y < 8;y++) {
  140. if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) && p->gra[y + 1][x - 1] == 0)
  141. {
  142. swap(p->gra[y][x], p->gra[y + 1][x - 1]);
  143. if (!p->czybic()) {
  144. return true;
  145. }
  146. else {
  147. swap(p->gra[y][x], p->gra[y + 1][x - 1]);
  148. }
  149. }
  150. if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) && p->gra[y - 1][x - 1] == 0)
  151. {
  152. swap(p->gra[y][x], p->gra[y - 1][x - 1]);
  153. if (!p->czybic()) {
  154. return true;
  155. }
  156. else {
  157. swap(p->gra[y][x], p->gra[y - 1][x - 1]);
  158. }
  159. }
  160. }
  161. }return false;
  162. }return false;
  163. }
  164. bool ruszaj(plansza *p) {
  165. for (int x = 0;x < 8;x++) {
  166. for (int y = 0;y < 8;y++) {
  167. if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) && p->gra[y + 1][x - 1] == 0 )
  168. {
  169. swap(p->gra[y][x], p->gra[y + 1][x - 1]);
  170. if (!p->czybic()) {
  171. return true;
  172. }
  173. else {
  174. swap(p->gra[y][x], p->gra[y + 1][x - 1]);
  175. }
  176. }
  177. if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) && p->gra[y - 1][x - 1] == 0)
  178. {
  179. swap(p->gra[y][x], p->gra[y - 1][x - 1]);
  180. if (!p->czybic()) {
  181. return true;
  182. }
  183. else {
  184. swap(p->gra[y][x], p->gra[y - 1][x - 1]);
  185. }
  186. }
  187. }
  188. }return false;
  189. }
  190. bool ruszaj2(plansza *p) {
  191. for (int x = 0;x < 8;x++) {
  192. for (int y = 0;y < 8;y++) {
  193. if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) && p->gra[y + 1][x - 1] == 0 )
  194. {
  195. swap(p->gra[y][x], p->gra[y + 1][x - 1]);
  196. return true;
  197. }
  198. if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) && p->gra[y - 1][x - 1] == 0 )
  199. {
  200. swap(p->gra[y][x], p->gra[y - 1][x - 1]);
  201. return true;
  202. }
  203. }
  204. }return false;
  205. }
  206. bool czybic(plansza *p) {
  207. for (int x = 0;x < 8;x++) {
  208. for (int y = 0;y < 8;y++) {
  209. if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) && (((p->gra[y - 1][x - 1] == 1 || p->gra[y - 1][x - 1] == 3) && p->gra[y - 2][x - 2] == 0) || ((p->gra[y - 1][x + 1] == 1 || p->gra[y - 1][x + 1] == 3) && p->gra[y - 2][x + 2] == 0) || ((p->gra[y + 1][x - 1] == 1 || p->gra[y + 1][x - 1] ==3) && p->gra[y + 2][x - 2] == 0) || ((p->gra[y + 1][x + 1] == 1 || p->gra[y + 1][x + 1] == 3 ) && p->gra[y + 2][x + 2] == 0))) {
  210. return true;
  211. }
  212. }
  213. }return false;
  214. }
  215. bool podwojne(plansza *p,int y, int x)
  216. {
  217. p->zamiana();
  218.  
  219. if ((p->gra[y][x] == 2 || p->gra[y][x] == 4) && (p->gra[y - 1][x - 1] == 1 || p->gra[y - 1][x - 1] == 3) && p->gra[y - 2][x - 2] == 0) {
  220. swap(p->gra[y - 2][x - 2], p->gra[y][x]);
  221. p->gra[y - 1][x - 1] = 0;
  222. podwojne(&*p, y - 2, x - 2);
  223. return true;
  224. }
  225. if ((p->gra[y][x] == 2 || p->gra[y][x] == 4) && (p->gra[y + 1][x - 1] == 1 || p->gra[y + 1][x - 1] == 3) && p->gra[y + 2][x - 2] == 0) {
  226. swap(p->gra[y + 2][x - 2], p->gra[y][x]);
  227. p->gra[y + 1][x - 1] = 0;
  228. podwojne(&*p, y + 2, x - 2);
  229. return true;
  230. }
  231. if ((p->gra[y][x] == 2 || p->gra[y][x] == 4) && (p->gra[y - 1][x + 1] == 1 || p->gra[y - 1][x + 1] == 3) && p->gra[y - 2][x + 2] == 0) {
  232. swap(p->gra[y - 2][x + 2], p->gra[y][x]);
  233. p->gra[y - 1][x + 1] = 0;
  234. podwojne(&*p, y - 2, x + 2);
  235. return true;
  236. }
  237. if ((p->gra[y][x] == 2 || p->gra[y][x] == 4) && (p->gra[y + 1][x + 1] == 1 || p->gra[y + 1][x + 1] == 3) && p->gra[y + 2][x + 2] == 0) {
  238. swap(p->gra[y + 2][x + 2], p->gra[y][x]);
  239. p->gra[y + 1][x + 1] = 0;
  240. podwojne(&*p, y + 2, x + 2);
  241. return true;
  242. } return false;
  243. }
  244. bool bicie(plansza *p) {
  245. for (int x = 0;x < 8;x++) {
  246. for (int y = 0;y < 8;y++) {
  247. if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) && (p->gra[y - 1][x - 1] == 1 || p->gra[y - 1][x - 1] == 3) && p->gra[y - 2][x - 2] == 0) {
  248. swap(p->gra[y - 2][x - 2], p->gra[y][x]);
  249. p->gra[y - 1][x - 1] = 0;
  250. if (podwojne(&*p,y-2,x-2)) {
  251. cout << endl << "Podwojne bicie" << endl;
  252. return true;
  253. }
  254. }if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) &&( p->gra[y + 1][x - 1] == 1 || p->gra[y + 1][x - 1] ==3) && p->gra[y + 2][x - 2] == 0) {
  255. swap(p->gra[y + 2][x - 2], p->gra[y][x]);
  256. p->gra[y + 1][x - 1] = 0;
  257. if (podwojne(&*p, y + 2, x - 2)) {
  258. cout << endl << "Podwojne bicie" << endl;
  259. return true;
  260. }
  261. }if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) && (p->gra[y - 1][x + 1] == 1 || p->gra[y - 1][x + 1] ==3) && p->gra[y - 2][x + 2] == 0) {
  262. swap(p->gra[y - 2][x + 2], p->gra[y][x]);
  263. p->gra[y - 1][x + 1] = 0;
  264. if (podwojne(&*p, y - 2, x + 2)) {
  265. cout << endl << "Podwojne bicie" << endl;
  266. return true;
  267. }
  268. }if (( p->gra[y][x] == 2 || p->gra[y][x] == 4 ) && (p->gra[y + 1][x + 1] == 1 || p->gra[y + 1][x + 1] ==3) && p->gra[y + 2][x + 2] == 0) {
  269. swap(p->gra[y + 2][x + 2], p->gra[y][x]);
  270. p->gra[y + 1][x + 1] = 0;
  271. if (podwojne(&*p, y + 2, x + 2)) {
  272. cout << endl << "Podwojne bicie" << endl;
  273. return true;
  274. }
  275. }
  276. }
  277. }return false;
  278. }
  279. };
  280. int main()
  281. {
  282. plansza p;
  283. przeciwnik prz;
  284. int koniec = 0;
  285. p.resetuj();
  286. do {
  287. int k, b;
  288. do {
  289. p.zamiana();
  290. if (p.czybic()) {
  291. cout << "trzeba bic" << endl;
  292. p.zamiana();
  293. p.wyswietl();
  294. flaga = 0;
  295. cin >> k;
  296. cin >> b;
  297. p.bicie(k, b);
  298. if (p.czybic()) {
  299. cout << "trzeba bic" << endl;
  300. p.zamiana();
  301. p.wyswietl();
  302. flaga = 0;
  303. cin >> k;
  304. cin >> b;
  305. p.bicie(k, b);
  306. if (p.czybic()) {
  307. cout << "trzeba bic" << endl;
  308. p.zamiana();
  309. p.wyswietl();
  310. flaga = 0;
  311. cin >> k;
  312. cin >> b;
  313. p.bicie(k, b);
  314. }
  315. }
  316. }
  317. else {
  318. p.zamiana();
  319. p.wyswietl();
  320. flaga = 0;
  321. cin >> k;
  322. cin >> b;
  323. p.przestaw(k, b);
  324. }
  325. } while (flaga == 0);
  326. system("cls");
  327. if(prz.czybic(&p)){
  328. cout << "bot bije" << endl;
  329. if (!prz.bicie(&p)) {
  330. cout << "problem z biciem" << endl;
  331. }
  332. }
  333. else {
  334. if (!prz.zaslon(&p)) {
  335. if (prz.ruszaj(&p)) {
  336. cout << "bot sie ruszyl" << endl;
  337. }
  338. else if (!prz.ruszaj2(&p)) {
  339. cout << "KONIEC" << endl;
  340. koniec = 1;
  341. }
  342. }
  343. }
  344. } while (koniec == 0);
  345. return 0;
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement