Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string.h>
- using namespace std;
- bool validateInput(int x){
- return (x>0 && x<8)?true:false;
- }// to check whether input is between board dimensions
- void dropPiece(int (&droppedPieces)[7],int column,int (&board)[6][7],int player){
- column--;
- int row=6-droppedPieces[column]-1;
- board[row][column]=player;
- droppedPieces[column]=droppedPieces[column]+1;
- }
- void showBoard(int (&board)[6][7]){
- for(int i=0;i<6;i++){
- for(int j=0;j<7;j++){
- cout<<board[i][j]<<" ";
- }
- cout<<endl;
- }
- }
- /*
- int check(int (&board)[6][7],int player,int row){
- for(int i=0;i<6;i++){
- for(int j=0;j<7;j++){
- if(board[i][j]==player){
- }
- }
- }
- }
- */
- int checkHorizontal(int row,int column,int (&board)[6][7],int player,int (&droppedPieces)[7]){
- int count=0;
- int middle;
- bool flag=false;
- bool has=false;
- for(int i=0;i<7;i++){
- if(board[row][i]==player){
- count++;
- }
- else{
- count=0;
- }
- if(count==3){
- middle=i-1;
- has=true;
- }
- if(i==6 && count<3){
- flag=true;
- }
- }
- if(has==false && flag==true){
- return -1;
- }
- int left=middle-2;
- int right=middle+2;
- bool leftSolution=true,rightSolution=true;
- if(left<0){
- leftSolution=false;
- }
- if(right>=7){
- rightSolution=false;
- }
- if(leftSolution || rightSolution){
- if(!rightSolution){
- if(row=6-droppedPieces[left]-1){
- return left;
- }
- }
- if(!leftSolution){
- if(row=6-droppedPieces[right]-1){
- return right;
- }
- }
- }
- return -1;
- }
- /*
- checkVertical(int col,int (&board)[6][7],int player,int (&droppedPieces)[7]){
- int count=0;
- int oppo=(player==1)?2:1;
- bool available=true;
- for(int i=0;i<6;i++){
- if(board[i][col]==1){
- count++;
- }
- else{
- if(board[i][col]==2){
- oppo=i;
- }
- }
- if(droppedPieces[col]-(6-oppo)<3){
- available=false;
- return -1;
- }
- if(count==3 && available==true){
- return i;
- }
- }
- return -1;
- }
- */
- int main(){
- int board[6][7]={{0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0},
- {0,0,0,0,0,0,0}};//defaut :D
- int n=-1;//number of user input
- while(n<1 || n>10){
- cin>>n;
- }
- int firstMoves[n];//array to hold the input
- //now will drop the pieces of user
- //we will need an array of data to keep track of the thrown pieces
- int droppedPieces[7]; //0 dropped pieces in each column
- memset(droppedPieces,0,sizeof(droppedPieces));
- for(int i=0;i<n;i++){ //getting the input
- cin>>firstMoves[i];
- if(!validateInput(firstMoves[i])){
- i--;//if the input is not between board dimension,
- //lower 'i', in order to repeat the current input
- }
- }
- int player=1;
- //dropping first moves
- for(int i=0;i<n;i++){
- int temp=firstMoves[i];
- dropPiece(droppedPieces,temp,board,player);
- if(player==1){
- player=2;
- }
- else{
- player=1;
- }
- }
- /*
- bool finish=false;
- while(!finish){
- }
- */
- showBoard(board);
- cout<<endl<<endl<<endl<<"----------------------------------------\n";
- cout<<"Put row, colum,player\n";
- int a,b,c;
- cin>>a>>b>>c;
- cout<<checkHorizontal(a,b,board,c,droppedPieces);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement