Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Include
- # Include "eingabe.h"
- # Include
- initialisiere_2dim_int_array void (int row, int column, int array [row] [column], int initial value);
- initialisiere_int_array void (int array [], int len, int initial value);
- void display (int, int rows, columns, int playing field [row] [column]);
- int set (int row, int column, int playing field [rows] [columns], int selection, int player, int val);
- ueberpruefe_siegbedingung int (int, int rows, columns, int playing field [row] [column]);
- schreibe_2dim_int_array void (int, int rows, columns, int array [row] [column]);
- schreibe_int_array void (int array [], int len);
- int main (void)
- {
- int spieler_1 = 1;
- spieler_2 int = 2;
- printf ("Please choose the number of columns [7-9]:");
- int column = erfasse_ganze_zahl (7, 9);
- printf ("Please choose the number of lines [6-9]:");
- int row = erfasse_ganze_zahl (6, 9);
- playing field int [rows] [columns];
- int len = sizeof (playing field) / sizeof (playing field [0]);
- initialisiere_2dim_int_array (rows, columns, playing field, 0);
- won int = 0;
- int player = 1;
- int value = 0;
- int success = 0;
- int winner = 0;
- int choice = 0;
- if (win == 0)
- {
- switch (player)
- {
- case 1:
- display (row, column, playing field);
- erfasse_ganze_zahl choices = (0, split);
- success = set (row, column, playing field, select, 1, 120);
- if (success == -1)
- {
- printf ("Error, train is not possible, please try again \ n");
- break;
- }
- victorious = ueberpruefe_siegbedingung (row, column, playing field);
- if (winner == 1)
- {
- printf ("check \ n");
- return 0;
- }
- printf ("Player 1's turn: Select a \ nSpalte, in which the token is to be thrown: \ n");
- player = 2;
- break;
- case 2:
- display (row, column, playing field);
- erfasse_ganze_zahl choices = (0, split);
- success = set (row, column, playing field, select, 1, 111);
- if (success == -1)
- {
- printf ("Error, train is not possible, please try again \ n");
- break;
- }
- victorious = ueberpruefe_siegbedingung (row, column, playing field);
- if (winner == 1)
- {
- printf ("check \ n");
- return 0;
- }
- printf ("Player 2's turn: Select a \ nSpalte, in which the token is to be thrown: \ n");
- player = 1;
- break;
- }
- }
- return 0;
- }
- int set (int row, int column, int playing field [rows] [columns], int selection, int player, int value)
- {
- selection -;
- for (int i = column - 1; i> = 0 i -)
- {
- if (playing field [i] [selection] == 0)
- {
- playing field [i] [selection] = value;
- return 0;
- }
- }
- return -1;
- }
- initialisiere_2dim_int_array void (int row, int column, int array [row] [column], int initial value)
- {
- for (int i = 0; row i <, i + +)
- initialisiere_int_array (array [i] split, initial value);
- }
- initialisiere_int_array void (int array [], int len, int initial value)
- {
- for (int i = 0; i len <, i + +)
- array [i] = initial value;
- }
- schreibe_2dim_int_array void (int row, int column, int array [row] [column])
- {
- for (int i = 0; row i <, i + +)
- schreibe_int_array (array [i], columns);
- }
- schreibe_int_array void (int array [], int len)
- {
- for (int i = 0; i len <, i + +)
- printf ("% d", array [i]);
- }
- void display (int row, int column, int playing field [row] [column])
- {
- int i, j, k = 0;
- for (i = 0; column i <, i + +)
- {
- for (j = 0; row j <j + +)
- {
- printf ("% c", playing field [i] [j]);
- printf ("|");
- if (j == row - 1)
- {
- printf ("\ n");
- for (k = 0; column k <, k + +)
- printf ("----");
- printf ("\ n");
- }
- }
- }
- }
- ueberpruefe_siegbedingung int (int row, int column, int playing field [row] [column])
- {
- int vertical = 1 ;/ / (|)
- int horizontal = 1 ;/ / (-)
- diagonal1 int = 1 ;/ / (\)
- diagonal2 int = 1 ;/ / (/)
- char = player playing field [row] [column];
- int i;
- int j ;/ / horizontal
- / / Check for vertical (|)
- for (i = 0; playing field [i] [column] == player && i row <=, i + +)
- Vertical + + ;/ / check down
- printf ("\ n% d% d \ n \ n% d% d \ n", vertical, horizontal, diagonal1, diagonal2);
- for (i = row; playing field [i] [column] == player && i> = 0 i -)
- Vertical + + ;/ / check up
- printf ("\ n% d% d \ n \ n% d% d \ n", vertical, horizontal, diagonal1, diagonal2);
- if (vertical> = 4) return 1;
- / / Check for horizontal (-)
- for (j = split -1; playing field [row] [j] == player && j> = 0, j - Horizontal + +) ;/ / Check left
- for (j = column +1; playing field [row] [j] == player && j <= 6, j + +, horizontal + +) ;/ / check right
- if (horizontal> = 4) return 1;
- / / Check for diagonal 1 (\)
- for (i = row -1, j = column - 1; playing field [i] [j] == player && i> = 0 && j> = 0; diagonal1 + +, i -, j -) ;/ / up and left
- for (i = row + 1, j + 1 = split; playing field [i] [j] == player && i <= 5 && j <= 6; diagonal1 + +, i + +, j + +) ;/ / down and right
- if (diagonal1> = 4) return 1;
- / / Check for diagonal 2 (/)
- for (i = row -1, j = column +1; playing field [i] [j] == player && i> = 0 && j <= 6; diagonal2 + +, i -, j + +) ;/ / up and right
- for (i = row + 1, j = split -1; playing field [i] [j] == player && i <= 5 && j> = 0; diagonal2 + +, i + +, j -) ;/ / up and left
- if (diagonal2> = 4) return 1;
- printf ("\ n% d% d \ n \ n% d% d \ n", vertical, horizontal, diagonal1, diagonal2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement