package Matrix2P;

/**
 * Author: Max Buegler - max@sarstech.com
 * Date: Sep 28, 2009
 * Time: 4:01:09 PM
 */
public class GameMatrix {
    private double[][] p1,p2;

    public GameMatrix(double[][] p1){
        this.p1=p1;
        this.p2=new double[p1.length][p1[0].length];
        for (int x=0;x<p1.length;x++)
            for (int y=0;y<p1[x].length;y++)p2[x][y]=-p1[x][y];
        printMatrix();
    }
    public GameMatrix(double[][] p1, double[][] p2){
        this.p1 = p1;
        this.p2 = p2;
        printMatrix();
    }
    
    public double[][] getTransposedP1(){
        double[][]out=new double[p1[0].length][p1.length];
        for (int x=0;x<p1.length;x++){
            for (int y=0;y<p1[0].length;y++){
                out[y][x]=p1[x][y];
            }
        }
        return out;
    }
    public void printMatrix(){
        for (int x=0;x<p1.length;x++){
            System.out.print(" [ ");
            for (int y=0;y<p1[x].length;y++){
                System.out.print(""+p1[x][y]+","+p2[x][y]+"\t\t");
                //if (y<p1[x].length-1)System.out.print(",");
            }
            System.out.println(" ]");
        }
        System.out.println();

    }

    public int getP1BestReply(int p2action){
        double max=-Double.MAX_VALUE;
        int maxaction=-1;
        for (int x=0;x<p1.length;x++){
            if (p1[x][p2action]>max){
                max=p1[x][p2action];
                maxaction=x;
            }
        }
        return maxaction;
    }

    public int getP2BestReply(int p1action){
        double max=-Double.MAX_VALUE;
        int maxaction=-1;
        for (int y=0;y<p2[0].length;y++){
            if (p2[p1action][y]>max){
                max=p2[p1action][y];
                maxaction=y;
            }
        }
        return maxaction;
    }
    
    public int getActionsP1(){
        return p1.length;
    }
    public int getActionsP2(){
        return p1[0].length;
    }
    public double[][] getP1() {
        return p1;
    }
    public double[][] getP2() {
        return p2;
    }
}
