import GenParamSamples
import os

method1 = "setWidth"
method2 = "setHeight"
method3 = "setRewardExponent"
method4 = "setPieceWeights"

paramf = open('params2.txt','r')
slist = paramf.readlines()
datalist = [s.split() for s in slist]
numberlist = [map(float,l) for l in datalist]
paramf.close()

# print("%f %f" % (numberlist[100][1],numberlist[100][11]))
for i in range(100):
#	os.remove('./src/TPMDP/TPMDP%d.java'% (i))
	f = open('./src/org/rlcommunity/environments/competition2009/Tetris/Proving/TPMDP%d.java'% (i),'w')

	f.write("""
/*
 * This code was auto-generated by the parameter script. Do not change these values manually.
 */
package org.rlcommunity.environments.competition2009.Tetris.Proving;

import org.rlcommunity.environments.competition2009.Tetris.GameState;
import org.rlcommunity.environments.competition2009.Tetris.TetrlaisPiece;
import java.util.Vector;
import org.rlcommunity.environments.competition2009.Tetris.Generalized.*;

public class TPMDP%d extends AbstractProvingMDPTetris{

    public TPMDP%d(){
	super();
	int width=0;
	int height=0;
	double []pieceWeights=null;
	double rewardExponent=1.0d;
	double evilness = 0.0d;
	int evilAgentType = 0;
	double benchmarkScore = 0.0;
		
	Vector<TetrlaisPiece> possibleBlocks=new Vector<TetrlaisPiece>();
        possibleBlocks.add(TetrlaisPiece.makeLine());
	possibleBlocks.add(TetrlaisPiece.makeSquare());
        possibleBlocks.add(TetrlaisPiece.makeTri());
	possibleBlocks.add(TetrlaisPiece.makeSShape());
	possibleBlocks.add(TetrlaisPiece.makeZShape());
	possibleBlocks.add(TetrlaisPiece.makeLShape());
	possibleBlocks.add(TetrlaisPiece.makeJShape());
""" % (i, i))
	width=numberlist[i][0]
	height=numberlist[i][1]+width
	rewardExponent=numberlist[i][2]
	pieceWeights=numberlist[i][3:10]
	evilness=numberlist[i][10]
	evilAgentType=numberlist[i][11]
	benchmarkScore=numberlist[i][12]
	f.write("""
	width=%d;
	height=%d;
	rewardExponent=%fd;
	evilness=%fd;
	evilAgentType=%d;
	benchmarkScore=%fd;
            """ % (width,  height, rewardExponent, evilness, evilAgentType, benchmarkScore))
	f.write("""
	pieceWeights=new double[]{%fd, %fd, %fd, %fd, %fd, %fd, %fd};
	GameState g=new GameState(width,height,possibleBlocks,pieceWeights,rewardExponent,evilness,evilAgentType,benchmarkScore);    
        super.gameState=g;
    }
}"""%(pieceWeights[0],pieceWeights[1],pieceWeights[2],pieceWeights[3],pieceWeights[4],pieceWeights[5],pieceWeights[6]))
	f.close()