Saddle Point For Game Theory in C++

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

//Program For Game Theory TO Check Whether The Saddle Point is Present or Not.
#include<iostream.h>
#include<conio.h>
#include<iomanip.h>
class game
{
private:
int A[100][100],i,j,minimax1,minimax2,maximin1,maximin2,max,min;
public :
void getdata(void);
void disp(void);
void calculate(void);
};
void game::getdata(void)
{
cout<<“\n\n Enter the 2X2 matrix…”;
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<“\n\n Enter the value for row “<<i+1<<” : “;
cin>>A[i][j];
}
}
}
void game::disp(void)
{
if(A[0][0]<=A[0][1])
{
minimax1 = A[0][0];
}
else
{
minimax1 = A[0][1];
}
if(A[1][0]<=A[1][1])
{
minimax2 = A[1][0];
}
else
{
minimax2 = A[1][1];
}
if(A[0][0]>=A[1][0])
{
maximin1 = A[0][0];
}
else
{
maximin1 = A[1][0];
}
if(A[0][1]>=A[1][1])
{
maximin2 = A[0][1];
}
else
{
maximin2 = A[1][1];
}
cout<<“\n\n Your Entered matrix is…\t\tRow”;
cout<<“\n\t\t\t\t MINIMAX”;
cout<<“\n\t\t\t ———–\n\t\t\t”;
for(i=0;i<2;i++)
{
cout<<” |”;
for(j=0;j<2;j++)
{
cout<<” “<<setw(2)<<A[i][j];
cout<<” |”;
}
if(i == 0)
{
cout<<” “<<minimax1;
}
else if(i == 1)
{
cout<<” “<<minimax2;
}
cout<<“\n\t\t\t ———–\n\t\t\t”;
}
cout<<“\n\t\t Col”;
cout<<“\n\t\t MAXIMIN “<<maximin1<<” “<<maximin2;
if(minimax1>=minimax2)
{
cout<<“\n\n\n MAXIMIN (the maximum value of minimax) is : “<<minimax1;
max = minimax1;
}
else
{
cout<<“\n\n\n MAXIMIN (the maximum value of minimax) is : “<<minimax2;
max = minimax2;
}
if(maximin1<=maximin2)
{
cout<<“\n\n\n MINIMAX (the minimum value of maximin) is : “<<maximin1;
min = maximin1;
}
else
{
cout<<“\n\n\n MINIMAX (the minimum value of maximin) is : “<<maximin2;
min = maximin2;
}

if(max == min)
{
cout<<“\n\n\n\n The MAXIMIN == MINIMAX ” ;
cout<<“\n\n\t So, the problem has saddle point”;
cout<<“\n\n\t hence game is of pure strategy.”;
}
else
{
cout<<“\n\n\n\n The MAXIMIN != MINIMAX ” ;
cout<<“\n\n\t So, the problem has no saddle point”;
cout<<“\n\n\t hence game is of mix strategy.”;
}
}
void main()
{
clrscr();
game g;
g.getdata();
g.disp();
getch();
}

output :

Enter the 2X2 matrix…

Enter the value for row 1 : 1
Enter the value for row 1 : 2
Enter the value for row 2 : 3
Enter the value for row 2 : 4

Your Entered matrix is… Row
MINIMAX
———-
| 1 | 2 | 1
———-
| 3 | 4 | 3
———-
Col
MAXIMIN 3 4

MAXIMIN (the maximum value of minimax) is : 3
MINIMAX (the minimum value of maximin) is : 3

The MAXIMIN == MINIMAX

So, the problem has saddle point
hence game is of pure strategy.

Leave a Reply

Your email address will not be published. Required fields are marked *