This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Oct 29th, 2012  |  syntax: None  |  size: 7.32 KB  |  views: 59  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Include
  2. # Include "eingabe.h"
  3. # Include
  4.  
  5.  
  6. initialisiere_2dim_int_array void (int row, int column, int array [row] [column], int initial value);
  7. initialisiere_int_array void (int array [], int len, int initial value);
  8. void display (int, int rows, columns, int playing field [row] [column]);
  9. int set (int row, int column, int playing field [rows] [columns], int selection, int player, int val);
  10. ueberpruefe_siegbedingung int (int, int rows, columns, int playing field [row] [column]);
  11. schreibe_2dim_int_array void (int, int rows, columns, int array [row] [column]);
  12. schreibe_int_array void (int array [], int len);
  13.  
  14.  
  15. int main (void)
  16. {
  17.     int spieler_1 = 1;
  18.     spieler_2 int = 2;
  19.     printf ("Please choose the number of columns [7-9]:");
  20.     int column = erfasse_ganze_zahl (7, 9);
  21.     printf ("Please choose the number of lines [6-9]:");
  22.     int row = erfasse_ganze_zahl (6, 9);
  23.     playing field int [rows] [columns];
  24.     int len ​​= sizeof (playing field) / sizeof (playing field [0]);
  25.     initialisiere_2dim_int_array (rows, columns, playing field, 0);
  26.     won int = 0;
  27.     int player = 1;
  28.     int value = 0;
  29.     int success = 0;
  30.     int winner = 0;
  31.     int choice = 0;
  32.     if (win == 0)
  33.     {
  34.         switch (player)
  35.         {
  36.             case 1:
  37.                 display (row, column, playing field);
  38.                 erfasse_ganze_zahl choices = (0, split);
  39.                 success = set (row, column, playing field, select, 1, 120);
  40.                 if (success == -1)
  41.                 {
  42.                     printf ("Error, train is not possible, please try again \ n");
  43.                     break;
  44.                 }
  45.                 victorious = ueberpruefe_siegbedingung (row, column, playing field);
  46.                 if (winner == 1)
  47.                     {
  48.                         printf ("check \ n");
  49.                         return 0;
  50.                     }
  51.                 printf ("Player 1's turn: Select a \ nSpalte, in which the token is to be thrown: \ n");
  52.                 player = 2;
  53.                 break;
  54.             case 2:
  55.                 display (row, column, playing field);
  56.                 erfasse_ganze_zahl choices = (0, split);
  57.                 success = set (row, column, playing field, select, 1, 111);
  58.                 if (success == -1)
  59.                 {
  60.                     printf ("Error, train is not possible, please try again \ n");
  61.                     break;
  62.                 }
  63.                 victorious = ueberpruefe_siegbedingung (row, column, playing field);
  64.                 if (winner == 1)
  65.                     {
  66.                         printf ("check \ n");
  67.                         return 0;
  68.                     }
  69.                 printf ("Player 2's turn: Select a \ nSpalte, in which the token is to be thrown: \ n");
  70.                 player = 1;
  71.                 break;
  72.         }
  73.     }
  74.     return 0;
  75. }
  76.  
  77.  
  78. int set (int row, int column, int playing field [rows] [columns], int selection, int player, int value)
  79. {
  80.     selection -;
  81.     for (int i = column - 1; i> = 0 i -)
  82.     {
  83.         if (playing field [i] [selection] == 0)
  84.         {
  85.             playing field [i] [selection] = value;
  86.             return 0;
  87.         }
  88.     }
  89.     return -1;
  90. }
  91.  
  92. initialisiere_2dim_int_array void (int row, int column, int array [row] [column], int initial value)
  93. {
  94.     for (int i = 0; row i <, i + +)
  95.         initialisiere_int_array (array [i] split, initial value);
  96. }
  97.  
  98. initialisiere_int_array void (int array [], int len, int initial value)
  99. {
  100.     for (int i = 0; i len <, i + +)
  101.         array [i] = initial value;
  102. }
  103.  
  104. schreibe_2dim_int_array void (int row, int column, int array [row] [column])
  105. {
  106.     for (int i = 0; row i <, i + +)
  107.         schreibe_int_array (array [i], columns);
  108. }
  109.  
  110. schreibe_int_array void (int array [], int len)
  111. {
  112.     for (int i = 0; i len <, i + +)
  113.         printf ("% d", array [i]);
  114. }
  115.  
  116.  
  117.  
  118.  
  119. void display (int row, int column, int playing field [row] [column])
  120. {
  121.     int i, j, k = 0;
  122.     for (i = 0; column i <, i + +)
  123.     {
  124.         for (j = 0; row j <j + +)
  125.         {
  126.             printf ("% c", playing field [i] [j]);
  127.             printf ("|");
  128.             if (j == row - 1)
  129.             {
  130.                 printf ("\ n");
  131.                 for (k = 0; column k <, k + +)
  132.                     printf ("----");
  133.                 printf ("\ n");
  134.             }
  135.         }
  136.     }
  137. }
  138.  
  139. ueberpruefe_siegbedingung int (int row, int column, int playing field [row] [column])
  140. {
  141.     int vertical = 1 ;/ / (|)
  142.     int horizontal = 1 ;/ / (-)
  143.     diagonal1 int = 1 ;/ / (\)
  144.     diagonal2 int = 1 ;/ / (/)
  145.     char = player playing field [row] [column];
  146.     int i;
  147.     int j ;/ / horizontal
  148.      / / Check for vertical (|)
  149.     for (i = 0; playing field [i] [column] == player && i row <=, i + +)
  150.         Vertical + + ;/ / check down
  151.     printf ("\ n% d% d \ n \ n% d% d \ n", vertical, horizontal, diagonal1, diagonal2);
  152.     for (i = row; playing field [i] [column] == player && i> = 0 i -)
  153.         Vertical + + ;/ / check up
  154.     printf ("\ n% d% d \ n \ n% d% d \ n", vertical, horizontal, diagonal1, diagonal2);
  155.     if (vertical> = 4) return 1;
  156.     / / Check for horizontal (-)
  157.     for (j = split -1; playing field [row] [j] == player && j> = 0, j - Horizontal + +) ;/ / Check left
  158.         for (j = column +1; playing field [row] [j] == player && j <= 6, j + +, horizontal + +) ;/ / check right
  159.             if (horizontal> = 4) return 1;
  160.     / / Check for diagonal 1 (\)
  161.     for (i = row -1, j = column - 1; playing field [i] [j] == player && i> = 0 && j> = 0; diagonal1 + +, i -, j -) ;/ / up and left
  162.         for (i = row + 1, j + 1 = split; playing field [i] [j] == player && i <= 5 && j <= 6; diagonal1 + +, i + +, j + +) ;/ / down and right
  163.             if (diagonal1> = 4) return 1;
  164.     / / Check for diagonal 2 (/)
  165.     for (i = row -1, j = column +1; playing field [i] [j] == player && i> = 0 && j <= 6; diagonal2 + +, i -, j + +) ;/ / up and right
  166.         for (i = row + 1, j = split -1; playing field [i] [j] == player && i <= 5 && j> = 0; diagonal2 + +, i + +, j -) ;/ / up and left
  167.             if (diagonal2> = 4) return 1;
  168.     printf ("\ n% d% d \ n \ n% d% d \ n", vertical, horizontal, diagonal1, diagonal2);
  169. return 0;
  170. }
clone this paste RAW Paste Data