Exemple #1
0
/*Simulates opponent’s coin being inserted into cell above available cell of column having number as that passed as argument*/
int preventWin(int a1[6][7],int a2[6][7],int a3[6][7],int a4[6][7],int n,int p)
{if (coinPos(n,a1)>=5)
	return 0;
 else
	{if ((-p*valRow(n,-p,(coinPos(n,a1)+1),a1)>=4)||(-p*valCol(n,-p,(coinPos(n,a1)+1),a2)>=4)||(-p*valLDia(n,-p,(coinPos(n,a1)+1),a3)>=4)||(-p*valRDia(n,-p,(coinPos(n,a1)+1),a4)>=4))
		return 1;
	else
		return 0;}
}
    ChangeDialogClass(wxWindow* parent, wxString name, int& dock, int& row, int& position, int& layer)
        : ChangeDialogGeneratedClass(parent, wxID_ANY,  "Change " + name) {
        wxGenericValidator valRow(&row);
        Row->SetValidator(valRow);

        wxGenericValidator valPosition(&position);
        Position->SetValidator(valPosition);

        wxGenericValidator valLayer(&layer);
        Layer->SetValidator(valLayer);

        TransferDataToWindow();
    }
Exemple #3
0
/*This function checks if there is a possibility of an immediate win by the computer in the immediate move */
int winMove(int a1[6][7],int a2[6][7],int a3[6][7],int a4[6][7],int p)
{int i,cp,flag=0;
 for(i=1;i<=7;i++)
	{if (a1[0][i-1]==0)
		{cp=coinPos(i,a1);
		if (p*valRow(i,p,cp,a1)>=4)
			{insRow(i,p,cp,a1);
			insCol(i,p,cp,a2);
			insLDia(i,p,cp,a3);
			insRDia(i,p,cp,a4);
			drawround(i-1,cp,ray,GREEN);
			++flag;
			return(1);}
		else if(p*valCol(i,p,cp,a2)>=4)
			{insRow(i,p,cp,a1);
			insCol(i,p,cp,a2);
			insLDia(i,p,cp,a3);
			insRDia(i,p,cp,a4);
			drawround(i-1,cp,ray,GREEN);
			++flag;
			return(1);}
		else if(p*valLDia(i,p,cp,a3)>=4)
			{insRow(i,p,cp,a1);
			insCol(i,p,cp,a2);
			insLDia(i,p,cp,a3);
			insRDia(i,p,cp,a4);
			drawround(i-1,cp,ray,GREEN);
			++flag;
			return(1);}
		else if(p*valRDia(i,p,cp,a4)>=4)
			{insRow(i,p,cp,a1);
			insCol(i,p,cp,a2);
			insLDia(i,p,cp,a3);
			insRDia(i,p,cp,a4);
			drawround(i-1,cp,ray,GREEN);
			++flag;
			return(1);}
		}
	}
 if (flag==0)
	return(0);
 else
	return(1);
}
Exemple #4
0
/*This function checks if there is a possibility of a win by the user in the user’s next move*/
int defMove(int a1[6][7],int a2[6][7],int a3[6][7],int a4[6][7],int p)
{int i,cp,flag=0;
 for(i=1;i<=7;i++)
	{if (a1[0][i-1]==0)
		{cp=coinPos(i,a1);
		if (p*valRow(i,-p,cp,a1)==-4)
			{insRow(i,p,cp,a1);
			insCol(i,p,cp,a2);
			insLDia(i,p,cp,a3);
			insRDia(i,p,cp,a4);
			++flag;
			return(1);}
		else if(p*valCol(i,-p,cp,a2)==-4)
			{insRow(i,p,cp,a1);
			insCol(i,p,cp,a2);
			insLDia(i,p,cp,a3);
			insRDia(i,p,cp,a4);
			++flag;
			return(1);}
		else if(p*valLDia(i,-p,cp,a3)==-4)
			{insRow(i,p,cp,a1);
			insCol(i,p,cp,a2);
			insLDia(i,p,cp,a3);
			insRDia(i,p,cp,a4);
			++flag;
			return(1);}
		else if(p*valRDia(i,-p,cp,a4)==-4)
			{insRow(i,p,cp,a1);
			insCol(i,p,cp,a2);
			insLDia(i,p,cp,a3);
			insRDia(i,p,cp,a4);
			++flag;
			 return(1);}
		}
	}
 if (flag==0)
	return(0);
 else
	return(1);
}
Exemple #5
0
/*It is only called if return value of defMove() is zer. Determines the move of the Computer*/
int genMove (int a1[6][7],int a2[6][7],int a3[6][7],int a4[6][7],int p)
{int posVal,max=0,i,opt,putCol=0,cp,pw[7],j=0,flag=0,k;
 opt=random(5);
 for (i=0;i<7;i++)
	{if ((preventWin(a1,a2,a3,a4,(i+1),p)==1))
		{pw[j]=i;
		++j;}}
 switch(opt)
 {
 case 0:
 for(i=0;i<7;i++)
	{if (a1[0][i]!=0)
		 {posVal=0;
		 break;}
	 else
		{for(k=0;k<j;k++)
			{if(i==k)
				{posVal=0;
				++flag;}}
		if(flag==0)
			{cp=coinPos(i+1,a1);
			posVal=p*(valRow(i+1,p,cp,a1)+valCol(i+1,p,cp,a2)+valLDia(i+1,p,cp,a3)+valRDia(i+1,p,cp,a4));}
			if(posVal>max)
				putCol=i;}
	}
  case 1:
  for(i=0;i<7;i++)
	{if (a1[0][i]!=0)
		break;
	else
		{for(k=0;k<j;k++)
			{if(i==k)
				{posVal=0;
				++flag;}}
			if(flag==0)
				{cp=coinPos(i+1,a1);
				posVal=-p*(valRow(i+1,-p,cp,a1)+valCol(i+1,-p,cp,a2)+valLDia(i+1,-p,cp,a3)+valRDia(i+1,-p,cp,a4));}
			if(posVal>max)
				putCol=i;
			}
		}
 case 2:
 case 3:
 case 4:
  for(i=0;i<7;i++)
	{if (a1[0][i]==0)
		{for(k=0;k<j;k++)
			{if(i==k)
				{posVal=0;
				++flag;}}
		if (flag==0)
			{cp=coinPos(i+1,a1);
			posVal=-p*(valRow(i+1,-p,cp,a1)+valCol(i+1,-p,cp,a2)+valLDia(i+1,-p,cp,a3)+valRDia(i+1,-p,cp,a4))+p*(valRow(i+1,p,cp,a1)+valCol(i+1,p,cp,a2)+valLDia(i+1,p,cp,a3)+valRDia(i+1,p,cp,a4));}
		if(posVal>max)
			{putCol=i;
			max=posVal;}
		}
	}
 }
 return(putCol);
}