package GUIs;

import GUIs.DivisionGUI;
import GUIs.CooperativeGUI;
import GUIs.WegaGUI;
import GUIs.WegaGUI3P;

import javax.swing.*;
import java.io.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;


/**
 * Author: Max Buegler - max@sarstech.com
 * Date: Sep 28, 2009
 * Time: 4:02:29 PM
 */
public class Main {
    private static final String VERSION="Wega Game Theory Toolbox 0.2q";
    public static final JTextArea CON=new JTextArea();
    public static final JFrame CONFRAME=new JFrame("Console");
    public static void main(String[] args){
        CONFRAME.setLayout(new GridLayout(1,1));
        JScrollPane pane=new JScrollPane(CON,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        pane.setAutoscrolls(true);
        CONFRAME.add(pane);
        CONFRAME.setSize(400,400);
        //CONFRAME.setVisible(true);
        
        class out extends FilterOutputStream{
            out(OutputStream out) {
                super(out);
            }

            public void write(byte b[]) throws IOException {
               String str = new String(b);
                CON.append(str);

             }

             public void write(byte b[], int off, int len) throws IOException {
               String str = new String(b, off, len);
               CON.append(str);
             }

             public void write(int b) throws IOException {
               String str = new String(new char[] { (char) b});
               CON.append(str);
             }
        }
        System.setOut(new PrintStream(new out(new ByteArrayOutputStream())));

        JFrame mainFrame=new JFrame("Wega");
        mainFrame.setLayout(new GridLayout(9,1));
        JLabel about=new JLabel(VERSION);
        about.setHorizontalAlignment(JLabel.CENTER);
        about.setVerticalAlignment(JLabel.CENTER);
        JLabel about2=new JLabel("Written 2009 by Max Bügler");
        JLabel about3=new JLabel("max@sarstech.com");
        JLabel about4=new JLabel("Bankruptcy problems written 2009 by Robbert Harms");
        JLabel about5=new JLabel("robbert@xkls.nl");

        about2.setHorizontalAlignment(JLabel.CENTER);
        about2.setVerticalAlignment(JLabel.CENTER);
        about3.setHorizontalAlignment(JLabel.CENTER);
        about3.setVerticalAlignment(JLabel.CENTER);
        about4.setHorizontalAlignment(JLabel.CENTER);
        about4.setVerticalAlignment(JLabel.CENTER);
        about5.setHorizontalAlignment(JLabel.CENTER);
        about5.setVerticalAlignment(JLabel.CENTER);

        mainFrame.add(about);
        mainFrame.add(about2);
        mainFrame.add(about3);
        mainFrame.add(about4);
        mainFrame.add(about5);
        JButton p1=new JButton("Bankruptcy problems");
        p1.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                new DivisionGUI();
            }
        });
        mainFrame.add(p1);
        JButton p4=new JButton("Cooperative games");
        p4.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                new CooperativeGUI(true);
            }
        });
        mainFrame.add(p4);
        JButton p2=new JButton("2 Player  matrix games");
        p2.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                new WegaGUI();
            }
        });
        mainFrame.add(p2);
        JButton p3=new JButton("3 Player matrix games (experimental)");
        p3.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                new WegaGUI3P();
            }
        });
        mainFrame.add(p3);
        mainFrame.setSize(400,300);
        mainFrame.setVisible(true);
        mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        /*double[][] p1=new double[][]{{1,2,3},
                                     {2,3,1},
                                     {3,1,2}};
        double[][] p2=new double[][]{{3,2,1},
                                     {2,1,3},
                                     {1,3,2}};
        new RegretMatching(new GameMatrix(p1,p2),0,0,0.2,0.2,0.0,10000);
        new FictitiousPlay(new GameMatrix(p1,p2),0,0,10000);

        p1=new double[][]{{4,2,-5},
                          {-2,-3,5},
                          {3,-1,2}};
        p2=new double[][]{{-3,-2,5},
                          {2,5,-3},
                          {5,3,-2}};
        //new RegretMatching(new GameMatrix(p1,p2),0,0,0.2,0.2,0.0,10000);
        //new FictitiousPlay(new GameMatrix(p1,p2),0,0,10000);

        p1=new double[][]{{4,2,-5,1,-3},
                          {-2,-3,5,2,5},
                          {3,-1,2,-3,-2},
                          {-2,-3,-5,-2,5},
                          {-2,-3,5,2,-5}};
        p2=new double[][]{{-4,-2,5,-1,3},
                          {2,-3,-5,-2,-5},
                          {-3,1,-2,3,2},
                          {5,3,5,2,-5},
                          {5,-3,-5,-2,5}};
        //new RegretMatching(new GameMatrix(p1,p2),0,0,0.2,0.2,0.0,10000);
        //new FictitiousPlay(new GameMatrix(p1,p2),0,0,10000);



        p1=new double[][]{{1,0,0},
                          {0,1,0},
                          {0,0,1}};
        p2=new double[][]{{0,0,1},
                          {1,0,0},
                          {0,1,0}};
        //new RegretMatching(new GameMatrix(p1,p2),0,0,0.5,0.5,0.0,10000);
        //new FictitiousPlay(new GameMatrix(p1,p2),0,0,10000);

        p1=new double[][]{{1            ,0},
                          {0            ,Math.sqrt(2)}};
        p2=new double[][]{{Math.sqrt(2) ,0},
                         {0             ,1}};

        //new RegretMatching(new GameMatrix(p1,p2),0,1,0.2,0.2,0.0,1000);
        //new FictitiousPlay(new GameMatrix(p1,p2),0,0,1000);

        p1=new double[][]{{ 1, 5},
                          { 0, 7},
                          { 4, 2},
                          { 6,-1}};

        //new RegretMatching(new GameMatrix(p1),0,0,0.2,0.2,0.0,10000);
        //new FictitiousPlay(new GameMatrix(p1),0,0,10000);
        //new SaddlePoints(new GameMatrix(p1));
        
        p1=new double[][]{{-3, 5},
                          { 0, 1}};
        //new SaddlePoints(new GameMatrix(p1));
        //new FictitiousPlay(new GameMatrix(p1),0,0,1000);
        //new RegretMatching(new GameMatrix(p1),0,0,0.5,0.5,0.0,1000);*/

    }

}
