Noam_15

דמקה V0.2.1

Apr 29th, 2017
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.89 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. enum Color {empty, Black, White}; // לבנים למטה
  4. enum errors {good, bad_arguments, first_location_empty, second_location_not_empty, bad_direction,
  5.     Not_in_the_same_diagonal, second_location_is_a_white_square, opponent_tries_to_eat_himself,
  6.     Skipping, error_in_check_direction_on_the_axis_F, king_tries_to_eat_2_or_more, king_did_not_stop_immediately_after_soldier};
  7.  
  8.  
  9. class Square{  //משבצת
  10. public:
  11.     Color Soldier_Color;
  12.     bool king;
  13.     bool AteBefore;
  14.     Square(Color CC = empty, bool aa = false, bool KK = false){
  15.         Soldier_Color = CC;
  16.         AteBefore = aa;
  17.         king = KK;
  18.     }
  19. };
  20. class Board{
  21. public:
  22.     Square DamkaArray [8][8];
  23. };
  24. Board Real_Damka_soldiers;   //  המערך הראשי
  25.  
  26.  
  27. class FromTo{
  28. public:
  29.     int i1,i2,b1,b2;
  30. };
  31.  
  32. // int user_move[4]; // עמודה b מייצגת מספר שורה ו i הם יעד. האות i2,b2 הם מוצא. ו i1,b1 כאשר  i1,b1,i2,b2  :מאחסן את פעולת השחקן האנושי. באופן הבא
  33. bool Is_it_sharsheret;
  34.  
  35. // int mode = 0; //  מצב המשחק. 0 פירושו אדם נגד אדם. 1 פירושו אדם נגד מחשב. וככל שעולה המספר כך עולה רמת הקושי
  36. // Color turn_color=White; // התור של מי. בחרנו כאן איזה צבע ראשון
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49. ////////////////////////////////////////////////////////////////       //הצהרות על פונקציות
  50. bool check_Future_possibility_for_sharsheret(FromTo a_move,  Board  this_board);
  51. void move_soldier(FromTo this_move, Board * this_board_P);
  52. errors rules (FromTo this_move, Board * this_board_P);
  53. void Print_Damka();
  54.  
  55.  
  56.  
  57. ////////////////////////////////////////////////////////////////
  58.  
  59.  
  60.  
  61.  
  62. void print_Error_type(errors en){
  63.     if (en==good) return;
  64.     cout<< "\n**Error found:\n";
  65.     switch(en) {
  66.     case bad_arguments:                cout<<"Error: bad arguments\n"; break;
  67.     case first_location_empty:         cout<<"Error: first location empty\n"; break;
  68.     case second_location_not_empty:    cout<<"Error: second location not empty\n"; break;
  69.     case bad_direction:                cout<<"Error: bad direction\n"; break;
  70.     case Not_in_the_same_diagonal:     cout<<"Error: Not_in_the_same_diagonal\n"; break;
  71.     case second_location_is_a_white_square:      cout<<"Error: second location is a white square\n"; break;
  72.     case opponent_tries_to_eat_himself:cout<<"Error: opponent tries to eat himself\n"; break;
  73.     case Skipping:                     cout<<"Error: Skipping\n"; break;
  74.     case error_in_check_direction_on_the_axis_F: cout<<"Error: error_in_check_direction_on_the_axis_F\n"; break;
  75.     case king_tries_to_eat_2_or_more:  cout<<"Error: king tries to eat 2 or more\n"; break;
  76.     case king_did_not_stop_immediately_after_soldier:  cout<<"Error: king did not stop immediately after a soldier\n"; break; // אופציונלי
  77.     }
  78.  
  79.     cout<<"\n\n";
  80. }
  81.  
  82. FromTo Get_From_User(Color turn_color){  //  מחזיר מהלך שתואם את כל החוקים
  83.  
  84.     //  להוסיף אפשרות להתחרט  //  ////  //
  85.  
  86.     char strFirst[3];
  87.     char strSecond[3];
  88.     char sharsheret_check;
  89.  
  90.     FromTo user_move;   //  בשביל הערך המספרי שמומר מהאותיות
  91.     do{
  92.         do{
  93.             if (turn_color==White) {cout<<"White move!\nEnter first location:  ";}
  94.             else {cout<<"Black move!\nEnter first location:  ";}
  95.             cin>>strFirst;
  96.             while(1){
  97.                 while (!((strFirst[0]>='A'&&strFirst[0]<='H' && strFirst[1]>='1'&&strFirst[1]<='8') ||
  98.                     (strFirst[0]>='a'&&strFirst[0]<='h' && strFirst[1]>='1'&&strFirst[1]<='8') ||
  99.                     (strFirst[1]>='A'&&strFirst[1]<='H' && strFirst[0]>='1'&&strFirst[0]<='8') ||
  100.                     (strFirst[1]>='a'&&strFirst[1]<='h' && strFirst[0]>='1'&&strFirst[0]<='8'))){
  101.                         cout<<"*Enter a legal first location:  ";
  102.                         cin>>strFirst;
  103.                 }
  104.  
  105.                 // עד כאן קליטה למשתני עזר
  106.  
  107.                 if(strFirst[0]>='A'&&strFirst[0]<='H'){
  108.                     user_move.b1=strFirst[0]-'A';
  109.                     user_move.i1=strFirst[1]-'1';
  110.                 }
  111.                 else if(strFirst[0]>='a'&&strFirst[0]<='h'){  // h לפי אסקי אפשר לוותר על הבדיקה של
  112.                     user_move.b1=strFirst[0]-'a';
  113.                     user_move.i1=strFirst[1]-'1';
  114.                 }
  115.                 else if(strFirst[1]>='A'&&strFirst[1]<='H'){
  116.                     user_move.b1=strFirst[1]-'A';
  117.                     user_move.i1=strFirst[0]-'1';
  118.                 }
  119.                 else{// if(strFirst[1]>='a'&&strFirst[1]<='h')  //אין צורך לכתוב       // h לפי אסקי אפשר לוותר על הבדיקה של
  120.                     user_move.b1=strFirst[1]-'a';
  121.                     user_move.i1=strFirst[0]-'1';
  122.                 }
  123.                 // עד כאן השמה של משתנה עזר ראשון במערך הגלובלי
  124.  
  125.                 if (Real_Damka_soldiers.DamkaArray[user_move.i1][user_move.b1].Soldier_Color==turn_color){  // בודק שהצבע מתאים לתור -מסתמכים על זה בהמשך. וגם בודק שלא ריק
  126.                     break;
  127.                 }
  128.                 else{
  129.                     cout<<"*Please enter black Square in YOUR COLOR:  ";
  130.                     cin>>strFirst;
  131.                 }
  132.             }
  133.  
  134.  
  135.  
  136.             //  עד כאן קליטת מוצא
  137.  
  138.  
  139.  
  140.             cout<<"Enter second location:  ";
  141.             cin>>strSecond;
  142.             while(1){
  143.                 while (!((strSecond[0]>='A'&&strSecond[0]<='H' && strSecond[1]>='1'&&strSecond[1]<='8') ||
  144.                     (strSecond[0]>='a'&&strSecond[0]<='h' && strSecond[1]>='1'&&strSecond[1]<='8') ||
  145.                     (strSecond[1]>='A'&&strSecond[1]<='H' && strSecond[0]>='1'&&strSecond[0]<='8') ||
  146.                     (strSecond[1]>='a'&&strSecond[1]<='h' && strSecond[0]>='1'&&strSecond[0]<='8'))){
  147.                         cout<<"*Enter a legal second location:  ";
  148.                         cin>>strSecond;
  149.                 }
  150.  
  151.                 // עד כאן קליטה למשתני עזר של המקום השני
  152.  
  153.  
  154.                 if(strSecond[0]>='A'&&strSecond[0]<='H'){
  155.                     user_move.b2=strSecond[0]-'A';
  156.                     user_move.i2=strSecond[1]-'1';
  157.                 }
  158.                 else if(strSecond[0]>='a'&&strSecond[0]<='h'){  // h לפי אסקי אפשר לוותר על הבדיקה של
  159.                     user_move.b2=strSecond[0]-'a';
  160.                     user_move.i2=strSecond[1]-'1';
  161.                 }
  162.                 else if(strSecond[1]>='A'&&strSecond[1]<='H'){
  163.                     user_move.b2=strSecond[1]-'A';
  164.                     user_move.i2=strSecond[0]-'1';
  165.                 }
  166.                 else{// if(strSecond[1]>='a'&&strSecond[1]<='h')  //אין צורך לכתוב       // h לפי אסקי אפשר לוותר על הבדיקה של
  167.                     user_move.b2=strSecond[1]-'a';
  168.                     user_move.i2=strSecond[0]-'1';
  169.                 }
  170.  
  171.  
  172.  
  173.  
  174.  
  175.                 Color enemy_color = (turn_color==White)? Black : White ;
  176.                 if (Real_Damka_soldiers.DamkaArray[user_move.i2][user_move.b2].Soldier_Color==empty && (user_move.i2 + user_move.b2)%2==1 ){  // בודק שהצבע מתאים לתור -מסתמכים על זה בהמשך. וגם בודק שלא ריק
  177.                     break;
  178.                 }
  179.                 else{
  180.                     cout<<"*Please enter empty black Square:  ";
  181.                     cin>>strSecond;
  182.                 }
  183.             }
  184.  
  185.  
  186.  
  187.  
  188.             errors ff = rules (user_move, &Real_Damka_soldiers);
  189.             if (ff==good){
  190.                 break;
  191.             }
  192.             else{
  193.                 print_Error_type(ff);
  194.                 cout<< "\nSo please read the rules...\n";
  195.                 Print_Damka();
  196.             }
  197.  
  198.         }while(1);   //  לולאה עבור בדיקת המוצא ויעד כחוקיים
  199.  
  200.  
  201.         cout<<"Will it be a sharsheret move? (Y/N):  ";
  202.         cin>>sharsheret_check;
  203.         while(sharsheret_check!='n' && sharsheret_check!='N' && sharsheret_check!='y' && sharsheret_check!='Y'){
  204.             cout<<"*Only Y/N:  ";
  205.             cin>>sharsheret_check;
  206.         }
  207.         if(sharsheret_check=='y'|| sharsheret_check=='Y'){
  208.             if(check_Future_possibility_for_sharsheret(user_move, Real_Damka_soldiers)==true){
  209.                 Is_it_sharsheret=true;
  210.                 break;
  211.             }
  212.             else{
  213.                 cout<<"*This move can't be a sharsheret move!\n*Please try again...\n\n";
  214.             }
  215.  
  216.         }
  217.         else{
  218.             Is_it_sharsheret=false;
  219.             break;
  220.         }
  221.  
  222.  
  223.  
  224.     }while(1);//  לולאה עבור בדיקת השרשרת כתקינה
  225.  
  226.  
  227.     return user_move;
  228. }
  229.  
  230.  
  231. char convert_to_symbol(int i, int b){  //  מקבל מקום במערך הדמקה ומחזיר סמל
  232.     if(Real_Damka_soldiers.DamkaArray[i][b].Soldier_Color == White){
  233.         if(Real_Damka_soldiers.DamkaArray[i][b].king==false) return 'W';
  234.         else  return (char)233; // מלך
  235.     }
  236.     if(Real_Damka_soldiers.DamkaArray[i][b].Soldier_Color == Black){
  237.         if(Real_Damka_soldiers.DamkaArray[i][b].king==false) return 'B';
  238.         else  return 232;
  239.     }
  240.     else {
  241.         if((i+b)%2==1) return 176; // ה 176 זה הצבע של השחור
  242.         else return 177;
  243.     }
  244. }
  245.  
  246. void Print_Damka(){
  247.     int i,a,b;
  248.     cout<<"\n  ABCDEFGH";
  249.     for(i=0; i<8; i++){
  250.         for(b=0;b<8;b++){
  251.             if(b%8==0) cout<<"\n";
  252.             if(b==0)cout<<i+1<<" ";  //מיספור
  253.             cout<<convert_to_symbol(i,b);
  254.         }
  255.     }
  256.     cout<<"\n\n";  
  257. }
  258.  
  259. void Order_First_Damka(){
  260.     int i,a,b;
  261.     for(i=0; i<3; i++){
  262.         for(b=0;b<8;b++){
  263.             if ((i+b)%2==1){
  264.                 Real_Damka_soldiers.DamkaArray[i][b].Soldier_Color=Black;
  265.             }
  266.         }
  267.     }
  268.     for(i=5; i<8; i++){
  269.         for(b=0;b<8;b++){
  270.             if ((i+b)%2==1){
  271.                 Real_Damka_soldiers.DamkaArray[i][b].Soldier_Color=White;
  272.             }
  273.         }
  274.  
  275.         // עבור בדיקת המלכים
  276.         for(b=0; b<8; b++){
  277.             Real_Damka_soldiers.DamkaArray[5][b].king=true;
  278.         }
  279.     }
  280.  
  281. }
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.  
  290. unsigned int  AVBTN(int a, int b){  // Absolute_value_between_two_numbers // ערך מוחלט
  291.     if(a>b) return a-b;
  292.     else return b-a;
  293. }
  294.  
  295. void Clear_soldier(int i, int b, Board * this_board_P){
  296.     (*this_board_P).DamkaArray[i][b].king = false;
  297.     //  (*this_board_P).DamkaArray[i][b].AteBefore = false;   // זה כנראה יהיה מיותר
  298.     (*this_board_P).DamkaArray[i][b].Soldier_Color = empty;
  299. }
  300.  
  301. Color check_soldier_color_between_two_location(int i1, int b1, int i2, int b2, Board * this_board_P){ // שימו לב שצריכה להיות בדיוק משבצת אחת ביניהם  //  פונקציה לא שימושית. הכנסתי כבר בתוך פונקציית העברה
  302.     return (*this_board_P).DamkaArray[(i1+i2)/2][(b1+b2)/2].Soldier_Color;
  303. }
  304.  
  305. int check_direction_on_the_axis(int exit_point, int aim_point){  // עולים או יורדים i/b בדיקת כיוון על הציר, האם מהיעד למטרה הפרמטרים של ציר  
  306.     if (aim_point - exit_point>0) return 1;   // עולים
  307.     if (aim_point - exit_point<0) return -1;  // יורדים
  308.     print_Error_type(error_in_check_direction_on_the_axis_F);  // עבור אם הם באותו מקום
  309.     return error_in_check_direction_on_the_axis_F ;
  310. }
  311.  
  312.  
  313. bool is_it_a_kill_move(FromTo a_move, Board * this_board_P){
  314.     bool a_kill=false;
  315.     Color this_color = (*this_board_P).DamkaArray[a_move.i1][a_move.b1].Soldier_Color;
  316.     Color enemy_color = (this_color==White)? Black : White ;
  317.  
  318.     int direction_i=check_direction_on_the_axis(a_move.i1,a_move.i2); // יורדים. אם עולים יהיה 1 i יהיה 1- אם מהיעד למטרה ערכי ציר ה
  319.     int direction_b=check_direction_on_the_axis(a_move.b1,a_move.b2); // יורדים. אם עולים יהיה 1 b יהיה 1- אם מהיעד למטרה ערכי ציר ה
  320.     int counter_i, counter_b;
  321.  
  322.     for(counter_i=a_move.i1+direction_i, counter_b=a_move.b1+direction_b; counter_i != a_move.i2; counter_i+=direction_i, counter_b+=direction_b){
  323.         if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color==enemy_color) {
  324.             a_kill=true;
  325.             break;
  326.         }
  327.     }
  328.  
  329.     return a_kill;
  330.  
  331. }
  332.  
  333. bool check_Future_possibility_for_sharsheret(FromTo a_move,  Board  this_board){  //  בודק אם אחרי המהלך, אותו שחקן יוכל להמשיך למהלך שרשרת
  334.     if (is_it_a_kill_move(a_move, &this_board)){
  335.         move_soldier(a_move, &this_board);
  336.  
  337.  
  338.         int direction_i=check_direction_on_the_axis(a_move.i1,a_move.i2); // יורדים. אם עולים יהיה 1 i יהיה 1- אם מהיעד למטרה ערכי ציר ה
  339.         int direction_b=check_direction_on_the_axis(a_move.b1,a_move.b2); // יורדים. אם עולים יהיה 1 b יהיה 1- אם מהיעד למטרה ערכי ציר ה
  340.         int counter_i, counter_b;
  341.         FromTo exmp;
  342.         exmp.i1 = a_move.i2;
  343.         exmp.b1 = a_move.b2;
  344.  
  345.         for(counter_i=0; counter_i<8; counter_i++){
  346.             for(counter_b=0; counter_b<8; counter_b++){
  347.                 if ((counter_i + counter_b)%2==1){
  348.                     exmp.i2=counter_i;
  349.                     exmp.b2=counter_b;
  350.                     if(rules(exmp, &this_board)==good){
  351.                         if (is_it_a_kill_move(exmp, &this_board)==true){
  352.                             return true;
  353.                         }
  354.                     }
  355.                     else continue;
  356.                 }
  357.                 else continue;
  358.  
  359.  
  360.             }
  361.         }
  362.  
  363.  
  364.  
  365.     }
  366.  
  367.     else return false;
  368. }
  369.  
  370.  
  371.  
  372.  
  373.  
  374.  
  375.  
  376.  
  377. void move_soldier(FromTo this_move, Board * this_board_P){
  378.  
  379.     int i1 = this_move.i1;
  380.     int i2 = this_move.i2;
  381.     int b1 = this_move.b1;
  382.     int b2 = this_move.b2;
  383.  
  384.     int direction_i=check_direction_on_the_axis(i1,i2); // יורדים. אם עולים יהיה 1 i יהיה 1- אם מהיעד למטרה ערכי ציר ה
  385.     int direction_b=check_direction_on_the_axis(b1,b2); // יורדים. אם עולים יהיה 1 b יהיה 1- אם מהיעד למטרה ערכי ציר ה
  386.  
  387.  
  388.  
  389.     (*this_board_P).DamkaArray[i2][b2] = (*this_board_P).DamkaArray[i1][b1];
  390.     Clear_soldier(i1, b1, this_board_P);
  391.     Clear_soldier(i2 - direction_i, b2 - direction_b, this_board_P); // אכילה. אם ההזזה הזו היא לא אכילה זה לא פגע בכלום
  392.  
  393.     if((i2==7&& (*this_board_P).DamkaArray[i2][b2].Soldier_Color== Black)||(i2==0 && (*this_board_P).DamkaArray[i2][b2].Soldier_Color== White))
  394.         (*this_board_P).DamkaArray[i2][b2].king=true;  // הפיכה למלך
  395.     /*
  396.     if(turn_color == White && sharsheret ==false) {turn_color=Black;}  // אחרי בדיקה שזה לא מהלך שרשרת, משנים צבע תור
  397.     else if(turn_color == Black && sharsheret ==false) turn_color=White;
  398.     */
  399.  
  400.     // צריך לשלוח מכאן לפונקציה שמטפלת במהלך שרשרת, בקליטה שלו, ובהודעות השגיעה  // // //
  401.  
  402.     // צריך להוסיף הגבלה של אכילה חובה- שרוף. אבל צריך לבדוק את החוקים קודם       // // //
  403.  
  404.     // צריך כאן פונקציה להיסטוריה   // // //
  405. }
  406.  
  407. errors rules (FromTo this_move, Board * this_board_P){
  408.  
  409.     /*
  410.     הפונקציה בודקת שהעברה אפשרית, אם כן - מעבירה חיילים ומשיבה הצלחה
  411.     אחרת - משיבה כישלון ומחזירה את סוג הכישלון
  412.     סוגי כישלון:
  413.     המיקומים שקיבלנו הם מחוץ ללוח  .1
  414.     2.  הייעד כבר תפוס, או שהמוצא ריק
  415.     3.  היעד הוא משבצת לבנה
  416.     4.  המוצא והיעד לא על אותו אלכסון
  417.     5.  חייל (לא מלך) לבן יורד, או חייל שחור עולה. למעט מהלך שרשרת
  418.  
  419.     6.  :בחייל (לא מלך) עליו לדלג רק משבצת אלכסונית אחת. ואם הוא אוכל אז רק שתיים, ואז עלינו לבדוק שהאכילה תקינה
  420.     .יש בין המוצא ליעד חייל. והוא לא מאותו צבע
  421.  
  422.     הגעתי עד כאן
  423.     7.  :אם זה מלך אז הוא יכול ללכת כל מספר שורות (שהוכח כבר שהן בתוך המשחק) אבל בתנאי
  424.     .אין חיילים מאותו צבע בדרך
  425.     .אין יותר מחייל עוין אחד
  426.     .אופציונלי: עליו לעצור מייד אחרי חייל עויין בלי להתרחק ממנו
  427.  
  428.     */
  429.  
  430.  
  431.     /* לא צריך לבדוק את צבע כלי המוצא אם הוא תואם את צבע התור, כי זה כבר נקלט בפונקציית הקלט. שימו לב שהרבה מהפעולות כאן על צבעים היה אפשר לחסוך
  432.     באמצעות המשתנה הגלובלי של צבע התור
  433.     */
  434.  
  435.  
  436.  
  437.     int i1 = this_move.i1;
  438.     int i2 = this_move.i2;
  439.     int b1 = this_move.b1;
  440.     int b2 = this_move.b2;
  441.     Color this_color = (*this_board_P).DamkaArray[i1][b1].Soldier_Color;
  442.     Color second_square = (*this_board_P).DamkaArray[i2][b2].Soldier_Color;
  443.  
  444.  
  445.  
  446.     if(i1>7||i1<0||b1>7||b1<0||i2>7||i2<0||b2>7||b2<0) return bad_arguments; // הכלים במקום שלא קיים  //  ייתכן שנמנע בקלט מהרקורסיה והמשתמש אפשרות שזה לא יהיה נכון, ואז אפשר לחסוך את הבדיקה הזאת
  447.     if(this_color == empty) return first_location_empty;  //  אגב זה בודק שהמקום הראשון לא לבן//  ייתכן שנמנע בקלט מהרקורסיה אפשרות שזה לא יהיה נכון, ואז אפשר לחסוך את הבדיקה הזאת
  448.     if((i2+b2)%2 == 0) return second_location_is_a_white_square;  // יש צורך לבדוק רק את המיקום השני, כי הראשון כבר יודעים שיש בו שחקן
  449.     if(second_square != empty) return second_location_not_empty; // בדיקה שהיעד ריק. אגב זה גם בודק שהמקום הראשון והשני לא זהים
  450.  
  451.  
  452.     // :משתנים שיועילו בהמשך
  453.     int AV_i=AVBTN(i1,i2); // שמירת ההפרשים המוחלטים מועילה להמשך  // Absolute_value
  454.     int AV_b=AVBTN(b1,b2);
  455.     int direction_i=check_direction_on_the_axis(i1,i2); // יורדים. אם עולים יהיה 1 i יהיה 1- אם מהיעד למטרה ערכי ציר ה
  456.     int direction_b=check_direction_on_the_axis(b1,b2); // יורדים. אם עולים יהיה 1 b יהיה 1- אם מהיעד למטרה ערכי ציר ה
  457.     int counter_i, counter_b;
  458.  
  459.     if(AV_i!=AV_b) return Not_in_the_same_diagonal; //  בדיקה שזה על אותו אלכסון. נכונה גם עבור מלכים
  460.  
  461.     if((*this_board_P).DamkaArray[i1][b1].king == false){ // חייל ולא מלך
  462.         if ((this_color == White && i1<=i2 && (*this_board_P).DamkaArray[i1][b1].AteBefore == false)||  // אם זה שרשרת אז זה חוקי
  463.             (this_color == Black && i1>=i2 && (*this_board_P).DamkaArray[i1][b1].AteBefore == false))
  464.             return bad_direction;  // כיוון לא נכון של שחקן שהלך לכיוון שלו
  465.  
  466.         if(AV_i>2) return Skipping; // כמובן שגם יותר משתי משבצות זה תמיד דילוג עבור חייל רגיל
  467.         if(AV_i==2){ // נבדוק אם יש ביניהם חייל מאותו צד ואז זו פגיעה עצמית, או אם אין כלל חייל ואז זה דילוג
  468.             Color soldier_color_between_two_location = (*this_board_P).DamkaArray[(i1+i2)/2][(b1+b2)/2].Soldier_Color; // משתנה לחיסכון בפעולות         
  469.             if(soldier_color_between_two_location==empty) return Skipping;
  470.             if(this_color == soldier_color_between_two_location){  // בדיקה מה יש ביניהם. נכונה רק עבור הפרש של משפצת אחת בינהם. מה שנכון עבור חייל
  471.                 return opponent_tries_to_eat_himself;
  472.             }
  473.         }
  474.     }
  475.  
  476.     else{ // אם זה מלך
  477.         int Counting_soldiers_eaten=0;
  478.         Color enemy_color = (this_color==White)? Black : White ;
  479.         for(counter_i=i1+direction_i, counter_b=b1+direction_b; counter_i != i2; counter_i+=direction_i, counter_b+=direction_b){
  480.             if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color==this_color) return opponent_tries_to_eat_himself;
  481.             if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color==enemy_color){
  482.                 Counting_soldiers_eaten++;
  483.                 if (Counting_soldiers_eaten>1) return king_tries_to_eat_2_or_more;
  484.             }
  485.         }
  486.         if((*this_board_P).DamkaArray[i2-direction_i][b2-direction_b].Soldier_Color == empty && Counting_soldiers_eaten==1) return king_did_not_stop_immediately_after_soldier;  // השורה הזאת לא נכונה. צריך לבדוק למה.
  487.  
  488.         // צריך לדון בדיוק מה מותר ואסור למלך לעשות כדי לכתוב את זה.   //   /////   //   /////   //
  489.     }
  490.  
  491.     return good;
  492.  
  493. }
  494.  
  495.  
  496.  
  497.  
  498.  
  499.  
  500. int How_many_blacks_left(){
  501.     int i,b,black_Counter=0;
  502.     for(i=0; i<8; i++){
  503.         for(b=0;b<8;b++){
  504.             if (Real_Damka_soldiers.DamkaArray[i][b].Soldier_Color==Black) black_Counter++;
  505.         }
  506.     }
  507.     return black_Counter;
  508. }
  509.  
  510. int How_many_white_left(){
  511.     int i,b,white_Counter=0;
  512.     for(i=0; i<8; i++){
  513.         for(b=0;b<8;b++){
  514.             if (Real_Damka_soldiers.DamkaArray[i][b].Soldier_Color==White) white_Counter++;
  515.         }
  516.     }
  517.     return white_Counter;
  518. }
  519.  
  520. void Check_for_victory(){
  521.     if (How_many_blacks_left()==0){
  522.         cout<<"------White won!------\n\n";
  523.         getchar();
  524.         exit;
  525.     }
  526.     if (How_many_white_left()==0){
  527.         cout<<"------Black won!------\n\n";
  528.         getchar();
  529.         exit;
  530.     }
  531.     // צריך להוסיף יחס שחקנים מלכים ותורות לניצחון
  532. }
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539. void main(){
  540.     FromTo ff;
  541.     // חוקים וקרדיט  והסבר על איך מתחרטים
  542.     Order_First_Damka();
  543.     Print_Damka();
  544.     do{
  545.         do{  //  מהלך של הלבנים
  546.             Is_it_sharsheret=false;
  547.             ff= Get_From_User(White);
  548.             move_soldier(ff, &Real_Damka_soldiers);
  549.             Print_Damka();
  550.             Check_for_victory();
  551.         }while(Is_it_sharsheret);
  552.  
  553.         do{  //  מהלך של השחורים
  554.             Is_it_sharsheret=false;
  555.             ff= Get_From_User(Black);
  556.             move_soldier(ff, &Real_Damka_soldiers);
  557.             Print_Damka();
  558.             Check_for_victory();
  559.         }while(Is_it_sharsheret);
  560.     }while(1);
  561. }// צריך בדיקה שלא להכנס למצב אין סופי שצד אחד לא יכול לזוז - לדלג על התור שלו. ואם שניהם לא יכולים לזוז אז להכריז על תיקו
  562.  
  563.  
  564.  
  565. // באג:    אם אןמרים שהיה מהלך שרשרת - הוא לא יודע לאפיין שרק החייל שקודם זז יכול שוב לזוז, ולא אחרים
  566.  
  567. // להוסיף שרופים
  568. // להוסיף שאסור לחזור על אותו מהלך יותר מ3 פעמים
  569. //
Advertisement
Add Comment
Please, Sign In to add comment