Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- void show_table(int n[3][3]);
- int check(int n[3][3]);
- int wstawX(int n[3][3]);
- int wstawO(int n[3][3]);
- int wstawKropki(int n[3][3]);
- using namespace std;
- int main(){
- int x,y,board[3][3];
- wstawKropki(board);
- do{
- wstawX(board);
- show_table(board);
- wstawO(board);
- show_table(board);
- }while(1==1);
- return 0;
- }
- void show_table(int n[3][3]){
- cout << "*******\n";
- for(int i=0;i<3;i++){
- cout << "*";
- for(int j=0;j<3;j++) cout << n[i][j] << "|";
- cout << "\n*******\n";
- }
- }
- int check(int n[3][3]){
- int i,j,sum;
- for(i=0;i<3;i++){
- sum=0;
- for(j=0;j<2;j++) if(n[i][j]==n[i][j+1]) sum++;
- if(sum==2) return n[i][j]; //pion
- sum=0;
- for(j=0;j<2;j++) if(n[j][i]==n[j+1][i]) sum++;
- if(sum==2) return n[j][i]; // poziom
- }
- i=0;
- for(i=0;i<2;i++){
- sum=0;
- if(n[i][i]==n[i+1][i+1]) sum++;
- if(sum==2) return n[i][i];
- sum=0;
- if(n[3-i][i]==n[3-(i+1)][i+1]) sum++;
- if(sum==2) return n[3-i][i];
- }
- sum = 0;
- for(i=0;i<3;i++) for(j=0;j<3;j++) if(n[i][j]!=0) sum++;
- if(sum==9) return 3;
- return 0;
- }
- int wstawX(int n[3][3]){
- int x,y;
- do{
- cout << "podaj wspolrzedna x: ";
- cin >> x;
- cout << "podaj wspolrzedna y: ";
- cin >> y;
- if(n[y-1][x-1]==0){
- n[y-1][x-1] = 1;
- break;
- }
- }while(1==1);
- return n[3][3];
- }
- int wstawO(int n[3][3]){
- int x,y;
- do{
- cout << "podaj wspolrzedna x: ";
- cin >> x;
- cout << "podaj wspolrzedna y: ";
- cin >> y;
- if(n[y-1][x-1]==0){
- n[y-1][x-1] = 2;
- break;
- }
- }while(1==1);
- return n[3][3];
- }
- int wstawKropki(int n[3][3]){
- for(int i=0;i<3;i++) for(int j=0;j<3;j++) n[i][j] = 0;
- return n[3][3];
- }
Add Comment
Please, Sign In to add comment