Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Functions.h"
- int main()
- {
- int remaining_lines,max_r,max_c;
- int grid[50][50];
- init(&max_r, &max_c, &remaining_lines);
- for(int i=0;i<max_r;i++)
- for(int j=0;j<max_c;j++)
- {
- grid[i][j]=0;
- }
- for(int i=0;i<12||i==12;i++)
- { one.turn=1;
- while(one.turn==1)
- {
- printf("it's %s 's turn\n", one.name);
- grid_move(grid,&max_r,&max_c,&remaining_lines);
- printf("\n\n player 1 score :%d\t\t player 2 score :%d\nplayer 1 remaining moves:%d\t\t player 2 remaining moves:%d\nremaining lines : %d\n\n",one.score,two.score,one.remainingmoves,two.remainingmoves,remaining_lines);
- one.turn--;
- }
- two.turn=1;
- while(two.turn==1)
- {
- printf("\n it's %s 's turn\n", two.name);
- grid_move(grid,&max_r,&max_c,&remaining_lines);
- printf("\n\n player 1 score :%d\t\t player 2 score :%d\nplayer 1 remaining moves:%d\t\t player 2 remaining moves:%d\nremaining lines : %d\n\n",one.score,two.score,one.remainingmoves,two.remainingmoves,remaining_lines);
- printf("%d",two.turn);
- two.turn--;
- }
- }
- }
- #include "functions.h"
- void init (int *max_r,int *max_c,int *remaining_lines)
- {
- int menu;
- printf("\t\t\t\t\t\tDots and Boxes\n\n\n\n\n");
- printf("\t\t\t\t 1-start game\n\n\t\t\t\t2-load game\n\n\t\t\t\t3-top 10 player\n\n\t\t\t\t 4-exit \n\n");
- scanf("%d",&menu);getchar();
- while(menu!=1&&menu!=2&&menu!=3&&menu!=4)
- {printf("please try again typing your choice correctly\a\n");
- scanf("%d",&menu);getchar();
- }
- if(menu==1)
- {
- int mode1,mode2;
- printf("choose \n1-one player \t\t2-two player\n");
- scanf("%d",&mode2);getchar();
- while(mode2!=1&&mode2!=2)
- {printf("please try again typing your choice correctly\a\n");
- scanf("%d",&mode2);getchar();
- }
- if(mode2==2)
- {
- printf("player 1 name: \n");
- scanf("\n");getchar();
- fgets(one.name,100,stdin);
- *one.name=strtok(one.name,"\n");
- printf("player 2 name: \n");
- fgets(two.name,100,stdin);
- *two.name=strtok(two.name,"\n");
- }
- //mode2 is 1 is missing
- printf("choose \n1-beginner \t\t 2-expert : ");
- scanf("%d",&mode1);getchar();
- while(mode1!=1&&mode1!=2)
- {printf("please try again typing your choice correctly\a\n");
- scanf("%d",&mode1);getchar();
- }
- if(mode1==1)
- {
- *max_r=9;//max rows with spaces
- *max_c=19;//max columns with spaces
- one.remainingmoves=beglines/2;
- two.remainingmoves=beglines/2;
- *remaining_lines=beglines;
- }
- else if(mode1==2)
- {
- *max_r=21;//max rows with spaces
- *max_c=46;//max columns with spaces
- one.remainingmoves=explines/2;
- two.remainingmoves=explines/2;
- *remaining_lines=explines;
- }
- }
- }
- #include "Functions.h"
- void grid_move(int grid[50][50],int *max_r,int *max_c,int *remaining_lines)
- {
- int tem,win1,win2;
- int count=0;
- int valid=0;
- int get_move[move_size];
- for(int i=0;i<(*max_r);i++)
- for(int j=0;j<(*max_c);j++)
- {
- if(i%4==0&&j%9==0)
- grid[i][j]=3; //3 for dots
- }
- printf("1-redo 2-move\n");
- scanf("%d",&rm);getchar();
- while(rm!=1&&rm!=2)
- {printf("please try again typing your choice correctly\a\n");
- scanf("%d",&rm);getchar();
- }
- if(rm==1)
- {
- if((*remaining_lines)==60)
- printf("redo can not be done");
- else
- redo( get_move);
- }
- if(rm==2)
- {
- while (count<4)
- { count=0;
- for(int i=0;i<move_size;i++)
- {
- scanf("%d",&get_move[i]);getchar();
- if(get_move[i]>(*max_r)/4+1||get_move[i]<1)
- { count--;
- printf("please try again\n\a");
- break;
- }
- else
- count++;
- }
- if(get_move[0]==get_move[1]&&get_move[3]==get_move[2])
- {count--; printf("please try again\n\a"); }
- else if(get_move[0]!=get_move[1]&&get_move[3]!=get_move[2])
- {count--; printf("please try again\n"); }
- else if(abs(get_move[0]-get_move[1])>1||abs(get_move[2]-get_move[3])>1)
- {count--; printf("please try again\n"); }
- }
- }
- if(rm!=1){
- for(int i=0;i<move_size;i++)
- {
- big[c]=get_move[i];
- c++;
- }
- }
- for(int i=0;i<move_size;i++)
- {
- if(i<1||i==1)
- get_move[i]=(get_move[i]-1)*4;
- if(i>1)
- get_move[i]=(get_move[i]-1)*9;
- }
- if(get_move[0]==get_move[1])
- {
- if(get_move[3]<get_move[2])
- {
- tem=get_move[3];
- get_move[3]=get_move[2];
- get_move[2]=tem;
- }
- for(int i=get_move[2]+1;i<get_move[3];i++)
- {if(rm==2)
- grid[get_move[1]][i]=1;
- if(rm==1)
- grid[get_move[1]][i]=0;
- // 1 for horizontal
- } // 1 for horizontal
- int constant =get_move[0];
- int start=get_move[2];
- int end=get_move[3];
- horizontal_win(constant,start,end,grid);
- }
- if(get_move[2]==get_move[3])
- {
- if(get_move[1]<get_move[0])
- {
- tem=get_move[1];
- get_move[1]=get_move[0];
- get_move[0]=tem;
- }
- for(int i=get_move[0]+1;i<get_move[1];i++)
- {if(rm==2)
- grid[i][get_move[2]]=2;
- if(rm==1)
- grid[i][get_move[2]]=0;
- // 2 for vertical
- } // 2 for vertical
- int constant =get_move[2];
- int start=get_move[0];
- int end=get_move[1];
- // putting numbers in the boxes :)
- vertical_win(constant,start,end,grid);
- }
- // int c=1;
- for(int i=0;i<(*max_r);i++)
- {
- { for(int j=0;j<(*max_c);j++)
- switch (grid[i][j])
- {
- case 1:printf("%c",196);
- break;
- case 2: printf("%c",179);
- break;
- case 3:printf("%c",254);
- break;
- case 4:printf("1");
- break;
- case 5:printf("2");
- break;
- default: printf(" ");
- break;
- }printf("\n");
- }}
- if (one.turn>0)
- one.remainingmoves--;
- if (two.turn>0)
- two.remainingmoves--;
- // current.remainingmoves--;
- (*remaining_lines)--;
- }
- #include "Functions.h"
- int horizontal_win(int constant ,int start,int end ,int grid[50][50])
- {
- int counter1=0;
- int counter2=0;
- if(grid[constant-1][start]==2)
- counter1++;
- if(grid[constant-4][start+1]==1)
- counter1++;
- if(grid[constant-1][end]==2)
- counter1++;
- if(counter1==3)
- {
- if (one.turn>1||one.turn==1)
- {grid[constant-2][start+4]=4;
- one.turn++;one.score++;}
- else if (two.turn>1||two.turn==1)
- {grid[constant-2][start+4]=5;
- two.turn++;two.score++;}
- }
- if(grid[constant+1][start]==2)
- {counter2++;}
- if(grid[constant+4][start+1]==1)
- {counter2++;}
- if(grid[constant+1][end]==2)
- {counter2++;}
- if(counter2==3)
- {
- if (one.turn>1||one.turn==1)
- {grid[constant+2][start+4]=4;
- one.turn++;one.score++;}
- else if (two.turn>1||two.turn==1)
- {grid[constant+2][start+4]=5;
- two.turn++;two.score++;}
- }
- }
- void redo( int get_move[move_size])
- {
- for(int i=0;i<move_size;i++)
- {
- get_move[3-i]=big[c-1];
- c--;
- }
- }
- #include "Functions.h"
- int vertical_win(int constant ,int start,int end ,int grid[50][50])
- {
- int counter1=0;
- int counter2=0;
- if(grid[start][constant-1]==1)
- counter1++;
- if(grid[start+1][constant-9]==2)
- counter1++;
- if(grid[end][constant-1]==1)
- counter1++;
- if(counter1==3)
- {
- if (one.turn>1||one.turn==1)
- {grid[start+2][constant-4]=4;
- one.turn++;one.score++;}
- else if (two.turn>1||two.turn==1)
- {grid[start+2][constant-4]=5;
- two.turn++;two.score++;}
- }
- if(grid[start][constant+1]==1)
- {counter2++;}
- if(grid[start+1][constant+9]==2)
- {counter2++;}
- if(grid[end][constant+1]==1)
- {counter2++;}
- if(counter2==3)
- {
- if (one.turn>1||one.turn==1)
- {grid[start+2][constant+4]=4;
- one.turn++;one.score++;}
- else if (two.turn>1||two.turn==1)
- {
- grid[start+2][constant+4]=5;
- two.turn++;two.score++;}
- }
- }
- #ifndef FUNCTIONS_H_INCLUDED
- #define FUNCTIONS_H_INCLUDED
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define explines 60
- #define beglines 12
- #define MAXBIG 100
- # define move_size 4
- #define total moves 12
- typedef struct
- {
- char name[100];
- int remainingmoves;
- int score;
- int turn;
- }player;
- player one;
- player two;
- extern int big[200];extern int c;extern int rm;
- void redo( int get_move[move_size]);
- void grid_move(int grid[50][50],int *max_r,int *max_c,int *remaining_lines);
- int vertical_win(int constant ,int start,int end ,int grid[50][50]);
- int horizontal_win(int constant ,int start,int end ,int grid[50][50]);
- void init (int *max_r,int *max_c,int *remaining_lines);
- #endif // FUNCTIONS_H_INCLUDED
- #include <stdio.h>
- #include <stdlib.h>
- int c=0;
- int big[200];
- int rm=0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement