Noam_15

דמקה V0.4.0

May 4th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 41.20 KB | None | 0 0
  1. //  v0.4.0       שחקן נגד שחקן עם מהלכי שרשרת ועם שרופים ועם התייחסות לתיקו כשיש מלך מול מלך. בלי תיקו כשחוזרים על אותו מהלך 15 פעמים.
  2. #include <iostream>
  3. using namespace std;
  4. enum Color {empty, Black, White}; // לבנים למטה
  5. enum errors {good, bad_arguments, first_location_empty, second_location_not_empty, bad_direction,
  6.     Not_in_the_same_diagonal, second_location_is_a_white_square, opponent_tries_to_eat_himself,
  7.     Skipping, error_in_check_direction_on_the_axis_F, king_tries_to_eat_2_or_more, king_did_not_stop_immediately_after_soldier,
  8.     Is_it_sharsheret_in_rules_F_was_a_lie, after_sharsheret_move_must_be_again_kill_move, Must_eat_when_possible};
  9.  
  10.  
  11. class a_location{
  12. public:
  13.     int i;
  14.     int b;
  15.     a_location(){  //  המסיים null יוצר ברירת מחדל שהיא כמו ה
  16.         i=0;
  17.         b=0;
  18.     }
  19. };
  20.  
  21. class LocationsArray{
  22. public:
  23.     a_location array[13];  //  null לכל שחקן יש לכל היותר 12 שחקנים. עוד אחד עבור ה
  24. };
  25.  
  26. class Square{  //משבצת
  27. public:
  28.     Color Soldier_Color;
  29.     bool king;
  30.     bool AteBefore;
  31.     Square(Color CC = empty, bool aa = false, bool KK = false){
  32.         Soldier_Color = CC;
  33.         AteBefore = aa;
  34.         king = KK;
  35.     }
  36. };
  37. class Board{
  38. public:
  39.     Square DamkaArray [8][8];
  40. };
  41. Board Real_Damka_soldiers;   //  המערך הראשי
  42.  
  43.  
  44. class FromTo{
  45. public:
  46.     int i1,i2,b1,b2;
  47. };
  48.  
  49. // int user_move[4]; // עמודה b מייצגת מספר שורה ו i הם יעד. האות i2,b2 הם מוצא. ו i1,b1 כאשר  i1,b1,i2,b2  :מאחסן את פעולת השחקן האנושי. באופן הבא
  50.  
  51.  
  52. // int mode = 0; //  מצב המשחק. 0 פירושו אדם נגד אדם. 1 פירושו אדם נגד מחשב. וככל שעולה המספר כך עולה רמת הקושי
  53. // Color turn_color=White; // התור של מי. בחרנו כאן איזה צבע ראשון
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66. ////////////////////////////////////////////////////////////////       //הצהרות על פונקציות
  67. bool check_Future_possibility_for_sharsheret(FromTo a_move,  Board  this_board);
  68. void move_soldier(FromTo this_move, Board * this_board_P);
  69. errors rules (FromTo this_move, Board * this_board_P, bool Is_it_sharsheret=false);
  70. void Print_Damka();
  71. unsigned int  AVBTN(int a, int b);
  72. int check_direction_on_the_axis(int exit_point, int aim_point);
  73.  
  74. ////////////////////////////////////////////////////////////////
  75.  
  76.  
  77.  
  78. // אולי אפשר למחוק את הפונקציה הזאת:
  79. bool is_this_soldier_not_stuck(a_location location, Board * this_board_P){ // חייב לקבל חייל או מלך ולא ריק. לא יודע להתמודד עם מהלך שרשרת
  80.     Color this_color = (* this_board_P).DamkaArray[location.i][location.b].Soldier_Color;
  81.     Color enemy_color = (this_color==White)? Black : White;
  82.     if((* this_board_P).DamkaArray[location.i][location.b].king == true || (* this_board_P).DamkaArray[location.i][location.b].AteBefore == true){  //  אם זה מלך או אם זה מהלך שרשרת שיכולים ללכת ל4 כיוונים
  83.  
  84.         if(location.i+1<8 && location.b+1<8){ // ציר ראשון
  85.             if ((* this_board_P).DamkaArray[location.i+1][location.b+1].Soldier_Color==empty) return true;
  86.             if(location.i+2<8 && location.b+2<8){
  87.                 if ((* this_board_P).DamkaArray[location.i+2][location.b+2].Soldier_Color==empty && (* this_board_P).DamkaArray[location.i+1][location.b+1].Soldier_Color==enemy_color) return true;
  88.             }
  89.         }
  90.  
  91.         if(location.i+1<8 && location.b-1>=0){ // ציר שני
  92.             if ((* this_board_P).DamkaArray[location.i+1][location.b-1].Soldier_Color==empty) return true;
  93.             if(location.i+2<8 && location.b-2>=0){
  94.                 if ((* this_board_P).DamkaArray[location.i+2][location.b-2].Soldier_Color==empty && (* this_board_P).DamkaArray[location.i+1][location.b-1].Soldier_Color==enemy_color) return true;
  95.             }
  96.         }
  97.  
  98.         if(location.i-1>=0 && location.b-1>=0){ // ציר שלישי
  99.             if ((* this_board_P).DamkaArray[location.i-1][location.b-1].Soldier_Color==empty) return true;
  100.             if(location.i-2>=0 && location.b-2>=0){
  101.                 if ((* this_board_P).DamkaArray[location.i-2][location.b-2].Soldier_Color==empty && (* this_board_P).DamkaArray[location.i-1][location.b-1].Soldier_Color==enemy_color) return true;
  102.             }
  103.         }
  104.  
  105.         if(location.i-1>=0 && location.b+1<8){ // ציר רביעי
  106.             if ((* this_board_P).DamkaArray[location.i-1][location.b+1].Soldier_Color==empty) return true;
  107.             if(location.i-2>=0 && location.b+2<8){
  108.                 if ((* this_board_P).DamkaArray[location.i-2][location.b+2].Soldier_Color==empty && (* this_board_P).DamkaArray[location.i-1][location.b+1].Soldier_Color==enemy_color) return true;
  109.             }
  110.         }
  111.  
  112.     }
  113.     else{ // אם זה לא מלך
  114.         if (this_color == White){
  115.             if(location.i-1>=0 && location.b-1>=0){
  116.                 if ((* this_board_P).DamkaArray[location.i-1][location.b-1].Soldier_Color==empty) return true;
  117.                 if(location.i-2>=0 && location.b-2>=0){
  118.                     if ((* this_board_P).DamkaArray[location.i-2][location.b-2].Soldier_Color==empty && (* this_board_P).DamkaArray[location.i-1][location.b-1].Soldier_Color==enemy_color) return true;
  119.                 }
  120.             }
  121.  
  122.             if(location.i-1>=0 && location.b+1<8){
  123.                 if ((* this_board_P).DamkaArray[location.i-1][location.b+1].Soldier_Color==empty) return true;
  124.                 if(location.i-2>=0 && location.b+2<8){
  125.                     if ((* this_board_P).DamkaArray[location.i-2][location.b+2].Soldier_Color==empty && (* this_board_P).DamkaArray[location.i-1][location.b+1].Soldier_Color==enemy_color) return true;
  126.                 }
  127.             }
  128.  
  129.         }
  130.         else{
  131.             if(location.i+1<8 && location.b+1<8){
  132.                 if ((* this_board_P).DamkaArray[location.i+1][location.b+1].Soldier_Color==empty) return true;
  133.                 if(location.i+2<8 && location.b+2<8){
  134.                     if ((* this_board_P).DamkaArray[location.i+2][location.b+2].Soldier_Color==empty && (* this_board_P).DamkaArray[location.i+1][location.b+1].Soldier_Color==enemy_color) return true;
  135.                 }
  136.             }
  137.  
  138.             if(location.i+1<8 && location.b-1>=0){
  139.                 if ((* this_board_P).DamkaArray[location.i+1][location.b-1].Soldier_Color==empty) return true;
  140.                 if(location.i+2<8 && location.b-2>=0){
  141.                     if ((* this_board_P).DamkaArray[location.i+2][location.b-2].Soldier_Color==empty && (* this_board_P).DamkaArray[location.i+1][location.b-1].Soldier_Color==enemy_color) return true;
  142.                 }
  143.             }
  144.  
  145.         }
  146.     }
  147.     return false;
  148. }
  149.  
  150. bool is_this_soldier_can_do_a_kiil_move(a_location location, Board * this_board_P){
  151.     // הפונקציה חייבת לקבל כתובת של חייל מאיזה שהוא צבע.   הפונקציה עונה האם אפשרי שהוא יאכל עכשיו
  152.     // הפןנקציה לא יודעת שאם חייל נמצא במהלך שרשרת אז הוא יכול לאכול אחורה
  153.     int counter_i, counter_b, i, b;
  154.     int direction_i; // =check_direction_on_the_axis(i1,i2); // יורדים. אם עולים יהיה 1 i יהיה 1- אם מהיעד למטרה ערכי ציר ה
  155.     int direction_b; // =check_direction_on_the_axis(b1,b2); // יורדים. אם עולים יהיה 1 b יהיה 1- אם מהיעד למטרה ערכי ציר ה
  156.     Color enemy_color = ((*this_board_P).DamkaArray[location.i][location.b].Soldier_Color==White)? Black : White ;
  157.  
  158.     if((*this_board_P).DamkaArray[location.i][location.b].king==true){  // אם הוא מלך אז אין צורך להתחשב בכיוון ובמרחק
  159.         int AV_i;// =AVBTN(i1,i2); // Absolute_value
  160.         int AV_b;// =AVBTN(b1,b2);
  161.         bool flag;
  162.  
  163.         for (counter_i=0; counter_i<8; counter_i++){
  164.             for (counter_b=0; counter_b<8; counter_b++){
  165.                 if((counter_i+counter_b)%2==0) continue; // לא משבצת לבנה
  166.                 if(location.i == counter_i || location.b == counter_b) continue; // לא באותה שורה או עמודה
  167.                 if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color != empty) continue;  // היעד לא תפוס
  168.                 if(AVBTN(location.i,counter_i) != AVBTN(location.b,counter_b)) continue;  // אותו אלכסון
  169.                 direction_i=check_direction_on_the_axis(location.i,counter_i);
  170.                 direction_b=check_direction_on_the_axis(location.b,counter_b);
  171.                 flag=true;
  172.                 for(i=location.i+direction_i, b=location.b+direction_b;  i != counter_i; i+=direction_i, b+=direction_b){   // סריקה על הציר מהמלך ליעד האם יש אין חייל מאותו צבע והאם יש חייל אויב שאפשר לאכול
  173.                     if ((*this_board_P).DamkaArray[i][b].Soldier_Color == (*this_board_P).DamkaArray[location.i][location.b].Soldier_Color){
  174.                         flag = false;
  175.                         break;
  176.                     }
  177.                 }
  178.                 if (flag == false) continue; //  בדיקה באמצעות הלולאה האם יש צבע ידיד על הציר
  179.                 if ((*this_board_P).DamkaArray[i][b].Soldier_Color == empty)
  180.                     if ((*this_board_P).DamkaArray[i-direction_i][b-direction_b].Soldier_Color == enemy_color) //  && i-direction_i != location.i  //    enemy_color אין צורך בבדיקה הזאת שלא יחשוב שהוא אוכל את עצמו - משום שאם זה היה הוא עצמו אז זה לא היה
  181.                         return true;
  182.                
  183.             }
  184.         }
  185.  
  186.         return false;
  187.     }
  188.  
  189.     else{
  190.         if ((*this_board_P).DamkaArray[location.i][location.b].AteBefore == true){
  191.             //  נבדוק כל פעם כיוון אחד מארבעת הכיוונים האפשריים האם לאותו כיוון אפשר לאכול
  192.             if(location.i+2 < 8 && location.b+2 <8){
  193.                 if((*this_board_P).DamkaArray[location.i+2][location.b+2].Soldier_Color == empty){
  194.                     if ((*this_board_P).DamkaArray[location.i+1][location.b+1].Soldier_Color == enemy_color) return true;
  195.                 }
  196.             }
  197.  
  198.             if(location.i+2 < 8 && location.b-2 >=0){
  199.                 if((*this_board_P).DamkaArray[location.i+2][location.b-2].Soldier_Color == empty){
  200.                     if ((*this_board_P).DamkaArray[location.i+1][location.b-1].Soldier_Color == enemy_color) return true;
  201.                 }
  202.             }
  203.  
  204.             if(location.i-2 >=0 && location.b-2 >=0){
  205.                 if((*this_board_P).DamkaArray[location.i-2][location.b-2].Soldier_Color == empty){
  206.                     if ((*this_board_P).DamkaArray[location.i-1][location.b-1].Soldier_Color == enemy_color) return true;
  207.                 }
  208.             }
  209.  
  210.             if(location.i-2 >0 && location.b+2 <8){
  211.                 if((*this_board_P).DamkaArray[location.i-2][location.b+2].Soldier_Color == empty){
  212.                     if ((*this_board_P).DamkaArray[location.i-1][location.b+1].Soldier_Color == enemy_color) return true;
  213.                 }
  214.             }
  215.             return false;
  216.         }
  217.  
  218.         else{
  219.             if((*this_board_P).DamkaArray[location.i][location.b].Soldier_Color == White){ // כאן נבדוק אכילה לכיוונים האפשריים של לבן
  220.  
  221.                 if(location.i-2 >=0 && location.b-2 >=0){
  222.                     if((*this_board_P).DamkaArray[location.i-2][location.b-2].Soldier_Color == empty){
  223.                         if ((*this_board_P).DamkaArray[location.i-1][location.b-1].Soldier_Color == enemy_color) return true;
  224.                     }
  225.                 }
  226.                 if(location.i-2 >0 && location.b+2 <8){
  227.                     if((*this_board_P).DamkaArray[location.i-2][location.b+2].Soldier_Color == empty){
  228.                         if ((*this_board_P).DamkaArray[location.i-1][location.b+1].Soldier_Color == enemy_color) return true;
  229.                     }
  230.                 }
  231.             }
  232.             else{ // כאן נבדוק אכילה לכיוונים האפשריים של שחור
  233.                 if(location.i+2 < 8 && location.b+2 <8){
  234.                     if((*this_board_P).DamkaArray[location.i+2][location.b+2].Soldier_Color == empty){
  235.                         if ((*this_board_P).DamkaArray[location.i+1][location.b+1].Soldier_Color == enemy_color) return true;
  236.                     }
  237.                 }
  238.  
  239.                 if(location.i+2 < 8 && location.b-2 >=0){
  240.                     if((*this_board_P).DamkaArray[location.i+2][location.b-2].Soldier_Color == empty){
  241.                         if ((*this_board_P).DamkaArray[location.i+1][location.b-1].Soldier_Color == enemy_color) return true;
  242.                     }
  243.                 }
  244.             }
  245.             return false;
  246.         }
  247.     }
  248. }
  249.  
  250. /*
  251. LocationsArray locations_on_the_board_that_can_move(Color turn_color, Board * this_board_P){
  252.     //
  253.     //מקבל צבע ומצביע ללוח ובודק איזה חיילים מאותו צבע יכולים לזוז באופן שלא חוסמים אותם
  254.     //ואם זה לא מהלך הריגה אז בודק שאין חייל אחר שיכול להרוג. אם יש חייל אחר שיכול להרוג אז זה לא חוקי כי שרוף
  255.     //מחזיר מערך של מקומות חוקיים
  256.     //
  257.    
  258.     LocationsArray a;
  259.     int Arr_i;
  260.     int counter_i, counter_b;
  261.  
  262.     for (counter_i=0; counter_i<8; counter_i++){
  263.         for (counter_b=0; counter_b<8; counter_b++){
  264.             if ((counter_i+counter_b)%2==1){//  תנאי ראשון - המקום חייב משבצת שחורה
  265.                 if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color==turn_color){ // תנאי שני - החייל צריך להיות בצבע התור
  266.  
  267.  
  268.  
  269.                 }
  270.  
  271.             }
  272.  
  273.         }
  274.     }
  275.  
  276.  
  277.  
  278.     return a;
  279.  
  280. }
  281. */
  282.  
  283.  
  284. bool is_this_soldier_can_do_a_legal_move(a_location location, Board * this_board_P){
  285.     int counter_i, counter_b;
  286.     FromTo move;
  287.     move.i1 = location.i;
  288.     move.b1 = location.b;
  289.     for(counter_i=0; counter_i<8; counter_i++){
  290.         for(counter_b=0; counter_b<8; counter_b++){
  291.             if((counter_i+counter_b)%2==0 || counter_i==location.i || counter_b==location.b) continue;
  292.             move.i2 = counter_i;
  293.             move.b2 = counter_b;
  294.             if (rules(move, this_board_P, false)==good) return true;
  295.         }
  296.     }
  297.     return false;
  298. }
  299.  
  300.  
  301.  
  302.  
  303.  
  304. void print_Error_type(errors en){
  305.     if (en==good) return;
  306.     cout<< "\n**Error found:\n";
  307.     switch(en) {
  308.     case bad_arguments:                cout<<"Error: bad arguments\n"; break;
  309.     case first_location_empty:         cout<<"Error: first location empty\n"; break;
  310.     case second_location_not_empty:    cout<<"Error: second location not empty\n"; break;
  311.     case bad_direction:                cout<<"Error: bad direction\n"; break;
  312.     case Not_in_the_same_diagonal:     cout<<"Error: Not in the same diagonal\n"; break;
  313.     case second_location_is_a_white_square:      cout<<"Error: second location is a white square\n"; break;
  314.     case opponent_tries_to_eat_himself:cout<<"Error: opponent tries to eat himself\n"; break;
  315.     case Skipping:                     cout<<"Error: Skipping\n"; break;
  316.     case error_in_check_direction_on_the_axis_F: cout<<"Error: error_in_check_direction_on_the_axis_F\n"; break;
  317.     case king_tries_to_eat_2_or_more:  cout<<"Error: king tries to eat 2 or more\n"; break;
  318.     case king_did_not_stop_immediately_after_soldier:   cout<<"Error: king did not stop immediately after a soldier\n"; break; // אופציונלי
  319.     case Is_it_sharsheret_in_rules_F_was_a_lie: {       cout<<"Error: This is sharsheret move. Only: ";   //  הדפסה יפה של השחקן היחיד שאמור להיות מסוגל לעשות שרשרת עכשיו לאחר המהלך הקודם
  320.         int counter_i, counter_b;
  321.         bool find_sharsheret_soldier=false;
  322.         for(counter_i=0; counter_i<8; counter_i++){
  323.             for(counter_b=0; counter_b<8; counter_b++){
  324.                 if(Real_Damka_soldiers.DamkaArray[counter_i][counter_b].AteBefore==true) {
  325.                     find_sharsheret_soldier=true;
  326.                     break;
  327.                 }
  328.             }
  329.             if (find_sharsheret_soldier==true) break;
  330.         }
  331.         cout<<(char)(counter_b+'A')<<(char)(counter_i+'1')<<" can move (and eat) now.\n";
  332.         break;
  333.                                                 }
  334.     case after_sharsheret_move_must_be_again_kill_move: cout<<"Error: After a sharsheret move must be again a kill move\n"; break; 
  335.     case Must_eat_when_possible:       cout<<"Error: Must eat when possible\n"; break;
  336.  
  337.     }
  338.  
  339.     cout<<"\n\n";
  340. }
  341.  
  342. a_location get_location_from_user_and_convert_to_numbers(char *input, char *FirstOrSecond){
  343.     a_location location_in_numbers;
  344.  
  345.                 while (!((input[0]>='A'&&input[0]<='H' && input[1]>='1'&&input[1]<='8') ||
  346.                     (input[0]>='a'&&input[0]<='h' && input[1]>='1'&&input[1]<='8') ||
  347.                     (input[1]>='A'&&input[1]<='H' && input[0]>='1'&&input[0]<='8') ||
  348.                     (input[1]>='a'&&input[1]<='h' && input[0]>='1'&&input[0]<='8'))){
  349.                         cout<<"*Enter a legal "<<FirstOrSecond<<" location:  ";
  350.                         cin>>input;
  351.                 }
  352.  
  353.                 if(input[0]>='A'&&input[0]<='H'){
  354.                     location_in_numbers.b=input[0]-'A';
  355.                     location_in_numbers.i=input[1]-'1';
  356.                 }
  357.                 else if(input[0]>='a'&&input[0]<='h'){  // h לפי אסקי אפשר לוותר על הבדיקה של
  358.                     location_in_numbers.b=input[0]-'a';
  359.                     location_in_numbers.i=input[1]-'1';
  360.                 }
  361.                 else if(input[1]>='A'&&input[1]<='H'){
  362.                     location_in_numbers.b=input[1]-'A';
  363.                     location_in_numbers.i=input[0]-'1';
  364.                 }
  365.                 else{// if(input[1]>='a'&&input[1]<='h')  //אין צורך לכתוב       // h לפי אסקי אפשר לוותר על הבדיקה של
  366.                     location_in_numbers.b=input[1]-'a';
  367.                     location_in_numbers.i=input[0]-'1';
  368.                 }
  369.  
  370.         return location_in_numbers;
  371. }
  372.  
  373. FromTo Get_From_User(Color turn_color, bool *Is_it_sharsheret=false){  //  מחזיר מהלך שתואם את כל החוקים
  374.     char strFirst[3];
  375.     char strSecond[3];
  376.     FromTo user_move;
  377.     a_location location_A;
  378.     errors ff;
  379.     if (turn_color==White) cout<<"White move!\n"; else cout<<"Black move!\n";
  380.  
  381.     if(*Is_it_sharsheret == true){  //  כל זה כדי שאם זה עכשיו מהלך שרשרת אז נלך ישר לקלט רק של היעד
  382.  
  383.         int counter_i, counter_b;
  384.         bool find_sharsheret_soldier=false;
  385.         for(counter_i=0; counter_i<8; counter_i++){
  386.             for(counter_b=0; counter_b<8; counter_b++){
  387.                 if(Real_Damka_soldiers.DamkaArray[counter_i][counter_b].AteBefore==true) {
  388.                     find_sharsheret_soldier=true;
  389.                     break;
  390.                 }
  391.             }
  392.             if (find_sharsheret_soldier==true) break;
  393.         }
  394.  
  395.         user_move.i1=counter_i;
  396.         user_move.b1=counter_b;  //  המונה עצר על הראשון - שאמור להיות גם היחיד - שכתוב לו שהוא אכל במהלך האחרון
  397.  
  398.         do{
  399.             cout<<"Enter second location:  ";
  400.             cin>>strSecond;
  401.             location_A = get_location_from_user_and_convert_to_numbers(strSecond, "second");
  402.             user_move.i2 = location_A.i;
  403.             user_move.b2 = location_A.b;
  404.             // עד כאן קלטנו מאיפו ולאן
  405.  
  406.  
  407.             ff = rules (user_move, &Real_Damka_soldiers, true);
  408.             print_Error_type(ff);
  409.         }while(ff!=good);
  410.     }
  411.  
  412.     else{  // אם זה לא מהלך שרשרת
  413.     regret:
  414.         do{
  415.             cout<<"Enter first location:  ";
  416.             cin>>strFirst;
  417.             location_A = get_location_from_user_and_convert_to_numbers(strFirst, "first");
  418.         }while (is_this_soldier_can_do_a_legal_move(location_A, &Real_Damka_soldiers)==false ||
  419.             (Real_Damka_soldiers.DamkaArray[location_A.i][location_A.b].Soldier_Color!=turn_color)); // בודק שבמיקום אכן נמצא שחקן מאותו צבע שיכול ללכת בצורה חוקית - כלומר אם זה לא מהלך אכילה אז שאף כלי אחר מאותו צבע לא יוכל לאכול
  420.        
  421.         user_move.i1 = location_A.i;
  422.         user_move.b1 = location_A.b;
  423.         //  עד כאן המקום הראשון הוא בצבע של בעל התור - שזה אומר לא יריב ולא לבן
  424.  
  425.         while(1){
  426.             cout<<"Enter second location:  ";
  427.             cin>>strSecond;
  428.             if(strSecond[0] == 'r' || strSecond[0] == 'R') goto regret;
  429.             location_A = get_location_from_user_and_convert_to_numbers(strSecond, "second");
  430.             user_move.i2 = location_A.i;
  431.             user_move.b2 = location_A.b;
  432.  
  433.             ff = rules (user_move, &Real_Damka_soldiers, false);
  434.             if(ff==good) break;
  435.             print_Error_type(ff);
  436.         }
  437.  
  438.     }
  439.  
  440.  
  441.     //  עד כאן מוצא ויעד תקינים.
  442.  
  443.     if(check_Future_possibility_for_sharsheret(user_move, Real_Damka_soldiers)==true){
  444.         char sharsheret_check[2];
  445.         do{
  446.             cout<<"Will it be a sharsheret move? (Y/N):  ";
  447.             cin>>sharsheret_check;
  448.         }while(sharsheret_check[0]!='n' && sharsheret_check[0]!='N' && sharsheret_check[0]!='y' && sharsheret_check[0]!='Y');
  449.  
  450.         if(sharsheret_check[0]=='y'|| sharsheret_check[0]=='Y'){
  451.             *Is_it_sharsheret=true;
  452.         }
  453.         else{
  454.             *Is_it_sharsheret=false;
  455.         }
  456.     }
  457.     else *Is_it_sharsheret=false;
  458.     return user_move;
  459. }
  460.  
  461.  
  462.  
  463.  
  464. char convert_to_symbol(int i, int b){  //  מקבל מקום במערך הדמקה ומחזיר סמל
  465.     if(Real_Damka_soldiers.DamkaArray[i][b].Soldier_Color == White){
  466.         if(Real_Damka_soldiers.DamkaArray[i][b].king==false) return 'W';
  467.         else  return (char)233; // מלך
  468.     }
  469.     if(Real_Damka_soldiers.DamkaArray[i][b].Soldier_Color == Black){
  470.         if(Real_Damka_soldiers.DamkaArray[i][b].king==false) return 'B';
  471.         else  return 232;
  472.     }
  473.     else {
  474.         if((i+b)%2==1) return 176; // ה 176 זה הצבע של השחור
  475.         else return 177;
  476.     }
  477. }
  478.  
  479. void Print_Damka(){
  480.     int i,a,b;
  481.     cout<<"\n  ABCDEFGH";
  482.     for(i=0; i<8; i++){
  483.         for(b=0;b<8;b++){
  484.             if(b%8==0) cout<<"\n";
  485.             if(b==0)cout<<i+1<<" ";  //מיספור
  486.             cout<<convert_to_symbol(i,b);
  487.         }
  488.     }
  489.     cout<<"\n  ABCDEFGH\n\n";  
  490. }
  491.  
  492. void Order_First_Damka(){
  493.     int i,a,b;
  494.     for(i=0; i<3; i++){
  495.         for(b=0;b<8;b++){
  496.             if ((i+b)%2==1){
  497.                 Real_Damka_soldiers.DamkaArray[i][b].Soldier_Color=Black;
  498.             }
  499.         }
  500.     }
  501.     for(i=5; i<8; i++){
  502.         for(b=0;b<8;b++){
  503.             if ((i+b)%2==1){
  504.                 Real_Damka_soldiers.DamkaArray[i][b].Soldier_Color=White;
  505.             }
  506.         }
  507.     }
  508.  
  509.     /*
  510.     // עבור בדיקת המלכים
  511.     for(b=0; b<8; b+=2){
  512.     Real_Damka_soldiers.DamkaArray[5][b].king=true;
  513.     }
  514.     */ 
  515. }
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524. unsigned int  AVBTN(int a, int b){  // Absolute_value_between_two_numbers // ערך מוחלט
  525.     if(a>b) return a-b;
  526.     else return b-a;
  527. }
  528.  
  529. void Clear_soldier(int i, int b, Board * this_board_P){
  530.     (*this_board_P).DamkaArray[i][b].king = false;
  531.     (*this_board_P).DamkaArray[i][b].AteBefore = false;   // זה כנראה יהיה מיותר
  532.     (*this_board_P).DamkaArray[i][b].Soldier_Color = empty;
  533. }
  534.  
  535. Color check_soldier_color_between_two_location(int i1, int b1, int i2, int b2, Board * this_board_P){ // שימו לב שצריכה להיות בדיוק משבצת אחת ביניהם  //  פונקציה לא שימושית. הכנסתי כבר בתוך פונקציית העברה
  536.     return (*this_board_P).DamkaArray[(i1+i2)/2][(b1+b2)/2].Soldier_Color;
  537. }
  538.  
  539. int check_direction_on_the_axis(int exit_point, int aim_point){  // עולים או יורדים i/b בדיקת כיוון על הציר, האם מהיעד למטרה הפרמטרים של ציר  
  540.     if (aim_point - exit_point>0) return 1;   // עולים
  541.     if (aim_point - exit_point<0) return -1;  // יורדים
  542.     print_Error_type(error_in_check_direction_on_the_axis_F);  // עבור אם הם באותו מקום
  543.     return error_in_check_direction_on_the_axis_F ;
  544. }
  545.  
  546.  
  547.  
  548. bool is_it_a_kill_move(FromTo a_move, Board * this_board_P){
  549.     // תדפיס ארור check_direction_on_the_axis  אסור לו לקבל שהמקום הראשון והשני יהיו זהים כי אם כן אז פונקציית
  550.    
  551.     bool a_kill=false;
  552.     Color this_color = (*this_board_P).DamkaArray[a_move.i1][a_move.b1].Soldier_Color;
  553.     Color enemy_color = (this_color==White)? Black : White ;
  554.  
  555.     int direction_i=check_direction_on_the_axis(a_move.i1,a_move.i2); // יורדים. אם עולים יהיה 1 i יהיה 1- אם מהיעד למטרה ערכי ציר ה
  556.     int direction_b=check_direction_on_the_axis(a_move.b1,a_move.b2); // יורדים. אם עולים יהיה 1 b יהיה 1- אם מהיעד למטרה ערכי ציר ה
  557.     int counter_i, counter_b;
  558.  
  559.     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){
  560.         if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color==enemy_color) {
  561.             a_kill=true;
  562.             break;
  563.         }
  564.     }
  565.  
  566.     return a_kill;
  567.  
  568. }
  569.  
  570. void print_full_damka_details(Board * this_board_P){   // לבדיקות באגים
  571.     int counter_i, counter_b;
  572.     cout<<"\n";
  573.  
  574.     cout<<"damka colors: \n";
  575.     for(counter_i=0; counter_i<8; counter_i++){
  576.         for(counter_b=0; counter_b<8; counter_b++){
  577.             if ((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color==White) cout <<"W";
  578.             if ((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color==Black) cout <<"B";
  579.             if ((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color==empty){if((counter_i+counter_b)%2==1) cout <<(char)176; else cout <<(char)177;}
  580.         }
  581.         cout<<"\n";
  582.     }
  583.     cout<<"\n\n";
  584.  
  585.     cout<<"damka kings: \n";
  586.     for(counter_i=0; counter_i<8; counter_i++){
  587.         for(counter_b=0; counter_b<8; counter_b++){
  588.             if ((*this_board_P).DamkaArray[counter_i][counter_b].king == true) cout <<"m";
  589.             else cout<<(char)178;
  590.         }
  591.         cout<<"\n";
  592.     }
  593.     cout<<"\n\n";
  594.  
  595.     cout<<"damka Ate before: \n";
  596.     for(counter_i=0; counter_i<8; counter_i++){
  597.         for(counter_b=0; counter_b<8; counter_b++){
  598.             if ((*this_board_P).DamkaArray[counter_i][counter_b].AteBefore== true) cout <<"A";
  599.             else cout<<(char)178;
  600.         }
  601.         cout<<"\n";
  602.     }
  603.     cout<<"\n\n";
  604. }
  605.  
  606. bool check_Future_possibility_for_sharsheret(FromTo a_move,  Board  this_board){  //  בודק אם אחרי המהלך, אותו שחקן יוכל להמשיך למהלך שרשרת
  607.     // תחזיר ארור  is_it_a_kill_move אסור לו לקבל שהמקום הראשון והשני יהיו זהים כי אם כן אז פונקציית
  608.    
  609.     if (is_it_a_kill_move(a_move, &this_board)){
  610.         move_soldier(a_move, &this_board);
  611.  
  612.         int direction_i=check_direction_on_the_axis(a_move.i1,a_move.i2); // יורדים. אם עולים יהיה 1 i יהיה 1- אם מהיעד למטרה ערכי ציר ה
  613.         int direction_b=check_direction_on_the_axis(a_move.b1,a_move.b2); // יורדים. אם עולים יהיה 1 b יהיה 1- אם מהיעד למטרה ערכי ציר ה
  614.  
  615.         int counter_i, counter_b;
  616.         FromTo exmp;
  617.         exmp.i1 = a_move.i2;
  618.         exmp.b1 = a_move.b2;
  619.  
  620.  
  621.         for(counter_i=0; counter_i<8; counter_i++){
  622.             for(counter_b=0; counter_b<8; counter_b++){
  623.                 if ((counter_i + counter_b)%2==1){
  624.                     exmp.i2=counter_i;
  625.                     exmp.b2=counter_b;
  626.                     // cout<<"here rules.   exmp.i1: "<<exmp.i1<<"   exmp.b1: "<<exmp.b1<<"   exmp.i2: "<<exmp.i2<<"   exmp.b2: "<<exmp.b2<<"\n";
  627.                     if(rules(exmp, &this_board, true)==good){  // שלא חשבתי עליו לעומק true צריך לעקוב אחר ארגומנט ה
  628.                         if (is_it_a_kill_move(exmp, &this_board)==true){
  629.                             return true;
  630.                         }
  631.                     }
  632.                     else continue;
  633.                 }
  634.                 else continue;
  635.  
  636.  
  637.             }
  638.         }
  639.  
  640.  
  641.  
  642.     }
  643.  
  644.     else return false;
  645. }
  646.  
  647.  
  648.  
  649.  
  650.  
  651.  
  652.  
  653.  
  654. void move_soldier(FromTo this_move, Board * this_board_P){
  655.     //  לא תעבוד is_it_a_kill_move אסור לקבל מוצא ויעד זהים כי אם כן
  656.  
  657.     int i1 = this_move.i1;
  658.     int i2 = this_move.i2;
  659.     int b1 = this_move.b1;
  660.     int b2 = this_move.b2;
  661.  
  662.     int direction_i=check_direction_on_the_axis(i1,i2); // יורדים. אם עולים יהיה 1 i יהיה 1- אם מהיעד למטרה ערכי ציר ה
  663.     int direction_b=check_direction_on_the_axis(b1,b2); // יורדים. אם עולים יהיה 1 b יהיה 1- אם מהיעד למטרה ערכי ציר ה
  664.  
  665.  
  666.     if(is_it_a_kill_move(this_move, this_board_P)){
  667.         (*this_board_P).DamkaArray[i1][b1].AteBefore=true;  // מזיזים את המוצא ולא את היעד כי הוא תיכף יעבור ליעד
  668.     }
  669.  
  670.     (*this_board_P).DamkaArray[i2][b2] = (*this_board_P).DamkaArray[i1][b1];
  671.     Clear_soldier(i1, b1, this_board_P);
  672.     Clear_soldier(i2 - direction_i, b2 - direction_b, this_board_P); // אכילה. אם ההזזה הזו היא לא אכילה זה לא פגע בכלום
  673.  
  674.     if((i2==7&& (*this_board_P).DamkaArray[i2][b2].Soldier_Color== Black)||(i2==0 && (*this_board_P).DamkaArray[i2][b2].Soldier_Color== White))
  675.         (*this_board_P).DamkaArray[i2][b2].king=true;  // הפיכה למלך
  676.     /*
  677.     if(turn_color == White && sharsheret ==false) {turn_color=Black;}  // אחרי בדיקה שזה לא מהלך שרשרת, משנים צבע תור
  678.     else if(turn_color == Black && sharsheret ==false) turn_color=White;
  679.     */
  680.  
  681.     // צריך לשלוח מכאן לפונקציה שמטפלת במהלך שרשרת, בקליטה שלו, ובהודעות השגיעה  // // //
  682.  
  683.     // צריך להוסיף הגבלה של אכילה חובה- שרוף. אבל צריך לבדוק את החוקים קודם       // // //
  684.  
  685.     // צריך כאן פונקציה להיסטוריה   // // //
  686. }
  687.  
  688. errors rules (FromTo this_move, Board * this_board_P, bool Is_it_sharsheret){
  689.  
  690.     /*
  691.     הפונקציה בודקת שהעברה אפשרית, אם כן - מעבירה חיילים ומשיבה הצלחה
  692.     אחרת - משיבה כישלון ומחזירה את סוג הכישלון
  693.     סוגי כישלון:
  694.     המיקומים שקיבלנו הם מחוץ ללוח  .1
  695.     2.  הייעד כבר תפוס, או שהמוצא ריק
  696.     3.  היעד הוא משבצת לבנה
  697.     4.  המוצא והיעד לא על אותו אלכסון
  698.     5.  חייל (לא מלך) לבן יורד, או חייל שחור עולה. למעט מהלך שרשרת
  699.  
  700.     6.  :בחייל (לא מלך) עליו לדלג רק משבצת אלכסונית אחת. ואם הוא אוכל אז רק שתיים, ואז עלינו לבדוק שהאכילה תקינה
  701.     .יש בין המוצא ליעד חייל. והוא לא מאותו צבע
  702.  
  703.     הגעתי עד כאן
  704.     7.  :אם זה מלך אז הוא יכול ללכת כל מספר שורות (שהוכח כבר שהן בתוך המשחק) אבל בתנאי
  705.     .אין חיילים מאותו צבע בדרך
  706.     .אין יותר מחייל עוין אחד
  707.     .אופציונלי: עליו לעצור מייד אחרי חייל עויין בלי להתרחק ממנו
  708.  
  709.     */
  710.  
  711.  
  712.     /* לא צריך לבדוק את צבע כלי המוצא אם הוא תואם את צבע התור, כי זה כבר נקלט בפונקציית הקלט. שימו לב שהרבה מהפעולות כאן על צבעים היה אפשר לחסוך
  713.     באמצעות המשתנה הגלובלי של צבע התור
  714.     */
  715.  
  716.  
  717.  
  718.     int i1 = this_move.i1;
  719.     int i2 = this_move.i2;
  720.     int b1 = this_move.b1;
  721.     int b2 = this_move.b2;
  722.     Color this_color = (*this_board_P).DamkaArray[i1][b1].Soldier_Color;
  723.     Color second_square = (*this_board_P).DamkaArray[i2][b2].Soldier_Color;
  724.  
  725.  
  726.     if(i1>7||i1<0||b1>7||b1<0||i2>7||i2<0||b2>7||b2<0) return bad_arguments; // הכלים במקום שלא קיים  //  ייתכן שנמנע בקלט מהרקורסיה והמשתמש אפשרות שזה לא יהיה נכון, ואז אפשר לחסוך את הבדיקה הזאת
  727.     if(this_color == empty) return first_location_empty;  //  אגב זה בודק שהמקום הראשון לא לבן//  ייתכן שנמנע בקלט מהרקורסיה אפשרות שזה לא יהיה נכון, ואז אפשר לחסוך את הבדיקה הזאת
  728.     if((i2+b2)%2 == 0) return second_location_is_a_white_square;  // יש צורך לבדוק רק את המיקום השני, כי הראשון כבר יודעים שיש בו שחקן
  729.     if(second_square != empty) return second_location_not_empty; // בדיקה שהיעד ריק. אגב זה גם בודק שהמקום הראשון והשני לא זהים
  730.  
  731.     if(i1==i2||b1==b2) return Not_in_the_same_diagonal;
  732.     // :משתנים שיועילו בהמשך
  733.     int AV_i=AVBTN(i1,i2); // שמירת ההפרשים המוחלטים מועילה להמשך  // Absolute_value
  734.     int AV_b=AVBTN(b1,b2);
  735.     int direction_i=check_direction_on_the_axis(i1,i2); // יורדים. אם עולים יהיה 1 i יהיה 1- אם מהיעד למטרה ערכי ציר ה
  736.     int direction_b=check_direction_on_the_axis(b1,b2); // יורדים. אם עולים יהיה 1 b יהיה 1- אם מהיעד למטרה ערכי ציר ה
  737.     int counter_i, counter_b;
  738.  
  739.     if(AV_i!=AV_b) return Not_in_the_same_diagonal; //  בדיקה שזה על אותו אלכסון. נכונה גם עבור מלכים
  740.  
  741.  
  742.     bool a_kill_move = is_it_a_kill_move(this_move, this_board_P);
  743.     if (Is_it_sharsheret == true){  // יתכן שלא יהיה צריך את הבדיקה הזאת הראשונה
  744.         if((*this_board_P).DamkaArray[i1][b1].AteBefore == false) return Is_it_sharsheret_in_rules_F_was_a_lie;
  745.         if (a_kill_move==false) return after_sharsheret_move_must_be_again_kill_move ;
  746.     }
  747.  
  748.  
  749.     if((*this_board_P).DamkaArray[i1][b1].king == false){ // חייל ולא מלך
  750.         if ((this_color == White && i1<=i2 && (*this_board_P).DamkaArray[i1][b1].AteBefore == false)||  // אם זה שרשרת אז זה חוקי
  751.             (this_color == Black && i1>=i2 && (*this_board_P).DamkaArray[i1][b1].AteBefore == false))
  752.             return bad_direction;  // כיוון לא נכון של שחקן שהלך לכיוון שלו
  753.  
  754.         if(AV_i>2) return Skipping; // כמובן שגם יותר משתי משבצות זה תמיד דילוג עבור חייל רגיל
  755.         if(AV_i==2){ // נבדוק אם יש ביניהם חייל מאותו צד ואז זו פגיעה עצמית, או אם אין כלל חייל ואז זה דילוג
  756.             Color soldier_color_between_two_location = (*this_board_P).DamkaArray[(i1+i2)/2][(b1+b2)/2].Soldier_Color; // משתנה לחיסכון בפעולות         
  757.             if(soldier_color_between_two_location==empty) return Skipping;
  758.             if(this_color == soldier_color_between_two_location){  // בדיקה מה יש ביניהם. נכונה רק עבור הפרש של משפצת אחת בינהם. מה שנכון עבור חייל
  759.                 return opponent_tries_to_eat_himself;
  760.             }
  761.         }
  762.     }
  763.  
  764.     else{ // אם זה מלך
  765.         int Counting_soldiers_eaten=0;
  766.         Color enemy_color = (this_color==White)? Black : White ;
  767.         for(counter_i=i1+direction_i, counter_b=b1+direction_b; counter_i != i2; counter_i+=direction_i, counter_b+=direction_b){
  768.             if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color==this_color) return opponent_tries_to_eat_himself;
  769.             if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color==enemy_color){
  770.                 Counting_soldiers_eaten++;
  771.                 if (Counting_soldiers_eaten>1) return king_tries_to_eat_2_or_more;
  772.             }
  773.         }
  774.         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;  // השורה הזאת לא נכונה. צריך לבדוק למה.
  775.  
  776.         // צריך לדון בדיוק מה מותר ואסור למלך לעשות כדי לכתוב את זה.   //   /////   //   /////   //
  777.     }
  778.  
  779.     // מכאן זו בדיקת שרופים
  780.     a_location location;
  781.     location.i = i1;
  782.     location.b = b1;
  783.     if (a_kill_move==false){
  784.         for (counter_i=0; counter_i<8; counter_i++){
  785.             for(counter_b=0; counter_b<8; counter_b++){
  786.                 if((counter_b+counter_i)%2==0) continue;
  787.                 if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color != this_color) continue;
  788.                 location.i = counter_i;
  789.                 location.b = counter_b;
  790.                 if (is_this_soldier_can_do_a_kiil_move(location, this_board_P) == true) return Must_eat_when_possible;
  791.             }
  792.         }      
  793.     }
  794.  
  795.  
  796.     return good;
  797.  
  798. }
  799.  
  800.  
  801. void Check_for_victory(Board *this_board_P, Color turn_color){
  802.     //   אחרי שמסיימים מהלך הפונקציה הזאת מקבלת אא צבע התור של היריב ובודקת אם ניצחנו.  אסור להגיע לפונקציה אם עכשיו מהלך רשרת ושוב תורנו במקום תור היריב
  803.  
  804.     int black_kings = 0, white_kings = 0, black_soldiers = 0, white_soldiers = 0;
  805.     int counter_i, counter_b;
  806.  
  807.     for(counter_i=0; counter_i<8; counter_i++){  //  סריקה כמה חיילים ומלכים יש לכל צד
  808.         for(counter_b=0; counter_b<8; counter_b++){
  809.             if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color == Black){
  810.                 if ((*this_board_P).DamkaArray[counter_i][counter_b].king == true) black_kings++;
  811.                 else black_soldiers++;
  812.             }
  813.             if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color == White){
  814.                 if ((*this_board_P).DamkaArray[counter_i][counter_b].king == true) white_kings++;
  815.                 else white_soldiers++;
  816.             }
  817.         }
  818.     }
  819.  
  820.     if (black_kings+black_soldiers==0){
  821.         cout<<"------White won!------\n\n";
  822.         cout<<"White have:   "<<white_soldiers<<" soldiers,   "<<white_kings<<" kings \n\n";
  823.         getchar();
  824.         exit(0);
  825.     }
  826.     if (white_kings+white_soldiers==0){
  827.         cout<<"------Black won!------\n\n";
  828.         cout<<"Black have:   "<<black_soldiers<<" soldiers,   "<<black_kings<<" kings\n\n";
  829.         getchar();
  830.         exit(0);
  831.     }
  832.  
  833.  
  834.  
  835.     // אם התור עכשיו הוא של הלבנים - אם הם חסומים אז השחורים ניצחו. וכן להפך
  836.     a_location location;
  837.     bool flag = false;
  838.     for(counter_i=0; counter_i<8; counter_i++){
  839.         for(counter_b=0; counter_b<8; counter_b++){
  840.             if ((counter_i+counter_b)%2==0) continue;
  841.             if((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color == turn_color){ // כך זה לא ריק ומאותו הצבע
  842.                 location.i = counter_i;
  843.                 location.b = counter_b;
  844.                 if(is_this_soldier_not_stuck(location, this_board_P)){
  845.                     flag = true;
  846.                     break;
  847.                 }
  848.             }
  849.         }
  850.         if (flag == true) break;
  851.     }
  852.     if (flag == false){ // כלומר אם אין אף חייל בצבע התור שיכול לזוז
  853.         if(turn_color==White) cout<<"White stuck\n------Black won!------\n\n";
  854.         else cout<<"Black stuck\n------White won!------\n\n";
  855.         cout<<"White have:   "<<white_soldiers<<" soldiers,   "<<white_kings<<" kings \n";
  856.         cout<<"Black have:   "<<black_soldiers<<" soldiers,   "<<black_kings<<" kings\n\n";
  857.         getchar();
  858.         exit(0);
  859.     }
  860.  
  861.  
  862.  
  863.  
  864.  
  865.      //  זה מקרה מיוחד של תיקו מלך מול מלך
  866.     if(white_soldiers==0 && black_soldiers==0 && white_kings==1 && black_kings==1){
  867.         //  אם שני מלכים נשארו אז זה אמור להיות תיקו. בתנאי שהמלך שעכשיו תורו לא יכול לאכול את המלך השני
  868.        
  869.         a_location black_king_location, white_king_location;
  870.         for(counter_i=0; counter_i<8; counter_i++){
  871.             for(counter_b=0; counter_b<8; counter_b++){
  872.                 if((counter_i+counter_b)%2==0) continue;
  873.                 if ((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color == White){
  874.                     white_king_location.i = counter_i;
  875.                     white_king_location.b = counter_b;
  876.                 }
  877.                 if ((*this_board_P).DamkaArray[counter_i][counter_b].Soldier_Color == Black){
  878.                     black_king_location.i = counter_i;
  879.                     black_king_location.b = counter_b;
  880.                 }
  881.             }
  882.         } // עד כאן אנחנו יודעים את מיקום המלכים
  883.  
  884.         flag = false;
  885.         FromTo move_exm;
  886.         Board board_exm;
  887.         if(turn_color == White){
  888.             if(is_this_soldier_can_do_a_kiil_move(white_king_location, this_board_P) == false){
  889.                 //  // קיים תנאי נוסף: אם לא משנה מה המלך שעכשיו תורו יעשה - הוא תמיד יאכל מייד על ידי המלך השני - אז הוא הפסיד
  890.                
  891.                 move_exm.i1 = white_king_location.i;
  892.                 move_exm.b1 = white_king_location.b;
  893.                 for(counter_i=0; counter_i<8; counter_i++){
  894.                     for(counter_b=0; counter_b<8; counter_b++){
  895.                         move_exm.i2 = counter_i;
  896.                         move_exm.b2 = counter_b;
  897.                         if(rules(move_exm,this_board_P,false)!=good) continue;
  898.                         board_exm=(*this_board_P);
  899.                         move_soldier(move_exm, &board_exm);
  900.                         if(is_this_soldier_can_do_a_kiil_move(black_king_location, &board_exm)==false){
  901.                             flag = true; // כי זה תיקו משום שלא כל מהלך שהוא יעשה הוא יאכל
  902.                             break;
  903.                         }
  904.                     }
  905.                     if(flag==true) break;
  906.                 }
  907.             }
  908.         }
  909.         else{ // אם צבע התור זה שחור
  910.             if(is_this_soldier_can_do_a_kiil_move(black_king_location, this_board_P) == false){
  911.                 //  // קיים תנאי נוסף: אם לא משנה מה המלך שעכשיו תורו יעשה - הוא תמיד יאכל מייד על ידי המלך השני - אז הוא הפסיד
  912.                
  913.                 move_exm.i1 = black_king_location.i;
  914.                 move_exm.b1 = black_king_location.b;
  915.                 for(counter_i=0; counter_i<8; counter_i++){
  916.                     for(counter_b=0; counter_b<8; counter_b++){
  917.                         move_exm.i2 = counter_i;
  918.                         move_exm.b2 = counter_b;
  919.                         if(rules(move_exm,this_board_P,false)!=good) continue;
  920.                         board_exm=(*this_board_P);
  921.                         move_soldier(move_exm, &board_exm);
  922.                         if(is_this_soldier_can_do_a_kiil_move(white_king_location, &board_exm)==false){
  923.                             flag = true; // כי זה תיקו משום שלא כל מהלך שהוא יעשה הוא יאכל
  924.                             break;
  925.                         }
  926.                     }
  927.                     if(flag==true) break;
  928.                 }
  929.             }
  930.         }
  931.         if(flag == true){
  932.                     cout<<"------2 kings! it's a tie!------\n\n";
  933.                     getchar();
  934.                     exit(0);
  935.                 }
  936.     }
  937.  
  938.  
  939. }
  940.  
  941.  
  942.  
  943.  
  944.  
  945.  
  946. void main(){
  947.     char c = '"';
  948.     cout<<"(C) Created by a student NN  04/05/2017\n\nThis is v0.4.0 Damka game ("<<c<<"checkers"<<c<<") for 2 people.\nI hope you know the rules...\nOne more rule: king must stop immediately after the soldier he ate.\nIf you want to change your first selection, press R\n\n\n";
  949.  
  950.  
  951.     FromTo ff;
  952.  
  953.     // חוקים וקרדיט  והסבר על איך מתחרטים
  954.     Order_First_Damka();
  955.     bool Is_it_sharsheret = false;
  956.     Print_Damka();
  957.     do{
  958.         do{  //  מהלך של הלבנים
  959.             ff= Get_From_User(White, &Is_it_sharsheret);
  960.             move_soldier(ff, &Real_Damka_soldiers);
  961.             Print_Damka();
  962.             if (Is_it_sharsheret == false) Check_for_victory(&Real_Damka_soldiers, Black);
  963.         }while(Is_it_sharsheret);
  964.         Real_Damka_soldiers.DamkaArray[ff.i2][ff.b2].AteBefore=false;  // עבור מהלכי שרשרת שנגמרו - וגם סתם מהלכים רגילים
  965.         Is_it_sharsheret=false;
  966.  
  967.         do{  //  מהלך של השחורים
  968.             ff= Get_From_User(Black, &Is_it_sharsheret);
  969.             move_soldier(ff, &Real_Damka_soldiers);
  970.             Print_Damka();
  971.             if (Is_it_sharsheret == false) Check_for_victory(&Real_Damka_soldiers, White);
  972.         }while(Is_it_sharsheret);
  973.         Real_Damka_soldiers.DamkaArray[ff.i2][ff.b2].AteBefore=false;  // עבור מהלכי שרשרת שנגמרו - וגם סתם מהלכים רגילים
  974.         Is_it_sharsheret=false;
  975.  
  976.     }while(1);
  977.     }// צריך בדיקה שלא להכנס למצב אין סופי שצד אחד לא יכול לזוז - לדלג על התור שלו. ואם שניהם לא יכולים לזוז אז להכריז על תיקו
  978.  
  979.  
  980.  
  981. // באג:    אם אןמרים שהיה מהלך שרשרת - הוא לא יודע לאפיין שרק החייל שקודם זז יכול שוב לזוז, ולא אחרים
  982.  
  983. // להוסיף שרופים
  984. // להוסיף שאסור לחזור על אותו מהלך יותר מ3 פעמים
  985. //
Advertisement
Add Comment
Please, Sign In to add comment