package cn.edu.nju.software.jksc.symys.algorithm;

import cn.edu.nju.software.jksc.symys.common.Bobble;
import cn.edu.nju.software.jksc.symys.common.exception.ParameterInvalidException;

/**
 * Created by 缪晓伟 on 2015/6/18.
 */
public class MapGenerator
{
	private static GeneratingAlgorithm[][] algorithmMatrix;

	static
	{
		algorithmMatrix=new GeneratingAlgorithm[7][5];
		algorithmMatrix[3][1]=new Algorithm3x3_1();
		algorithmMatrix[3][2]=new Algorithm3x3_2();
		algorithmMatrix[3][4]=new Algorithm3x3_4();
		algorithmMatrix[4][1]=new Algorithm4x4_1();
		algorithmMatrix[4][2]=new Algorithm4x4_2();
		algorithmMatrix[4][4]=new Algorithm4x4_4();
		algorithmMatrix[5][1]=new Algorithm5x5_1();
		algorithmMatrix[5][2]=new Algorithm5x5_2();
		algorithmMatrix[5][4]=new Algorithm5x5_4();
		algorithmMatrix[6][1]=new Algorithm6x6_1();
		algorithmMatrix[6][2]=new Algorithm6x6_2();
		algorithmMatrix[6][4]=new Algorithm6x6_4();
	}

	public static Bobble[][] generate(int gridSize,int numOfAxis,int numOfMix,int step)
	{
		if(gridSize<3||gridSize>6||numOfAxis<1||numOfAxis>4)
			return null;

		if(numOfAxis==3)
			numOfAxis=4;

		Bobble[][] ret;
		try
		{
			ret=algorithmMatrix[gridSize][numOfAxis].generate(numOfMix);
		}
		catch(ParameterInvalidException e)
		{
			e.printStackTrace();
			return null;
		}

		//For redundancy
		algorithmMatrix[gridSize][numOfAxis].swap(ret,(int)(step/1.5f));

		return ret;
	}
}

@@ -1140,16 +1140,26 @@
 et;%0A
+%09%09do%0A%09%09%7B%0A%09
 %09%09try%0A%09%09
 %7B%0A%09%09
@@ -1154,18 +1154,20 @@
 %09%09try%0A%09%09
+%09
 %7B%0A
+%09
 %09%09%09ret=a
@@ -1224,18 +1224,20 @@
 Mix);%0A%09%09
+%09
 %7D%0A
+%09
 %09%09catch(
@@ -1267,18 +1267,20 @@
 on e)%0A%09%09
+%09
 %7B%0A
+%09
 %09%09%09e.pri
@@ -1294,24 +1294,25 @@
 Trace();%0A%09%09%09
+%09
 return null;
@@ -1314,17 +1314,112 @@
 null;%0A%09%09
-%7D
+%09%7D%0A%09%09//In case of initial symmetrical situation%0A%09%09%7Dwhile(AxisChecker.countAxis(ret)==numOfAxis);
 %0A%0A%09%09//Fo

Optimize logic symmetric generating