text
stringlengths 30
1.67M
|
|---|
<s> package com . g4 . java . ending ; import java . util . List ; import com . g4 . java . model . Individual ; public interface EndingMethod { boolean shouldEnd ( List < Individual > population , int iterations ) ; } </s>
|
<s> package com . g4 . java ; import com . g4 . java . model . Individual ; import com . g4 . java . util . InputValues ; import com . g4 . java . util . RandomGenerator ; import com . g4 . matlab . ann . ANN ; import com . mathworks . toolbox . javabuilder . MWCellArray ; import com . mathworks . toolbox . javabuilder . MWException ; public class Backpropagation { private ANN ann ; private int iterations ; private double prob ; public Backpropagation ( ANN ann , int iterations , double prob ) { this . prob = prob ; this . ann = ann ; this . iterations = iterations ; } public Individual run ( Individual individual ) { Individual ret = new Individual ( ) ; Object [ ] matlabRet = null ; try { matlabRet = ann . backpropagation ( <NUM_LIT:1> , individual . getData ( ) , InputValues . getInstance ( ) . getInputs ( ) , InputValues . getInstance ( ) . getExpectedOutputs ( ) , iterations , FunctionResolver . ARCHITECTURE ) ; } catch ( MWException e ) { } ret . setData ( ( MWCellArray ) matlabRet [ <NUM_LIT:0> ] ) ; return ret ; } public boolean shouldApply ( ) { return RandomGenerator . getDouble ( ) < this . prob ; } } </s>
|
<s> package com . g4 . java ; import com . g4 . java . model . Individual ; import com . g4 . java . util . InputValues ; import com . g4 . matlab . ann . ANN ; import com . mathworks . toolbox . javabuilder . MWException ; import com . mathworks . toolbox . javabuilder . MWNumericArray ; public class Function { private ANN ann ; public Function ( ANN ann ) { this . ann = ann ; } public double eval ( Individual individual ) { double retVal ; try { Object [ ] ret = ann . evalANN ( <NUM_LIT:2> , individual . getData ( ) , InputValues . getInstance ( ) . getInputs ( ) , InputValues . getInstance ( ) . getExpectedOutputs ( ) , InputValues . getInstance ( ) . getInputsTest ( ) , InputValues . getInstance ( ) . getExpectedOutputsTest ( ) , FunctionResolver . ARCHITECTURE ) ; retVal = ( ( MWNumericArray ) ret [ <NUM_LIT:0> ] ) . getDouble ( <NUM_LIT:1> ) ; } catch ( MWException e ) { retVal = Double . MIN_VALUE ; } return retVal ; } } </s>
|
<s> package com . g4 . java . configuration ; import java . io . FileInputStream ; import java . io . FileNotFoundException ; import java . io . IOException ; import java . util . List ; import java . util . Properties ; import com . g4 . java . Backpropagation ; import com . g4 . java . configuration . factories . BackpropagationFactory ; import com . g4 . java . configuration . factories . CrossOverFactory ; import com . g4 . java . configuration . factories . EndingFactory ; import com . g4 . java . configuration . factories . MutationFactory ; import com . g4 . java . configuration . factories . ReplacementFactory ; import com . g4 . java . configuration . factories . SelectionFactory ; import com . g4 . java . crossover . Crossover ; import com . g4 . java . ending . EndingMethod ; import com . g4 . java . mutation . Mutation ; import com . g4 . java . selection . Selection ; import com . mathworks . toolbox . javabuilder . MWException ; public class Configuration { private Properties properties ; private int architecture ; private int popSize ; private double generationGap ; private EndingMethod ending ; private Mutation mutation ; private Backpropagation backpropagation ; private List < Selection > selectionMethods ; private List < Selection > replacementMethods ; private Crossover crossOver ; private MutationFactory mutationFactory ; private SelectionFactory selectionFactory ; private ReplacementFactory replacementFactory ; private CrossOverFactory crossOverFactory ; private EndingFactory endingFactory ; private BackpropagationFactory backpropagationFactory ; public Configuration ( String propertiesPath ) throws FileNotFoundException , IOException , MWException { this . properties = new Properties ( ) ; this . mutationFactory = new MutationFactory ( this . properties ) ; this . selectionFactory = new SelectionFactory ( this . properties ) ; this . replacementFactory = new ReplacementFactory ( this . properties ) ; this . crossOverFactory = new CrossOverFactory ( this . properties ) ; this . endingFactory = new EndingFactory ( this . properties ) ; this . backpropagationFactory = new BackpropagationFactory ( this . properties ) ; this . properties . load ( new FileInputStream ( System . getProperty ( "<STR_LIT>" ) + propertiesPath ) ) ; loadGeneralData ( ) ; loadMutationData ( ) ; loadBackpropagationData ( ) ; loadSelectionData ( ) ; loadReplacementData ( ) ; loadCrossOverData ( ) ; loadEndingData ( ) ; } private void loadGeneralData ( ) { this . architecture = Integer . valueOf ( this . properties . getProperty ( "<STR_LIT>" ) ) ; this . popSize = Integer . valueOf ( this . properties . getProperty ( "<STR_LIT>" ) ) ; this . generationGap = Double . valueOf ( this . properties . getProperty ( "<STR_LIT>" ) ) ; } private void loadBackpropagationData ( ) throws MWException { this . backpropagation = this . backpropagationFactory . loadBackpropagation ( ) ; } private void loadEndingData ( ) { this . ending = this . endingFactory . loadEnding ( ) ; } private void loadCrossOverData ( ) { this . crossOver = this . crossOverFactory . loadCrossOver ( ) ; } private void loadReplacementData ( ) { this . replacementMethods = this . replacementFactory . loadReplacementMethods ( ) ; } private void loadSelectionData ( ) { this . selectionMethods = this . selectionFactory . loadSelectionMethods ( ) ; } private void loadMutationData ( ) { this . mutation = this . mutationFactory . loadMutationList ( ) ; } public Mutation getMutation ( ) { return mutation ; } public Backpropagation getBackpropagation ( ) { return backpropagation ; } public List < Selection > getSelectionMethods ( ) { return selectionMethods ; } public List < Selection > getReplacementMethods ( ) { return replacementMethods ; } public Crossover getCrossOverMethods ( ) { return crossOver ; } public EndingMethod getEnding ( ) { return ending ; } public int getArchitecture ( ) { return architecture ; } public int getPopSize ( ) { return popSize ; } public double getGenerationGap ( ) { return generationGap ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; import java . util . Properties ; import com . g4 . java . crossover . AnularCrossover ; import com . g4 . java . crossover . Crossover ; import com . g4 . java . crossover . GeneCrossOver ; import com . g4 . java . crossover . MultipleCrossOver ; import com . g4 . java . crossover . ParameterizedUniformCrossOver ; import com . g4 . java . crossover . SinglePointCrossOver ; public class CrossOverFactory { private Properties properties ; public CrossOverFactory ( Properties properties ) { this . properties = properties ; } public Crossover loadCrossOver ( ) { Crossover crossover = null ; CrossOverEnum crossEnum = CrossOverEnum . getCrossOverEnum ( properties . getProperty ( "<STR_LIT>" ) . toUpperCase ( ) ) ; double crossoverProbability = <NUM_LIT> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { crossoverProbability = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } switch ( crossEnum ) { case ANULAR : crossover = new AnularCrossover ( crossoverProbability ) ; break ; case MULTIPLE_POINT : int cutPointsQty = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { cutPointsQty = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } crossover = new MultipleCrossOver ( crossoverProbability , cutPointsQty ) ; break ; case UNIFORM : double segmentedProb = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { segmentedProb = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } crossover = new ParameterizedUniformCrossOver ( crossoverProbability , segmentedProb ) ; break ; case CLASSIC : crossover = new SinglePointCrossOver ( crossoverProbability ) ; break ; case GENE : crossover = new GeneCrossOver ( crossoverProbability ) ; break ; } return crossover ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; import java . util . Properties ; import com . g4 . java . mutation . ClassicMutation ; import com . g4 . java . mutation . Mutation ; import com . g4 . java . mutation . NotUniformMutation ; public class MutationFactory { private Properties properties ; public MutationFactory ( Properties properties ) { this . properties = properties ; } public Mutation loadMutationList ( ) { MutationEnum mutEnum = MutationEnum . getMutationEnum ( properties . getProperty ( "<STR_LIT>" ) . toUpperCase ( ) ) ; Mutation mutation = null ; double mutationProbability = <NUM_LIT> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { mutationProbability = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } double alleleProb = <NUM_LIT> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { alleleProb = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } switch ( mutEnum ) { case CLASSIC : mutation = new ClassicMutation ( mutationProbability , alleleProb ) ; break ; case NOT_UNIFORM : double decreaseConstant = <NUM_LIT> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { decreaseConstant = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } int generationToDecrease = <NUM_LIT:10> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { generationToDecrease = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } mutation = new NotUniformMutation ( mutationProbability , generationToDecrease , decreaseConstant , alleleProb ) ; break ; } return mutation ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; public enum EndingEnum { MAXGENERATION ( "<STR_LIT>" ) , STRUCTURAL ( "<STR_LIT>" ) , CONTENT ( "<STR_LIT>" ) , OPTIMUM ( "<STR_LIT>" ) ; private String name ; private EndingEnum ( String name ) { this . name = name ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public static EndingEnum getEndingEnum ( String str ) { for ( EndingEnum rep : EndingEnum . values ( ) ) { if ( rep . getName ( ) . equals ( str ) ) return rep ; } return null ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; public enum MutationEnum { CLASSIC ( "<STR_LIT>" ) , NOT_UNIFORM ( "<STR_LIT>" ) ; private String name ; private MutationEnum ( String name ) { this . name = name ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public static MutationEnum getMutationEnum ( String str ) { for ( MutationEnum rep : MutationEnum . values ( ) ) { if ( rep . getName ( ) . equals ( str ) ) return rep ; } return null ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; import java . util . ArrayList ; import java . util . List ; import java . util . Properties ; import com . g4 . java . ending . ContentEnding ; import com . g4 . java . ending . EndingMethod ; import com . g4 . java . ending . MaxGenerationEnding ; import com . g4 . java . ending . MixEnding ; import com . g4 . java . ending . OptimumOrFitnessEnding ; import com . g4 . java . ending . StructuralEnding ; public class EndingFactory { private Properties properties ; public EndingFactory ( Properties properties ) { this . properties = properties ; } public EndingMethod loadEnding ( ) { List < EndingMethod > selected = new ArrayList < EndingMethod > ( ) ; String [ ] endings = properties . getProperty ( "<STR_LIT>" ) . split ( "<STR_LIT:/>" ) ; for ( int i = <NUM_LIT:0> ; i < endings . length ; i ++ ) { String endingMethod = endings [ i ] . trim ( ) . toUpperCase ( ) ; if ( endingMethod . equals ( EndingEnum . MAXGENERATION . getName ( ) ) ) { int iterationsToEnd = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { iterationsToEnd = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } selected . add ( new MaxGenerationEnding ( iterationsToEnd ) ) ; } else if ( endingMethod . equals ( EndingEnum . CONTENT . getName ( ) ) ) { double improvement = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { improvement = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } int iterationsToImprove = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { iterationsToImprove = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } selected . add ( new ContentEnding ( iterationsToImprove , improvement ) ) ; } else if ( endingMethod . equals ( EndingEnum . OPTIMUM . getName ( ) ) ) { double optimum = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { optimum = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } double tolerance = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { tolerance = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } selected . add ( new OptimumOrFitnessEnding ( optimum , tolerance ) ) ; } else if ( endingMethod . equals ( EndingEnum . STRUCTURAL . getName ( ) ) ) { int iterationsToCheck = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { iterationsToCheck = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } int percent = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { percent = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } int popSize = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { popSize = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } selected . add ( new StructuralEnding ( iterationsToCheck , percent , popSize ) ) ; } } return new MixEnding ( selected ) ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; public enum SelectionEnum { ELITE ( "<STR_LIT>" ) , RULETTE ( "<STR_LIT>" ) , UNIVERSAL ( "<STR_LIT>" ) , TOURNAMENT ( "<STR_LIT>" ) , BOLTZMAN ( "<STR_LIT>" ) ; private String name ; private SelectionEnum ( String name ) { this . name = name ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public static SelectionEnum getSelectionEnum ( String str ) { for ( SelectionEnum rep : SelectionEnum . values ( ) ) { if ( rep . getName ( ) . equals ( str ) ) return rep ; } return null ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; import java . util . Properties ; import com . g4 . java . Backpropagation ; import com . g4 . java . MatlabSingleton ; import com . mathworks . toolbox . javabuilder . MWException ; public class BackpropagationFactory { private Properties properties ; public BackpropagationFactory ( Properties properties ) { this . properties = properties ; } public Backpropagation loadBackpropagation ( ) throws MWException { double prob = <NUM_LIT:0> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { prob = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } int iterations = <NUM_LIT:30> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) { iterations = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; } return new Backpropagation ( MatlabSingleton . getInstance ( ) . getAnn ( ) , iterations , prob ) ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; import java . util . ArrayList ; import java . util . List ; import java . util . Properties ; import com . g4 . java . selection . BoltzmannSelection ; import com . g4 . java . selection . EliteSelection ; import com . g4 . java . selection . RuletteSelection ; import com . g4 . java . selection . Selection ; import com . g4 . java . selection . TournamentSelection ; import com . g4 . java . selection . UniversalSelection ; public class ReplacementFactory { private Properties properties ; public ReplacementFactory ( Properties properties ) { this . properties = properties ; } public List < Selection > loadReplacementMethods ( ) { List < Selection > replaced = new ArrayList < Selection > ( ) ; String [ ] replacements = properties . getProperty ( "<STR_LIT>" ) . split ( "<STR_LIT:/>" ) ; for ( int i = <NUM_LIT:0> ; i < replacements . length ; i ++ ) { String replacedMethod = replacements [ i ] . trim ( ) . toUpperCase ( ) ; if ( replacedMethod . equals ( SelectionEnum . ELITE . getName ( ) ) ) { int toSelect = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) toSelect = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; replaced . add ( new EliteSelection ( toSelect ) ) ; } else if ( replacedMethod . equals ( SelectionEnum . RULETTE . getName ( ) ) ) { int toSelect = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) toSelect = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; replaced . add ( new RuletteSelection ( toSelect ) ) ; } else if ( replacedMethod . equals ( SelectionEnum . TOURNAMENT . getName ( ) ) ) { int toSelect = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) toSelect = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; int tSize = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) tSize = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; replaced . add ( new TournamentSelection ( toSelect , tSize ) ) ; } else if ( replacedMethod . equals ( SelectionEnum . UNIVERSAL . getName ( ) ) ) { int toSelect = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) toSelect = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; replaced . add ( new UniversalSelection ( toSelect ) ) ; } else if ( replacedMethod . equals ( SelectionEnum . BOLTZMAN . getName ( ) ) ) { int toSelect = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) toSelect = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; double maxTemperature = <NUM_LIT:1000> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) maxTemperature = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; double minTemperature = <NUM_LIT:100> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) minTemperature = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; double decrement = <NUM_LIT:5> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) decrement = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; replaced . add ( new BoltzmannSelection ( maxTemperature , minTemperature , decrement , toSelect ) ) ; } } return replaced ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; public enum ReplacementEnum { ELITE ( "<STR_LIT>" ) , RULETTE ( "<STR_LIT>" ) , UNIVERSAL ( "<STR_LIT>" ) , TOURNAMENT ( "<STR_LIT>" ) , BOLTZMAN ( "<STR_LIT>" ) ; private String name ; private ReplacementEnum ( String name ) { this . name = name ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public static ReplacementEnum getReplacementEnum ( String str ) { for ( ReplacementEnum rep : ReplacementEnum . values ( ) ) { if ( rep . getName ( ) . equals ( str ) ) return rep ; } return null ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; public enum CrossOverEnum { CLASSIC ( "<STR_LIT>" ) , MULTIPLE_POINT ( "<STR_LIT>" ) , UNIFORM ( "<STR_LIT>" ) , ANULAR ( "<STR_LIT>" ) , GENE ( "<STR_LIT>" ) ; private String name ; private CrossOverEnum ( String name ) { this . name = name ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public static CrossOverEnum getCrossOverEnum ( String str ) { for ( CrossOverEnum rep : CrossOverEnum . values ( ) ) { if ( rep . getName ( ) . equals ( str ) ) return rep ; } return null ; } } </s>
|
<s> package com . g4 . java . configuration . factories ; import java . util . ArrayList ; import java . util . List ; import java . util . Properties ; import com . g4 . java . selection . BoltzmannSelection ; import com . g4 . java . selection . EliteSelection ; import com . g4 . java . selection . RuletteSelection ; import com . g4 . java . selection . Selection ; import com . g4 . java . selection . TournamentSelection ; import com . g4 . java . selection . UniversalSelection ; public class SelectionFactory { private Properties properties ; public SelectionFactory ( Properties properties ) { this . properties = properties ; } public List < Selection > loadSelectionMethods ( ) { List < Selection > selected = new ArrayList < Selection > ( ) ; String [ ] selections = properties . getProperty ( "<STR_LIT>" ) . split ( "<STR_LIT:/>" ) ; for ( int i = <NUM_LIT:0> ; i < selections . length ; i ++ ) { String selectedMethod = selections [ i ] . trim ( ) . toUpperCase ( ) ; if ( selectedMethod . equals ( SelectionEnum . ELITE . getName ( ) ) ) { int toSelect = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) toSelect = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; selected . add ( new EliteSelection ( toSelect ) ) ; } else if ( selectedMethod . equals ( SelectionEnum . RULETTE . getName ( ) ) ) { int toSelect = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) toSelect = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; selected . add ( new RuletteSelection ( toSelect ) ) ; } else if ( selectedMethod . equals ( SelectionEnum . TOURNAMENT . getName ( ) ) ) { int toSelect = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) toSelect = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; int tSize = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) tSize = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; selected . add ( new TournamentSelection ( toSelect , tSize ) ) ; } else if ( selectedMethod . equals ( SelectionEnum . UNIVERSAL . getName ( ) ) ) { int toSelect = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) toSelect = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; selected . add ( new UniversalSelection ( toSelect ) ) ; } else if ( selectedMethod . equals ( SelectionEnum . BOLTZMAN . getName ( ) ) ) { int toSelect = <NUM_LIT:1> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) toSelect = Integer . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; double maxTemperature = <NUM_LIT:1000> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) maxTemperature = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; double minTemperature = <NUM_LIT:100> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) minTemperature = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; double decrement = <NUM_LIT:5> ; if ( properties . getProperty ( "<STR_LIT>" ) != null ) decrement = Double . valueOf ( properties . getProperty ( "<STR_LIT>" ) ) ; selected . add ( new BoltzmannSelection ( maxTemperature , minTemperature , decrement , toSelect ) ) ; } } return selected ; } } </s>
|
<s> package com . g4 . java . util ; public class Pair < S , T > { private S o1 ; private T o2 ; public Pair ( S o1 , T o2 ) { this . o1 = o1 ; this . o2 = o2 ; } public S getO1 ( ) { return o1 ; } public T getO2 ( ) { return o2 ; } public void setO1 ( S o1 ) { this . o1 = o1 ; } public void setO2 ( T o2 ) { this . o2 = o2 ; } } </s>
|
<s> package com . g4 . java . util ; import java . util . Random ; public class RandomGenerator { public static Random random = new Random ( ) ; public static int getInt ( int lowerBound , int upperBound ) { if ( lowerBound == upperBound ) { return lowerBound ; } return random . nextInt ( upperBound - lowerBound ) + lowerBound ; } public static double getDouble ( double lowerBound , double upperBound ) { return random . nextDouble ( ) * Math . abs ( upperBound - lowerBound ) + Math . min ( lowerBound , upperBound ) ; } public static int getInt ( int upperBound ) { return random . nextInt ( upperBound ) ; } public static int getInt ( ) { return random . nextInt ( ) ; } public static double getDouble ( ) { return random . nextDouble ( ) ; } public static boolean getBoolean ( double trueProbalility ) { return random . nextDouble ( ) < trueProbalility ; } } </s>
|
<s> package com . g4 . java . util ; import java . util . List ; import com . g4 . java . model . Individual ; public class Printer { public static double mean ( double [ ] data ) { double mean = <NUM_LIT:0> ; final int n = data . length ; if ( n < <NUM_LIT:2> ) { return Double . NaN ; } for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { mean += data [ i ] ; } mean /= n ; return mean ; } public static double StandardDeviationMean ( double [ ] data ) { double mean = <NUM_LIT:0> ; final int n = data . length ; if ( n < <NUM_LIT:2> ) { return Double . NaN ; } for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { mean += data [ i ] ; } mean /= n ; double sum = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { final double v = data [ i ] - mean ; sum += v * v ; } return Math . sqrt ( sum / ( n - <NUM_LIT:1> ) ) ; } public static double standardDeviationCalculate ( double [ ] data ) { final int n = data . length ; if ( n < <NUM_LIT:2> ) { return Double . NaN ; } double avg = data [ <NUM_LIT:0> ] ; double sum = <NUM_LIT:0> ; for ( int i = <NUM_LIT:1> ; i < data . length ; i ++ ) { double newavg = avg + ( data [ i ] - avg ) / ( i + <NUM_LIT:1> ) ; sum += ( data [ i ] - avg ) * ( data [ i ] - newavg ) ; avg = newavg ; } return Math . sqrt ( sum / ( n - <NUM_LIT:1> ) ) ; } public double mean ( List < Individual > population ) { double [ ] list = new double [ population . size ( ) ] ; for ( int i = <NUM_LIT:0> ; i < list . length ; i ++ ) { list [ i ] = population . get ( i ) . getApptitude ( ) ; } return mean ( list ) ; } public double sdForIndividual ( List < Individual > population ) { double [ ] list = new double [ population . size ( ) ] ; for ( int i = <NUM_LIT:0> ; i < list . length ; i ++ ) { list [ i ] = population . get ( i ) . getApptitude ( ) ; } return standardDeviationCalculate ( list ) ; } } </s>
|
<s> package com . g4 . java . util ; import com . mathworks . toolbox . javabuilder . MWArray ; public class InputValues { private MWArray inputs ; private MWArray expectedOutputs ; private MWArray inputsTest ; private MWArray expectedOutputsTest ; private static InputValues instance = new InputValues ( ) ; public static InputValues getInstance ( ) { return instance ; } private InputValues ( ) { } public MWArray getInputs ( ) { return inputs ; } public void setInputs ( MWArray inputs ) { this . inputs = inputs ; } public MWArray getExpectedOutputs ( ) { return expectedOutputs ; } public void setExpectedOutputs ( MWArray expectedOutputs ) { this . expectedOutputs = expectedOutputs ; } public MWArray getInputsTest ( ) { return inputsTest ; } public void setInputsTest ( MWArray inputsTest ) { this . inputsTest = inputsTest ; } public MWArray getExpectedOutputsTest ( ) { return expectedOutputsTest ; } public void setExpectedOutputsTest ( MWArray expectedOutputsTest ) { this . expectedOutputsTest = expectedOutputsTest ; } } </s>
|
<s> package com . g4 . java . crossover ; import com . g4 . java . model . Individual ; import com . g4 . java . util . RandomGenerator ; public class AnularCrossover implements Crossover { private double prob ; public AnularCrossover ( double crossoverProbability ) { this . prob = crossoverProbability ; } @ Override public Individual [ ] cross ( Individual [ ] entities ) { double [ ] dad = entities [ <NUM_LIT:0> ] . getLupusArray ( ) ; double [ ] mom = entities [ <NUM_LIT:1> ] . getLupusArray ( ) ; double [ ] son1 = new double [ dad . length ] ; double [ ] son2 = new double [ dad . length ] ; int r = RandomGenerator . getInt ( <NUM_LIT:0> , dad . length ) ; int l = RandomGenerator . getInt ( <NUM_LIT:1> , dad . length / <NUM_LIT:2> ) ; int i ; for ( i = <NUM_LIT:0> ; i < mom . length && i < r ; i ++ ) { son1 [ i ] = dad [ i ] ; son2 [ i ] = mom [ i ] ; } for ( i = r ; i < mom . length && i < ( r + l ) ; i ++ ) { son2 [ i ] = mom [ i ] ; son1 [ i ] = dad [ i ] ; } if ( dad . length - ( r + l ) < <NUM_LIT:0> ) { for ( i = <NUM_LIT:0> ; i < ( ( r + l ) - dad . length ) ; i ++ ) { son2 [ i ] = mom [ i ] ; son1 [ i ] = dad [ i ] ; } } Individual newSon1 = Individual . creator ( entities [ <NUM_LIT:0> ] . getData ( ) , son1 ) ; Individual newSon2 = Individual . creator ( entities [ <NUM_LIT:0> ] . getData ( ) , son2 ) ; return new Individual [ ] { newSon1 , newSon2 } ; } @ Override public boolean shouldApply ( ) { return RandomGenerator . getDouble ( ) < this . prob ; } } </s>
|
<s> package com . g4 . java . crossover ; import com . g4 . java . model . Individual ; import com . g4 . java . util . RandomGenerator ; public class ParameterizedUniformCrossOver implements Crossover { private double prob ; private double crossProb ; public ParameterizedUniformCrossOver ( double prob , double crossProb ) { this . prob = prob ; this . crossProb = crossProb ; } @ Override public Individual [ ] cross ( Individual [ ] entities ) { double [ ] dad = entities [ <NUM_LIT:0> ] . getLupusArray ( ) ; double [ ] mom = entities [ <NUM_LIT:1> ] . getLupusArray ( ) ; double [ ] son1 = new double [ dad . length ] ; double [ ] son2 = new double [ dad . length ] ; for ( int i = <NUM_LIT:0> ; i < dad . length ; i ++ ) { son1 [ i ] = dad [ i ] ; son2 [ i ] = mom [ i ] ; } for ( int i = <NUM_LIT:0> ; i < dad . length ; i ++ ) { if ( RandomGenerator . getDouble ( ) < this . prob ) { double aux = son1 [ i ] ; son1 [ i ] = son2 [ i ] ; son2 [ i ] = aux ; } } Individual indSon1 = Individual . creator ( entities [ <NUM_LIT:0> ] . getData ( ) , son1 ) ; Individual indSon2 = Individual . creator ( entities [ <NUM_LIT:0> ] . getData ( ) , son2 ) ; return new Individual [ ] { indSon1 , indSon2 } ; } @ Override public boolean shouldApply ( ) { return RandomGenerator . getDouble ( ) < this . crossProb ; } } </s>
|
<s> package com . g4 . java . crossover ; import com . g4 . java . model . Individual ; public interface Crossover { Individual [ ] cross ( Individual [ ] entities ) ; boolean shouldApply ( ) ; } </s>
|
<s> package com . g4 . java . crossover ; import com . g4 . java . model . Individual ; import com . g4 . java . util . RandomGenerator ; public class SinglePointCrossOver implements Crossover { private double prob ; public SinglePointCrossOver ( double prob ) { this . prob = prob ; } public Individual [ ] cross ( Individual [ ] entities ) { double [ ] dad = entities [ <NUM_LIT:0> ] . getLupusArray ( ) ; double [ ] mom = entities [ <NUM_LIT:1> ] . getLupusArray ( ) ; double [ ] son1 = new double [ dad . length ] ; double [ ] son2 = new double [ dad . length ] ; int cutPoint = RandomGenerator . getInt ( <NUM_LIT:1> , dad . length ) ; for ( int i = <NUM_LIT:0> ; i < cutPoint ; i ++ ) { son1 [ i ] = dad [ i ] ; son2 [ i ] = mom [ i ] ; } for ( int i = cutPoint ; i < mom . length ; i ++ ) { son2 [ i ] = dad [ i ] ; son1 [ i ] = mom [ i ] ; } Individual indSon1 = Individual . creator ( entities [ <NUM_LIT:0> ] . getData ( ) , son1 ) ; Individual indSon2 = Individual . creator ( entities [ <NUM_LIT:0> ] . getData ( ) , son2 ) ; return new Individual [ ] { indSon1 , indSon2 } ; } @ Override public boolean shouldApply ( ) { return RandomGenerator . getDouble ( ) < this . prob ; } } </s>
|
<s> package com . g4 . java . crossover ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import com . g4 . java . model . Individual ; import com . g4 . java . util . RandomGenerator ; public class MultipleCrossOver implements Crossover { private int cutPointsCount ; private double prob ; public MultipleCrossOver ( double prob , int cutPointsQty ) { this . cutPointsCount = cutPointsQty ; this . prob = prob ; } @ Override public Individual [ ] cross ( Individual [ ] entities ) { double [ ] dad = entities [ <NUM_LIT:0> ] . getLupusArray ( ) ; double [ ] mom = entities [ <NUM_LIT:1> ] . getLupusArray ( ) ; double [ ] son1 = new double [ dad . length ] ; double [ ] son2 = new double [ dad . length ] ; int cutPoint = <NUM_LIT:1> ; List < Integer > cutPoints = new ArrayList < Integer > ( cutPointsCount ) ; cutPoints . add ( <NUM_LIT:0> ) ; do { int auxCut = RandomGenerator . getInt ( cutPoint , dad . length ) ; if ( ! cutPoints . contains ( auxCut ) ) { cutPoints . add ( auxCut ) ; } } while ( cutPoints . size ( ) <= cutPointsCount ) ; Collections . sort ( cutPoints ) ; int k = <NUM_LIT:0> ; for ( ; k < cutPoints . size ( ) - <NUM_LIT:1> ; k ++ ) { if ( k % <NUM_LIT:2> == <NUM_LIT:0> ) { for ( int i = cutPoints . get ( k ) ; i < cutPoints . get ( k + <NUM_LIT:1> ) ; i ++ ) { son1 [ i ] = dad [ i ] ; son2 [ i ] = mom [ i ] ; } } else { for ( int i = cutPoints . get ( k ) ; i < cutPoints . get ( k + <NUM_LIT:1> ) ; i ++ ) { son1 [ i ] = mom [ i ] ; son2 [ i ] = dad [ i ] ; } } } if ( k % <NUM_LIT:2> == <NUM_LIT:0> ) { for ( int i = cutPoints . get ( k ) ; i < dad . length ; i ++ ) { son1 [ i ] = dad [ i ] ; son2 [ i ] = mom [ i ] ; } } else { for ( int i = cutPoints . get ( k ) ; i < dad . length ; i ++ ) { son1 [ i ] = mom [ i ] ; son2 [ i ] = dad [ i ] ; } } Individual indSon1 = Individual . creator ( entities [ <NUM_LIT:0> ] . getData ( ) , son1 ) ; Individual indSon2 = Individual . creator ( entities [ <NUM_LIT:0> ] . getData ( ) , son2 ) ; return new Individual [ ] { indSon1 , indSon2 } ; } @ Override public boolean shouldApply ( ) { return RandomGenerator . getDouble ( ) < this . prob ; } } </s>
|
<s> package com . g4 . java . crossover ; import java . util . List ; import com . g4 . java . model . Individual ; import com . g4 . java . util . RandomGenerator ; public class GeneCrossOver implements Crossover { private double prob ; public GeneCrossOver ( double prob ) { this . prob = prob ; } @ Override public Individual [ ] cross ( Individual [ ] entities ) { int size = entities [ <NUM_LIT:0> ] . getLupusArray ( ) . length ; List < double [ ] [ ] > dad = entities [ <NUM_LIT:0> ] . getLupusMatrix ( ) ; List < double [ ] [ ] > mom = entities [ <NUM_LIT:1> ] . getLupusMatrix ( ) ; double [ ] son1 = new double [ size ] ; double [ ] son2 = new double [ size ] ; int cutPoint = RandomGenerator . getInt ( <NUM_LIT:1> , dad . size ( ) ) ; int index = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < cutPoint ; i ++ ) { double [ ] [ ] dadMatrix = dad . get ( i ) ; double [ ] [ ] momMatrix = mom . get ( i ) ; for ( int j = <NUM_LIT:0> ; j < dadMatrix . length ; j ++ ) { for ( int k = <NUM_LIT:0> ; k < dadMatrix [ j ] . length ; k ++ ) { son1 [ index ] = dadMatrix [ j ] [ k ] ; son2 [ index ++ ] = momMatrix [ j ] [ k ] ; } } } for ( int i = cutPoint ; i < dad . size ( ) ; i ++ ) { double [ ] [ ] dadMatrix = dad . get ( i ) ; double [ ] [ ] momMatrix = mom . get ( i ) ; for ( int j = <NUM_LIT:0> ; j < dadMatrix . length ; j ++ ) { for ( int k = <NUM_LIT:0> ; k < dadMatrix [ j ] . length ; k ++ ) { son1 [ index ] = dadMatrix [ j ] [ k ] ; son2 [ index ++ ] = momMatrix [ j ] [ k ] ; } } } Individual indSon1 = Individual . creator ( entities [ <NUM_LIT:0> ] . getData ( ) , son1 ) ; Individual indSon2 = Individual . creator ( entities [ <NUM_LIT:0> ] . getData ( ) , son2 ) ; return new Individual [ ] { indSon1 , indSon2 } ; } @ Override public boolean shouldApply ( ) { return RandomGenerator . getDouble ( ) < this . prob ; } } </s>
|
<s> package com . g4 . java ; import com . g4 . matlab . ann . ANN ; import com . mathworks . toolbox . javabuilder . MWException ; public class MatlabSingleton { private static MatlabSingleton instance = null ; private ANN ann ; public static MatlabSingleton getInstance ( ) throws MWException { if ( instance == null ) { instance = new MatlabSingleton ( ) ; } return instance ; } public MatlabSingleton ( ) throws MWException { ann = new ANN ( ) ; } public ANN getAnn ( ) { return ann ; } } </s>
|
<s> package com . g4 . java . selection ; import java . util . List ; import com . g4 . java . model . Individual ; public class BoltzmannSelection extends RuletteSelection { private double temperature ; private double varInTime ; private final double maxTemperature ; private final double minTemperature ; private final double decrement ; public BoltzmannSelection ( final double maxTemperature , final double minTemperature , final double decrement , final int toSelect ) { super ( toSelect ) ; this . maxTemperature = maxTemperature ; this . minTemperature = minTemperature ; this . decrement = decrement ; } @ Override public double filterFitness ( double fitness ) { return Math . exp ( fitness / temperature ) / this . varInTime ; } @ Override public List < Individual > select ( List < Individual > population , int generation ) { calculateTemperature ( generation ) ; this . varInTime = <NUM_LIT:0> ; for ( Individual ind : population ) { this . varInTime += Math . exp ( ind . getApptitude ( ) / this . temperature ) ; } this . varInTime = this . varInTime / population . size ( ) ; return super . select ( population , generation ) ; } private void calculateTemperature ( int generation ) { this . temperature = maxTemperature - generation * this . decrement ; if ( this . temperature < this . minTemperature ) { this . temperature = this . minTemperature ; } } } </s>
|
<s> package com . g4 . java . selection ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . List ; import com . g4 . java . model . Individual ; public class EliteSelection implements Selection { private int toSelect ; public EliteSelection ( final int toSelect ) { this . toSelect = toSelect ; } @ Override public List < Individual > select ( List < Individual > population , int generation ) { return select ( population , generation , this . toSelect ) ; } @ Override public List < Individual > select ( List < Individual > population , int generation , int ggToSelect ) { List < Individual > ret = new ArrayList < Individual > ( population ) ; Collections . sort ( ret , new Comparator < Individual > ( ) { @ Override public int compare ( Individual i1 , Individual i2 ) { final double i1Aptitude = i1 . getApptitude ( ) ; final double i2Aptitude = i2 . getApptitude ( ) ; if ( i1Aptitude < i2Aptitude ) { return <NUM_LIT:1> ; } else if ( i1Aptitude > i2Aptitude ) { return - <NUM_LIT:1> ; } return <NUM_LIT:0> ; } } ) ; return ret . subList ( <NUM_LIT:0> , ggToSelect ) ; } } </s>
|
<s> package com . g4 . java . selection ; import java . util . ArrayList ; import java . util . List ; import com . g4 . java . model . Individual ; import com . g4 . java . util . RandomGenerator ; public class RuletteSelection implements Selection { protected int toSelect ; public RuletteSelection ( final int toSelect ) { this . toSelect = toSelect ; } protected double filterFitness ( double fitness ) { return fitness ; } @ Override public List < Individual > select ( List < Individual > population , int generation ) { return select ( population , generation , this . toSelect ) ; } @ Override public List < Individual > select ( List < Individual > population , int generation , int ggToSelect ) { List < Individual > newGeneration = new ArrayList < Individual > ( ggToSelect ) ; double fitnessSum = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < population . size ( ) ; i ++ ) { fitnessSum += filterFitness ( population . get ( i ) . getApptitude ( ) ) ; } while ( newGeneration . size ( ) < ggToSelect ) { double r = fitnessSum * RandomGenerator . getDouble ( ) ; int j = <NUM_LIT:0> ; double f = <NUM_LIT:0> ; Individual individual = null ; do { if ( j >= population . size ( ) ) { break ; } individual = population . get ( j ++ ) ; f += filterFitness ( individual . getApptitude ( ) ) ; } while ( f < r ) ; newGeneration . add ( individual ) ; } return newGeneration ; } } </s>
|
<s> package com . g4 . java . selection ; import java . util . List ; import com . g4 . java . model . Individual ; public interface Selection { List < Individual > select ( List < Individual > population , final int generation ) ; List < Individual > select ( List < Individual > population , final int generation , int ggToSelect ) ; } </s>
|
<s> package com . g4 . java . selection ; import java . util . ArrayList ; import java . util . List ; import com . g4 . java . model . Individual ; import com . g4 . java . util . RandomGenerator ; public class UniversalSelection implements Selection { private int toSelect ; public UniversalSelection ( final int toSelect ) { this . toSelect = toSelect ; } @ Override public List < Individual > select ( List < Individual > population , int generation ) { return select ( population , generation , this . toSelect ) ; } @ Override public List < Individual > select ( List < Individual > population , int generation , int ggToSelect ) { List < Individual > newGeneration = new ArrayList < Individual > ( ) ; double distance = <NUM_LIT> / ggToSelect ; double r = RandomGenerator . getDouble ( ) / ggToSelect ; for ( int i = <NUM_LIT:0> ; i < ggToSelect ; i ++ ) { double f = <NUM_LIT:0> ; int j = <NUM_LIT:0> ; Individual individual = null ; do { individual = population . get ( j ++ ) ; f += individual . getApptitude ( ) ; } while ( f < r ) ; newGeneration . add ( individual ) ; r += distance ; } return newGeneration ; } } </s>
|
<s> package com . g4 . java . selection ; import java . util . ArrayList ; import java . util . List ; import com . g4 . java . model . Individual ; public class TournamentSelection implements Selection { private int tSize ; private int toSelect ; public TournamentSelection ( int tSize , final int toSelect ) { this . tSize = tSize ; this . toSelect = toSelect ; } @ Override public List < Individual > select ( List < Individual > population , int generation ) { return select ( population , generation ) ; } @ Override public List < Individual > select ( List < Individual > population , int generation , int ggToSelect ) { List < Individual > selected = new ArrayList < Individual > ( ggToSelect ) ; for ( int i = <NUM_LIT:0> ; i < toSelect ; ++ i ) { double bestAptitude = Double . NEGATIVE_INFINITY ; Individual auxEntity = null ; for ( int j = <NUM_LIT:0> ; j < tSize ; ++ j ) { int index = ( int ) Math . floor ( Math . random ( ) * ( population . size ( ) ) ) ; double curAptitude = population . get ( index ) . getApptitude ( ) ; if ( curAptitude > bestAptitude ) { auxEntity = population . get ( index ) ; bestAptitude = curAptitude ; } } if ( auxEntity != null ) { selected . add ( auxEntity ) ; } } return selected ; } } </s>
|
<s> package com . g4 . java . selection ; import java . util . ArrayList ; import java . util . List ; import com . g4 . java . model . Individual ; public class MixSelection implements Selection { private List < Selection > selections ; public MixSelection ( List < Selection > selections ) { this . selections = selections ; } @ Override public List < Individual > select ( List < Individual > population , int generation ) { List < Individual > selected = new ArrayList < Individual > ( ) ; for ( Selection selection : selections ) { selected . addAll ( selection . select ( population , generation ) ) ; } return selected ; } @ Override public List < Individual > select ( List < Individual > population , int generation , int ggToSelect ) { List < Individual > selected = new ArrayList < Individual > ( ggToSelect ) ; for ( Selection selection : selections ) { selected . addAll ( selection . select ( population , generation , ggToSelect ) ) ; } return selected ; } } </s>
|
<s> package com . g4 . java ; import java . io . BufferedWriter ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . FileWriter ; import java . io . IOException ; import java . util . ArrayList ; import java . util . List ; import com . g4 . java . configuration . Configuration ; import com . g4 . java . crossover . Crossover ; import com . g4 . java . ending . EndingMethod ; import com . g4 . java . model . Individual ; import com . g4 . java . mutation . Mutation ; import com . g4 . java . reproduction . MonogamousReproduction ; import com . g4 . java . reproduction . Reproduction ; import com . g4 . java . selection . EliteSelection ; import com . g4 . java . selection . MixSelection ; import com . g4 . java . util . InputValues ; import com . g4 . java . util . Printer ; import com . g4 . matlab . ann . ANN ; import com . mathworks . toolbox . javabuilder . MWArray ; import com . mathworks . toolbox . javabuilder . MWCellArray ; import com . mathworks . toolbox . javabuilder . MWException ; public class FunctionResolver { public static int ARCHITECTURE ; private int POP_SIZE ; private double generationGap ; private Configuration configuration ; private MixSelection selection ; private Mutation mutation ; private Crossover crossover ; private Reproduction reproduction = new MonogamousReproduction ( ) ; private EndingMethod ending ; private Backpropagation backpropagation ; private MixSelection replacement ; private List < Individual > population = new ArrayList < Individual > ( POP_SIZE ) ; private Printer debugger ; private static BufferedWriter outFile ; private ANN ann ; public static void main ( String [ ] args ) throws FileNotFoundException , IOException , MWException { FunctionResolver resolver = new FunctionResolver ( ) ; if ( args . length != <NUM_LIT:1> ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:0> ) ; } try { resolver . configuration = new Configuration ( args [ <NUM_LIT:0> ] ) ; } catch ( FileNotFoundException e ) { System . err . println ( "<STR_LIT>" + e . getCause ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } FunctionResolver . ARCHITECTURE = resolver . configuration . getArchitecture ( ) ; resolver . POP_SIZE = resolver . configuration . getPopSize ( ) ; resolver . generationGap = resolver . configuration . getGenerationGap ( ) ; resolver . selection = new MixSelection ( resolver . configuration . getSelectionMethods ( ) ) ; resolver . mutation = resolver . configuration . getMutation ( ) ; resolver . crossover = resolver . configuration . getCrossOverMethods ( ) ; resolver . ending = resolver . configuration . getEnding ( ) ; resolver . backpropagation = resolver . configuration . getBackpropagation ( ) ; resolver . replacement = new MixSelection ( resolver . configuration . getReplacementMethods ( ) ) ; resolver . ann = MatlabSingleton . getInstance ( ) . getAnn ( ) ; resolver . debugger = new Printer ( ) ; try { File file = new File ( System . getProperty ( "<STR_LIT>" ) + args [ <NUM_LIT:0> ] ) ; String outFileName = file . getName ( ) ; file = new File ( System . getProperty ( "<STR_LIT>" ) + "<STR_LIT>" + outFileName + "<STR_LIT>" ) ; file . delete ( ) ; file . createNewFile ( ) ; FileWriter fstream = new FileWriter ( file ) ; outFile = new BufferedWriter ( fstream ) ; } catch ( Exception e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; } try { resolver . run ( ) ; } catch ( MWException e ) { System . err . println ( e . getCause ( ) ) ; System . exit ( <NUM_LIT:0> ) ; } } private void run ( ) throws MWException { Object [ ] inputResult = ann . generateInputFromFile ( <NUM_LIT:4> , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:0> ) ; InputValues . getInstance ( ) . setInputs ( ( MWArray ) inputResult [ <NUM_LIT:0> ] ) ; InputValues . getInstance ( ) . setExpectedOutputs ( ( MWArray ) inputResult [ <NUM_LIT:1> ] ) ; InputValues . getInstance ( ) . setInputsTest ( ( MWArray ) inputResult [ <NUM_LIT:2> ] ) ; InputValues . getInstance ( ) . setExpectedOutputsTest ( ( MWArray ) inputResult [ <NUM_LIT:3> ] ) ; Function function = new Function ( ann ) ; long creationStartTime = System . currentTimeMillis ( ) ; for ( int i = <NUM_LIT:0> ; i < POP_SIZE ; i ++ ) { Individual individual = new Individual ( ) ; Object [ ] createIndividualResult = ann . createIndividual ( <NUM_LIT:1> , InputValues . getInstance ( ) . getInputs ( ) , InputValues . getInstance ( ) . getExpectedOutputs ( ) , InputValues . getInstance ( ) . getInputsTest ( ) , InputValues . getInstance ( ) . getExpectedOutputsTest ( ) , ARCHITECTURE ) ; individual . setData ( ( MWCellArray ) createIndividualResult [ <NUM_LIT:0> ] ) ; population . add ( individual ) ; } for ( int i = <NUM_LIT:0> ; i < POP_SIZE ; i ++ ) { population . get ( i ) . setApptitude ( function . eval ( population . get ( i ) ) ) ; } System . out . println ( "<STR_LIT>" + ( System . currentTimeMillis ( ) - creationStartTime ) ) ; for ( int i = <NUM_LIT:0> ; ! ending . shouldEnd ( population , i ) ; i ++ ) { long initial = System . currentTimeMillis ( ) ; System . out . println ( "<STR_LIT>" + i ) ; mutation . updateMutationProbability ( i ) ; int toSelect = ( int ) ( POP_SIZE * this . generationGap ) ; List < Individual > best = selection . select ( population , i ) ; List < Individual [ ] > parents = reproduction . getParents ( best ) ; List < Individual > generation = new ArrayList < Individual > ( ) ; List < Individual > sons = new ArrayList < Individual > ( ) ; for ( Individual [ ] family : parents ) { generation . add ( family [ <NUM_LIT:0> ] ) ; generation . add ( family [ <NUM_LIT:1> ] ) ; if ( crossover . shouldApply ( ) ) { Individual [ ] childs = crossover . cross ( family ) ; sons . add ( childs [ <NUM_LIT:0> ] ) ; sons . add ( childs [ <NUM_LIT:1> ] ) ; } else { sons . add ( family [ <NUM_LIT:0> ] ) ; sons . add ( family [ <NUM_LIT:1> ] ) ; } } List < Individual > sonsToAdd = new ArrayList < Individual > ( ) ; for ( Individual individual : sons ) { Individual individualToAdd = individual ; if ( mutation . shouldMutate ( ) ) { individualToAdd = mutation . mutate ( individualToAdd , i ) ; } if ( backpropagation . shouldApply ( ) ) { individualToAdd = backpropagation . run ( individualToAdd ) ; } sonsToAdd . add ( individualToAdd ) ; } sons . clear ( ) ; sons = null ; for ( Individual individual : sonsToAdd ) { individual . setApptitude ( function . eval ( individual ) ) ; } population = replacement . select ( population , i ) ; population . addAll ( sonsToAdd ) ; if ( population . size ( ) != POP_SIZE ) { System . err . println ( "<STR_LIT>" + population . size ( ) + "<STR_LIT>" + POP_SIZE + "<STR_LIT>" ) ; System . exit ( - <NUM_LIT:1> ) ; } EliteSelection bestSel = new EliteSelection ( population . size ( ) ) ; List < Individual > bestList = bestSel . select ( population , i ) ; try { outFile . write ( i + "<STR_LIT:U+0020>" + bestList . get ( <NUM_LIT:0> ) . getApptitude ( ) + "<STR_LIT:U+0020>" + bestList . get ( population . size ( ) - <NUM_LIT:1> ) . getApptitude ( ) + "<STR_LIT:U+0020>" + this . debugger . mean ( population ) + "<STR_LIT:U+0020>" + this . debugger . sdForIndividual ( population ) + "<STR_LIT>" ) ; outFile . flush ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } System . out . println ( "<STR_LIT>" + bestList . get ( <NUM_LIT:0> ) . getApptitude ( ) + "<STR_LIT>" + bestList . get ( population . size ( ) - <NUM_LIT:1> ) . getApptitude ( ) + "<STR_LIT>" + this . debugger . sdForIndividual ( population ) + "<STR_LIT>" + this . debugger . mean ( population ) ) ; long finish = System . currentTimeMillis ( ) ; System . out . println ( "<STR_LIT>" + i + "<STR_LIT>" + ( finish - initial ) / <NUM_LIT:1000> + "<STR_LIT>" ) ; } } } </s>
|
<s> package g4 ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Random ; import g4 . heuristics . Heuristic ; import gps . api . GPSProblem ; import gps . api . GPSRule ; import gps . api . GPSState ; public abstract class MahjongProblem implements GPSProblem { protected Heuristic heuristic ; @ Override public List < GPSRule > getRules ( GPSState state ) { List < GPSRule > rules = new ArrayList < GPSRule > ( ) ; final MahjongGPSState gpsState = ( MahjongGPSState ) state ; int count = gpsState . getBoard ( ) . getPayersCount ( ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { rules . add ( new MahjongGPSRule ( i ) ) ; } Collections . shuffle ( rules , new Random ( <NUM_LIT> ) ) ; return rules ; } public float getHValue ( GPSState state1 ) { return heuristic . getValue ( state1 ) ; } } </s>
|
<s> package g4 . heuristics ; import gps . api . GPSState ; public interface Heuristic { float getValue ( GPSState state ) ; } </s>
|
<s> package g4 . heuristics ; import aga . mahjong . core . Board ; import g4 . MahjongGPSState ; import gps . api . GPSState ; public class HStar implements Heuristic { @ Override public float getValue ( GPSState state ) { Board board = ( ( MahjongGPSState ) state ) . getBoard ( ) ; if ( <NUM_LIT:0> == board . getPayersCount ( ) ) { return Float . MAX_VALUE ; } return board . getTilesCount ( ) * <NUM_LIT> ; } } </s>
|
<s> package g4 . heuristics ; import aga . mahjong . core . Board ; import aga . mahjong . core . Pair ; import aga . mahjong . core . Position ; import g4 . MahjongGPSState ; import gps . api . GPSState ; public class BiggerRowsFirst implements Heuristic { @ Override public float getValue ( GPSState state1 ) { float ret = <NUM_LIT:0> ; MahjongGPSState state = ( MahjongGPSState ) state1 ; Board board = state . getBoard ( ) ; Pair pair = state . getMove ( ) ; int pairs = board . getTilesCount ( ) / <NUM_LIT:2> ; int payersCount = board . getPayersCount ( ) ; if ( pairs == <NUM_LIT:0> ) { return <NUM_LIT> ; } if ( payersCount == <NUM_LIT:0> ) { return Float . MAX_VALUE ; } ret = ( board . getTilesCount ( ) - tileValue ( pair . getPosition1 ( ) , board ) - tileValue ( pair . getPosition2 ( ) , board ) ) / <NUM_LIT:2> ; if ( ret <= <NUM_LIT:0> && board . getTilesCount ( ) > <NUM_LIT:0> ) { ret = <NUM_LIT:1> ; } return ret ; } public int tileValue ( Position position , Board board ) { return getAmountHorizontalBlockers ( position , board ) * ( position . getLayer ( ) + <NUM_LIT:1> ) ; } public int getAmountHorizontalBlockers ( Position position , Board board ) { int x = position . getColumn ( ) ; int y = position . getRow ( ) ; int z = position . getLayer ( ) ; int inc = <NUM_LIT:0> ; int ret = <NUM_LIT:0> ; if ( board . getItem ( z , y , x + <NUM_LIT:1> ) != null ) { inc = <NUM_LIT:1> ; } else { inc = - <NUM_LIT:1> ; } while ( board . getItem ( z , y , x + inc ) != null ) { ret ++ ; } return ret / <NUM_LIT:2> ; } } </s>
|
<s> package g4 . heuristics ; import aga . mahjong . core . Board ; import g4 . MahjongGPSState ; import gps . api . GPSState ; public class MorePayers implements Heuristic { @ Override public float getValue ( GPSState state ) { Board board = ( ( MahjongGPSState ) state ) . getBoard ( ) ; float pairs = board . getTilesCount ( ) * <NUM_LIT> ; float payersCount = board . getPayersCount ( ) ; if ( pairs == <NUM_LIT:0> ) { return <NUM_LIT> ; } if ( payersCount == <NUM_LIT:0> ) { return Float . MAX_VALUE ; } float ret = pairs - payersCount ; return ( ret > <NUM_LIT:0> ) ? ret : <NUM_LIT:1> ; } } </s>
|
<s> package g4 . heuristics ; import aga . mahjong . core . Board ; import aga . mahjong . core . Pair ; import g4 . MahjongGPSState ; import gps . api . GPSState ; public class UpperLevelFirst implements Heuristic { @ Override public float getValue ( GPSState state1 ) { MahjongGPSState state = ( MahjongGPSState ) state1 ; Board board = state . getBoard ( ) ; int pairs = board . getTilesCount ( ) / <NUM_LIT:2> ; Pair pair = state . getMove ( ) ; int height = pair . getPosition1 ( ) . getLayer ( ) + pair . getPosition2 ( ) . getLayer ( ) ; float ret = pairs - height ; if ( pairs == <NUM_LIT:0> ) { return <NUM_LIT> ; } if ( board . getPayersCount ( ) == <NUM_LIT:0> ) { return Float . MAX_VALUE ; } return ( ret > <NUM_LIT:0> ) ? ret : <NUM_LIT> ; } } </s>
|
<s> package g4 ; import aga . mahjong . core . Board ; import aga . mahjong . core . Pair ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; public class MahjongGPSRule implements GPSRule { private static float cost = <NUM_LIT:1> ; private int indexToUse ; public MahjongGPSRule ( int indexToUse ) { this . indexToUse = indexToUse ; } public static void setCost ( float cost1 ) { cost = cost1 ; } @ Override public float getCost ( ) { return cost ; } @ Override public String getName ( ) { return String . format ( "<STR_LIT>" , indexToUse ) ; } @ Override public GPSState evalRule ( GPSState state ) throws NotAppliableException { MahjongGPSState original = ( MahjongGPSState ) state ; if ( original . getBoard ( ) . getPayersCount ( ) == <NUM_LIT:0> ) { throw new NotAppliableException ( ) ; } Pair pair = null ; try { pair = original . getBoard ( ) . getPairs ( ) [ indexToUse ] ; } catch ( IndexOutOfBoundsException e ) { throw new NotAppliableException ( ) ; } MahjongGPSState clone = null ; try { clone = ( MahjongGPSState ) original . clone ( ) ; } catch ( CloneNotSupportedException e ) { throw new NotAppliableException ( ) ; } Board board = clone . getBoard ( ) ; Pair toRemove = board . getPairs ( ) [ indexToUse ] ; board . setItem ( toRemove . getPosition1 ( ) , null ) ; board . setItem ( toRemove . getPosition2 ( ) , null ) ; clone . setMove ( pair ) ; return clone ; } } </s>
|
<s> package g4 ; import g4 . heuristics . Heuristic ; import g4 . parseLine . CommandLineParser ; import g4 . parseLine . HeuristicFactory ; import g4 . parseLine . ProblemFactory ; import gps . SearchStrategy ; import gps . api . GPSProblem ; import org . kohsuke . args4j . CmdLineException ; import org . kohsuke . args4j . CmdLineParser ; public class Main { public static void main ( String [ ] args ) { CommandLineParser arguments = new CommandLineParser ( ) ; CmdLineParser parser = new CmdLineParser ( arguments ) ; try { parser . parseArgument ( args ) ; } catch ( CmdLineException e ) { System . err . println ( "<STR_LIT>" ) ; parser . printUsage ( System . err ) ; System . exit ( <NUM_LIT:1> ) ; } if ( arguments . help ) { parser . printUsage ( System . out ) ; System . exit ( <NUM_LIT:1> ) ; } if ( arguments . getStrategy ( ) == null ) { System . err . println ( "<STR_LIT>" ) ; parser . printUsage ( System . err ) ; System . exit ( <NUM_LIT:1> ) ; } if ( arguments . getHeuristic ( ) == null && arguments . getStrategy ( ) != SearchStrategy . DFS && arguments . getStrategy ( ) != SearchStrategy . BFS && arguments . getStrategy ( ) != SearchStrategy . IterativeDepth ) { System . err . println ( "<STR_LIT>" ) ; parser . printUsage ( System . err ) ; System . exit ( <NUM_LIT:1> ) ; } Heuristic heuristic = null ; if ( arguments . getStrategy ( ) != SearchStrategy . DFS && arguments . getStrategy ( ) != SearchStrategy . BFS && arguments . getStrategy ( ) != SearchStrategy . IterativeDepth ) { heuristic = HeuristicFactory . createHeuristicFromString ( arguments . getHeuristic ( ) ) ; if ( heuristic == null ) { System . err . println ( "<STR_LIT>" ) ; parser . printUsage ( System . err ) ; System . exit ( <NUM_LIT:1> ) ; } } if ( arguments . getCost ( ) != null ) { MahjongGPSRule . setCost ( arguments . getCost ( ) ) ; } SearchStrategy strategy = arguments . getStrategy ( ) ; GPSProblem problem = ProblemFactory . createProblem ( arguments . getLevel ( ) , heuristic ) ; if ( problem == null ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } if ( strategy == null ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( <NUM_LIT:1> ) ; } G4GPSEngine engine = new G4GPSEngine ( ) ; engine . engine ( problem , strategy ) ; } } </s>
|
<s> package g4 ; import gps . GPSEngine ; import gps . GPSNode ; import gps . SearchStrategy ; import gps . api . GPSProblem ; import java . util . Collections ; import java . util . Comparator ; import java . util . LinkedList ; import java . util . List ; import com . google . common . base . Predicate ; import com . google . common . collect . Collections2 ; import com . google . common . collect . Lists ; public class G4GPSEngine extends GPSEngine { protected int depthLevel = <NUM_LIT:0> ; protected int generatedNodes ; @ Override public void engine ( GPSProblem myProblem , SearchStrategy myStrategy ) { generatedNodes = <NUM_LIT:0> ; super . engine ( myProblem , myStrategy ) ; } @ Override public void addNode ( GPSNode node ) { switch ( strategy ) { case BFS : open . add ( node ) ; break ; case IterativeDepth : if ( node . getTreeLevel ( ) > depthLevel + <NUM_LIT:1> ) { generatedNodes += open . size ( ) + closed . size ( ) ; closed . clear ( ) ; open . clear ( ) ; open . add ( rootNode ) ; depthLevel ++ ; break ; } else if ( node . getTreeLevel ( ) > depthLevel ) { open . add ( node ) ; break ; } case DFS : ( ( LinkedList < GPSNode > ) open ) . addFirst ( node ) ; break ; case AStar : int index = Collections . binarySearch ( open , node , new Comparator < GPSNode > ( ) { @ Override public int compare ( GPSNode o1 , GPSNode o2 ) { Float f1 = o1 . getCost ( ) + problem . getHValue ( o1 . getState ( ) ) ; Float f2 = o2 . getCost ( ) + problem . getHValue ( o2 . getState ( ) ) ; if ( f1 < f2 ) { return - <NUM_LIT:1> ; } else if ( f1 == f2 ) { return <NUM_LIT:0> ; } else { return <NUM_LIT:1> ; } } } ) ; if ( index >= <NUM_LIT:0> ) { ( ( LinkedList < GPSNode > ) open ) . add ( index , node ) ; } else { ( ( LinkedList < GPSNode > ) open ) . add ( - <NUM_LIT:1> * ( index + <NUM_LIT:1> ) , node ) ; } break ; case Greedy : if ( open . isEmpty ( ) || ! open . get ( <NUM_LIT:0> ) . getParent ( ) . equals ( node . getParent ( ) ) ) { ( ( LinkedList < GPSNode > ) open ) . addFirst ( node ) ; } else { final GPSNode node2 = node ; List < GPSNode > openParent = Lists . newArrayList ( Collections2 . filter ( open , new Predicate < GPSNode > ( ) { @ Override public boolean apply ( GPSNode input ) { return input . getParent ( ) . equals ( node2 . getParent ( ) ) ; } } ) ) ; int index2 = Collections . binarySearch ( openParent , node , new Comparator < GPSNode > ( ) { @ Override public int compare ( GPSNode o1 , GPSNode o2 ) { return ( int ) ( problem . getHValue ( o1 . getState ( ) ) - problem . getHValue ( o2 . getState ( ) ) ) ; } } ) ; if ( index2 >= <NUM_LIT:0> ) { ( ( LinkedList < GPSNode > ) open ) . add ( index2 , node ) ; } else { ( ( LinkedList < GPSNode > ) open ) . add ( - <NUM_LIT:1> * ( index2 + <NUM_LIT:1> ) , node ) ; } } break ; default : open . add ( node ) ; break ; } } } </s>
|
<s> package g4 . parseLine ; import g4 . heuristics . BiggerRowsFirst ; import g4 . heuristics . HStar ; import g4 . heuristics . Heuristic ; import g4 . heuristics . MorePayers ; import g4 . heuristics . UpperLevelFirst ; public class HeuristicFactory { public static Heuristic createHeuristicFromString ( String heuristic ) { if ( heuristic == null ) { return null ; } if ( heuristic . compareToIgnoreCase ( "<STR_LIT>" ) == <NUM_LIT:0> ) { return new BiggerRowsFirst ( ) ; } if ( heuristic . compareToIgnoreCase ( "<STR_LIT>" ) == <NUM_LIT:0> ) { return new MorePayers ( ) ; } if ( heuristic . compareToIgnoreCase ( "<STR_LIT>" ) == <NUM_LIT:0> ) { return new UpperLevelFirst ( ) ; } if ( heuristic . compareToIgnoreCase ( "<STR_LIT>" ) == <NUM_LIT:0> ) { return new HStar ( ) ; } return null ; } } </s>
|
<s> package g4 . parseLine ; import gps . SearchStrategy ; import org . kohsuke . args4j . Option ; public class CommandLineParser { @ Option ( name = "<STR_LIT>" , aliases = { "<STR_LIT>" } , usage = "<STR_LIT>" ) private SearchStrategy strategies ; @ Option ( name = "<STR_LIT>" , aliases = { "<STR_LIT>" } , usage = "<STR_LIT>" ) private int level ; @ Option ( name = "<STR_LIT>" , aliases = { "<STR_LIT>" } , usage = "<STR_LIT>" ) private String heuristic ; @ Option ( name = "<STR_LIT>" , aliases = { "<STR_LIT>" } , usage = "<STR_LIT>" ) private Float cost ; private boolean hasToDraw = false ; public boolean help = false ; public SearchStrategy getStrategy ( ) { return strategies ; } public Float getCost ( ) { return cost ; } public int getLevel ( ) { return level ; } public boolean hasToDraw ( ) { return hasToDraw ; } public String getHeuristic ( ) { return heuristic ; } @ Option ( name = "<STR_LIT>" , usage = "<STR_LIT>" ) public void showHelp ( boolean flag ) { help = true ; } } </s>
|
<s> package g4 . parseLine ; import g4 . heuristics . Heuristic ; import g4 . layouts . layout1 . Layout1Problem ; import g4 . layouts . layout2 . Layout2Problem ; import g4 . layouts . layout3 . Layout3Problem ; import g4 . layouts . layout4 . Layout4Problem ; import gps . api . GPSProblem ; public class ProblemFactory { public static GPSProblem createProblem ( int level , Heuristic heuristic ) { GPSProblem problem = null ; switch ( level ) { case <NUM_LIT:1> : problem = new Layout1Problem ( heuristic ) ; break ; case <NUM_LIT:2> : problem = new Layout2Problem ( heuristic ) ; break ; case <NUM_LIT:3> : problem = new Layout3Problem ( heuristic ) ; case <NUM_LIT:4> : problem = new Layout4Problem ( heuristic ) ; default : break ; } return problem ; } } </s>
|
<s> package g4 ; import gps . api . GPSState ; import aga . mahjong . core . Board ; import aga . mahjong . core . Pair ; import aga . mahjong . core . Tile ; public class MahjongGPSState implements GPSState { private Board board ; private Pair move ; @ Override public boolean compare ( GPSState state ) { MahjongGPSState other = ( MahjongGPSState ) state ; for ( int i = <NUM_LIT:0> ; i < other . getBoard ( ) . getLayerCount ( ) ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < other . getBoard ( ) . getRowCount ( ) ; j ++ ) { for ( int k = <NUM_LIT:0> ; k < other . getBoard ( ) . getColumnCount ( ) ; k ++ ) { Tile tile1 = other . getBoard ( ) . getItem ( i , j , k ) ; Tile tile2 = board . getItem ( i , j , k ) ; if ( tile1 == null && tile2 != null ) { return false ; } else if ( tile1 != null && tile2 == null ) { return false ; } else if ( tile1 == null && tile2 == null ) { continue ; } else { if ( ! tile1 . equals ( tile2 ) ) { return false ; } } } } } return true ; } public void setBoard ( Board board ) { this . board = board ; } public Board getBoard ( ) { return board ; } @ Override public String toString ( ) { return "<STR_LIT>" + board . toString ( ) ; } @ Override protected Object clone ( ) throws CloneNotSupportedException { MahjongGPSState clone = new MahjongGPSState ( ) ; Board board = ( Board ) this . board . clone ( ) ; clone . setBoard ( board ) ; return clone ; } public Pair getMove ( ) { return move ; } public void setMove ( Pair move ) { this . move = move ; } } </s>
|
<s> package g4 . layouts . layout2 ; import g4 . MahjongGPSState ; import g4 . MahjongProblem ; import g4 . heuristics . Heuristic ; import gps . api . GPSState ; import aga . mahjong . core . Board ; public class Layout2Problem extends MahjongProblem { public Layout2Problem ( Heuristic heuristic1 ) { this . heuristic = heuristic1 ; } @ Override public GPSState getInitState ( ) { MahjongGPSState gpsState = new MahjongGPSState ( ) ; Board board = new Board ( new Layout2 ( ) ) ; Layout2Arrange arrange = new Layout2Arrange ( ) ; arrange . arrange ( board ) ; gpsState . setBoard ( board ) ; assert ( board . getPayersCount ( ) > <NUM_LIT:0> ) ; return gpsState ; } @ Override public GPSState getGoalState ( ) { MahjongGPSState gpsState = new MahjongGPSState ( ) ; Board board = new Board ( new Layout2 ( ) ) ; gpsState . setBoard ( board ) ; assert ( board . getPayersCount ( ) == <NUM_LIT:0> ) ; return gpsState ; } } </s>
|
<s> package g4 . layouts . layout2 ; import aga . mahjong . core . Board ; import aga . mahjong . core . IArrangeStrategy ; import aga . mahjong . core . Position ; import aga . mahjong . core . Tile ; import aga . mahjong . core . TileKind ; public class Layout2Arrange implements IArrangeStrategy { @ Override public void arrange ( Board board ) { board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:7> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:9> ) , new Tile ( TileKind . Dot , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) , new Tile ( TileKind . Wind , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> ) , new Tile ( TileKind . Character , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:6> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:12> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:16> ) , new Tile ( TileKind . Dragon , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:20> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT> ) , new Tile ( TileKind . Wind , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:24> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:3> ) , new Tile ( TileKind . Dragon , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:5> ) , new Tile ( TileKind . Character , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:16> ) , new Tile ( TileKind . Character , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT> ) , new Tile ( TileKind . Wind , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:24> ) , new Tile ( TileKind . Dot , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:0> ) , new Tile ( TileKind . Dot , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:2> ) , new Tile ( TileKind . Character , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:4> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:16> ) , new Tile ( TileKind . Wind , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:24> ) , new Tile ( TileKind . Dragon , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:0> ) , new Tile ( TileKind . Character , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:2> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:8> ) , new Tile ( TileKind . Dragon , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:12> ) , new Tile ( TileKind . Character , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:16> ) , new Tile ( TileKind . Dot , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> ) , new Tile ( TileKind . Flower , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:24> ) , new Tile ( TileKind . Dragon , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:8> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:12> ) , new Tile ( TileKind . Wind , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:16> ) , new Tile ( TileKind . Wind , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:24> ) , new Tile ( TileKind . Dot , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:10> ) , new Tile ( TileKind . Dragon , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:12> ) , new Tile ( TileKind . Character , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT> ) , new Tile ( TileKind . Flower , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:16> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:16> ) , new Tile ( TileKind . Dot , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:7> ) , new Tile ( TileKind . Wind , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:9> ) , new Tile ( TileKind . Character , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> ) , new Tile ( TileKind . Dragon , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> ) , new Tile ( TileKind . Dragon , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:6> ) , new Tile ( TileKind . Dot , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:10> ) , new Tile ( TileKind . Wind , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:12> ) , new Tile ( TileKind . Wind , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:16> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:20> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:24> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:3> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> ) , new Tile ( TileKind . Character , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:12> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:16> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:24> ) , new Tile ( TileKind . Flower , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:0> ) , new Tile ( TileKind . Dot , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:2> ) , new Tile ( TileKind . Character , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:4> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:10> ) , new Tile ( TileKind . Season , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:12> ) , new Tile ( TileKind . Wind , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:16> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT> ) , new Tile ( TileKind . Wind , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT> ) , new Tile ( TileKind . Dragon , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:24> ) , new Tile ( TileKind . Character , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:0> ) , new Tile ( TileKind . Character , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:2> ) , new Tile ( TileKind . Season , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:8> ) , new Tile ( TileKind . Dot , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:12> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:16> ) , new Tile ( TileKind . Wind , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:24> ) , new Tile ( TileKind . Dot , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:12> ) , new Tile ( TileKind . Character , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:16> ) , new Tile ( TileKind . Character , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:24> ) , new Tile ( TileKind . Dot , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:8> ) , new Tile ( TileKind . Wind , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:12> ) , new Tile ( TileKind . Character , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT> ) , new Tile ( TileKind . Wind , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:16> ) , new Tile ( TileKind . Dot , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:11> ) , new Tile ( TileKind . Dragon , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) , new Tile ( TileKind . Dragon , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:15> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:11> ) , new Tile ( TileKind . Dot , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:6> , <NUM_LIT:11> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:6> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:7> , <NUM_LIT:1> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT:11> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:8> ) , new Tile ( TileKind . Season , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:10> ) , new Tile ( TileKind . Dragon , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:12> ) , new Tile ( TileKind . Season , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:16> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:12> ) , new Tile ( TileKind . Character , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:16> ) , new Tile ( TileKind . Flower , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT> ) , new Tile ( TileKind . Character , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT> ) , new Tile ( TileKind . Wind , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT:11> , <NUM_LIT:9> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT:11> , <NUM_LIT:11> ) , new Tile ( TileKind . Dot , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT:11> , <NUM_LIT> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT:11> , <NUM_LIT:15> ) , new Tile ( TileKind . Wind , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT:11> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:4> ) ) ; } } </s>
|
<s> package g4 . layouts . layout2 ; import java . util . ArrayList ; import aga . mahjong . core . Layout ; import aga . mahjong . core . Position ; public class Layout2 extends Layout { private static final long serialVersionUID = <NUM_LIT:1L> ; public Layout2 ( ) { name = "<STR_LIT>" ; layerCount = <NUM_LIT:4> ; rowCount = <NUM_LIT:16> ; columnCount = <NUM_LIT:30> ; positions = new ArrayList < Position > ( ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:7> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:9> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:20> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:24> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:3> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:5> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:24> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:24> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:24> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:24> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:7> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:9> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:20> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:24> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:3> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:5> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:4> , <NUM_LIT:24> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:6> , <NUM_LIT:24> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:24> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:24> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:11> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:15> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:11> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:6> , <NUM_LIT:11> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:6> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:7> , <NUM_LIT:1> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT:11> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:10> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT:16> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:12> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT:11> , <NUM_LIT:9> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT:11> , <NUM_LIT:11> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT:11> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT:11> , <NUM_LIT:15> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT:11> , <NUM_LIT> ) ) ; } } </s>
|
<s> package g4 . layouts . layout4 ; import aga . mahjong . core . Board ; import aga . mahjong . core . IArrangeStrategy ; import aga . mahjong . core . Position ; import aga . mahjong . core . Tile ; import aga . mahjong . core . TileKind ; public class Layout4Arrange implements IArrangeStrategy { @ Override public void arrange ( Board board ) { board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:7> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) , new Tile ( TileKind . Dot , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:7> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:16> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:15> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:7> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:15> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT:6> ) , new Tile ( TileKind . Character , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:6> ) , new Tile ( TileKind . Character , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:15> , <NUM_LIT:6> ) , new Tile ( TileKind . Character , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:6> ) , new Tile ( TileKind . Character , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:4> ) , new Tile ( TileKind . Character , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:4> ) , new Tile ( TileKind . Character , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:16> , <NUM_LIT:4> ) , new Tile ( TileKind . Character , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:7> , <NUM_LIT:2> ) , new Tile ( TileKind . Wind , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT:2> ) , new Tile ( TileKind . Wind , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT:2> ) , new Tile ( TileKind . Wind , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) , new Tile ( TileKind . Wind , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:15> , <NUM_LIT:2> ) , new Tile ( TileKind . Wind , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) , new Tile ( TileKind . Wind , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) , new Tile ( TileKind . Wind , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) , new Tile ( TileKind . Wind , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0> ) , new Tile ( TileKind . Dragon , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:15> , <NUM_LIT:0> ) , new Tile ( TileKind . Dragon , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT> ) , new Tile ( TileKind . Dragon , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT> ) , new Tile ( TileKind . Dragon , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) , new Tile ( TileKind . Dragon , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) , new Tile ( TileKind . Dragon , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:12> ) , new Tile ( TileKind . Flower , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:12> ) , new Tile ( TileKind . Flower , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:12> ) , new Tile ( TileKind . Season , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:7> , <NUM_LIT:12> ) , new Tile ( TileKind . Season , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:16> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:11> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Dot , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:7> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:11> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:11> , <NUM_LIT:6> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:6> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:6> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:6> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:4> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:4> ) , new Tile ( TileKind . Character , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:16> , <NUM_LIT:4> ) , new Tile ( TileKind . Character , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:2> ) , new Tile ( TileKind . Character , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:2> ) , new Tile ( TileKind . Character , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:0> ) , new Tile ( TileKind . Character , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:12> ) , new Tile ( TileKind . Character , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:12> ) , new Tile ( TileKind . Character , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Character , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:12> ) , new Tile ( TileKind . Character , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:11> ) , new Tile ( TileKind . Character , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:11> ) , new Tile ( TileKind . Character , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:11> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:7> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:9> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:10> ) , new Tile ( TileKind . Wind , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:8> ) , new Tile ( TileKind . Wind , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:11> , <NUM_LIT:8> ) , new Tile ( TileKind . Wind , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Wind , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:8> ) , new Tile ( TileKind . Wind , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Wind , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:24> , <NUM_LIT:8> ) , new Tile ( TileKind . Wind , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:11> , <NUM_LIT:6> ) , new Tile ( TileKind . Wind , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:6> ) , new Tile ( TileKind . Dragon , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:6> ) , new Tile ( TileKind . Dragon , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:6> ) , new Tile ( TileKind . Dragon , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:11> ) , new Tile ( TileKind . Dragon , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT:24> , <NUM_LIT:11> ) , new Tile ( TileKind . Dragon , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:9> ) , new Tile ( TileKind . Dragon , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT:15> , <NUM_LIT:9> ) , new Tile ( TileKind . Flower , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:7> ) , new Tile ( TileKind . Flower , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT:15> , <NUM_LIT:7> ) , new Tile ( TileKind . Season , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:4> , <NUM_LIT> , <NUM_LIT:8> ) , new Tile ( TileKind . Season , <NUM_LIT:4> ) ) ; } } </s>
|
<s> package g4 . layouts . layout4 ; import g4 . MahjongGPSState ; import g4 . MahjongProblem ; import g4 . heuristics . Heuristic ; import gps . api . GPSState ; import aga . mahjong . core . Board ; public class Layout4Problem extends MahjongProblem { public Layout4Problem ( Heuristic heuristic1 ) { this . heuristic = heuristic1 ; } @ Override public GPSState getInitState ( ) { MahjongGPSState gpsState = new MahjongGPSState ( ) ; Board board = new Board ( new Layout4 ( ) ) ; Layout4Arrange arrange = new Layout4Arrange ( ) ; arrange . arrange ( board ) ; gpsState . setBoard ( board ) ; if ( board . getPayersCount ( ) == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" ) ; return null ; } if ( ! board . isValid ( ) ) { return null ; } return gpsState ; } @ Override public GPSState getGoalState ( ) { MahjongGPSState gpsState = new MahjongGPSState ( ) ; Board board = new Board ( new Layout4 ( ) ) ; gpsState . setBoard ( board ) ; assert ( board . getPayersCount ( ) == <NUM_LIT:0> ) ; return gpsState ; } } </s>
|
<s> package g4 . layouts . layout4 ; import java . util . ArrayList ; import aga . mahjong . core . Layout ; import aga . mahjong . core . Position ; public class Layout4 extends Layout { private static final long serialVersionUID = <NUM_LIT:1L> ; public Layout4 ( ) { name = "<STR_LIT>" ; layerCount = <NUM_LIT:5> ; rowCount = <NUM_LIT:30> ; columnCount = <NUM_LIT:16> ; positions = new ArrayList < Position > ( ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:7> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:7> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:16> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:15> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:3> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:7> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:15> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:15> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:16> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:7> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:11> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:15> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:15> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:7> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:16> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:9> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:11> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:7> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:11> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:11> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:12> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:16> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:15> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:11> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:11> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:11> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:4> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:11> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:24> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:11> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:15> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:11> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT:24> , <NUM_LIT:11> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:9> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT:15> , <NUM_LIT:9> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:7> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT:15> , <NUM_LIT:7> ) ) ; positions . add ( new Position ( <NUM_LIT:4> , <NUM_LIT> , <NUM_LIT:8> ) ) ; } } </s>
|
<s> package g4 . layouts . layout1 ; import java . util . ArrayList ; import aga . mahjong . core . Layout ; import aga . mahjong . core . Position ; public class Layout1 extends Layout { private static final long serialVersionUID = <NUM_LIT:1L> ; public Layout1 ( ) { name = "<STR_LIT>" ; layerCount = <NUM_LIT:4> ; rowCount = <NUM_LIT:5> ; columnCount = <NUM_LIT:7> ; positions = new ArrayList < Position > ( ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:4> ) ) ; } } </s>
|
<s> package g4 . layouts . layout1 ; import g4 . MahjongGPSState ; import g4 . MahjongProblem ; import g4 . heuristics . Heuristic ; import gps . api . GPSState ; import aga . mahjong . core . Board ; public class Layout1Problem extends MahjongProblem { public Layout1Problem ( Heuristic heuristic1 ) { this . heuristic = heuristic1 ; } @ Override public GPSState getInitState ( ) { MahjongGPSState gpsState = new MahjongGPSState ( ) ; Board board = new Board ( new Layout1 ( ) ) ; Layout1Arrange arrange = new Layout1Arrange ( ) ; arrange . arrange ( board ) ; gpsState . setBoard ( board ) ; if ( board . getPayersCount ( ) == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" ) ; return null ; } if ( ! board . isValid ( ) ) { return null ; } return gpsState ; } @ Override public GPSState getGoalState ( ) { MahjongGPSState gpsState = new MahjongGPSState ( ) ; Board board = new Board ( new Layout1 ( ) ) ; gpsState . setBoard ( board ) ; assert ( board . getPayersCount ( ) == <NUM_LIT:0> ) ; return gpsState ; } } </s>
|
<s> package g4 . layouts . layout1 ; import aga . mahjong . core . Board ; import aga . mahjong . core . IArrangeStrategy ; import aga . mahjong . core . Position ; import aga . mahjong . core . Tile ; import aga . mahjong . core . TileKind ; public class Layout1Arrange implements IArrangeStrategy { @ Override public void arrange ( Board board ) { board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> ) , new Tile ( TileKind . Character , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:2> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:4> ) , new Tile ( TileKind . Character , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:4> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:2> , <NUM_LIT:1> , <NUM_LIT:4> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:3> ) ) ; board . setItem ( new Position ( <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:4> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; } } </s>
|
<s> package g4 . layouts . layout3 ; import java . util . ArrayList ; import aga . mahjong . core . Layout ; import aga . mahjong . core . Position ; public class Layout3 extends Layout { private static final long serialVersionUID = <NUM_LIT:1L> ; public Layout3 ( ) { name = "<STR_LIT>" ; layerCount = <NUM_LIT:1> ; rowCount = <NUM_LIT> ; columnCount = <NUM_LIT> ; positions = new ArrayList < Position > ( ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:0> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:4> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:6> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:8> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:10> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:12> ) ) ; positions . add ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:12> ) ) ; } } </s>
|
<s> package g4 . layouts . layout3 ; import aga . mahjong . core . Board ; import aga . mahjong . core . IArrangeStrategy ; import aga . mahjong . core . Position ; import aga . mahjong . core . Tile ; import aga . mahjong . core . TileKind ; public class Layout3Arrange implements IArrangeStrategy { @ Override public void arrange ( Board board ) { board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:0> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:0> ) , new Tile ( TileKind . Character , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:0> ) , new Tile ( TileKind . Dot , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:0> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:0> ) , new Tile ( TileKind . Character , <NUM_LIT:5> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> ) , new Tile ( TileKind . Wind , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:4> ) , new Tile ( TileKind . Dot , <NUM_LIT:2> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:4> ) , new Tile ( TileKind . Character , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:6> ) , new Tile ( TileKind . Wind , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:6> ) , new Tile ( TileKind . Wind , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:6> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:8> ) , new Tile ( TileKind . Character , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:4> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:4> , <NUM_LIT:10> ) , new Tile ( TileKind . Character , <NUM_LIT:6> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:10> ) , new Tile ( TileKind . Wind , <NUM_LIT:8> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:12> , <NUM_LIT:10> ) , new Tile ( TileKind . Bamboo , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:12> ) , new Tile ( TileKind . Dot , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:6> , <NUM_LIT:12> ) , new Tile ( TileKind . Dragon , <NUM_LIT:1> ) ) ; board . setItem ( new Position ( <NUM_LIT:0> , <NUM_LIT:10> , <NUM_LIT:12> ) , new Tile ( TileKind . Dragon , <NUM_LIT:1> ) ) ; } } </s>
|
<s> package g4 . layouts . layout3 ; import g4 . MahjongGPSState ; import g4 . MahjongProblem ; import g4 . heuristics . Heuristic ; import gps . api . GPSState ; import aga . mahjong . core . Board ; public class Layout3Problem extends MahjongProblem { public Layout3Problem ( Heuristic heuristic1 ) { this . heuristic = heuristic1 ; } @ Override public GPSState getInitState ( ) { MahjongGPSState gpsState = new MahjongGPSState ( ) ; Board board = new Board ( new Layout3 ( ) ) ; Layout3Arrange arrange = new Layout3Arrange ( ) ; arrange . arrange ( board ) ; gpsState . setBoard ( board ) ; if ( board . getPayersCount ( ) == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" ) ; return null ; } if ( ! board . isValid ( ) ) { return null ; } return gpsState ; } @ Override public GPSState getGoalState ( ) { MahjongGPSState gpsState = new MahjongGPSState ( ) ; Board board = new Board ( new Layout3 ( ) ) ; gpsState . setBoard ( board ) ; assert ( board . getPayersCount ( ) == <NUM_LIT:0> ) ; return gpsState ; } } </s>
|
<s> package gps . api ; import java . util . List ; public interface GPSProblem { GPSState getInitState ( ) ; GPSState getGoalState ( ) ; List < GPSRule > getRules ( GPSState state ) ; float getHValue ( GPSState state ) ; } </s>
|
<s> package gps . api ; import gps . exception . NotAppliableException ; public interface GPSRule { float getCost ( ) ; String getName ( ) ; GPSState evalRule ( GPSState state ) throws NotAppliableException ; } </s>
|
<s> package gps . api ; public interface GPSState { boolean compare ( GPSState state ) ; } </s>
|
<s> package gps . exception ; public class NotAppliableException extends Exception { private static final long serialVersionUID = <NUM_LIT:1L> ; } </s>
|
<s> package gps ; import g4 . MahjongGPSState ; import gps . api . GPSProblem ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; import java . util . ArrayList ; import java . util . LinkedList ; import java . util . List ; public abstract class GPSEngine { private static final long TIME_LIMIT = <NUM_LIT:1000> * <NUM_LIT> * <NUM_LIT:5> ; protected List < GPSNode > open = new LinkedList < GPSNode > ( ) ; protected List < GPSNode > closed = new ArrayList < GPSNode > ( ) ; protected GPSProblem problem ; protected GPSNode rootNode ; protected SearchStrategy strategy ; public void engine ( GPSProblem myProblem , SearchStrategy myStrategy ) { problem = myProblem ; strategy = myStrategy ; rootNode = new GPSNode ( problem . getInitState ( ) , <NUM_LIT:0> ) ; boolean finished = false ; boolean failed = false ; boolean timeUp = false ; long start = System . currentTimeMillis ( ) ; long explosionCounter = <NUM_LIT:0> ; GPSNode currentNode = null ; open . add ( rootNode ) ; while ( ! failed && ! finished && ! timeUp ) { if ( open . size ( ) <= <NUM_LIT:0> ) { failed = true ; } else { currentNode = open . get ( <NUM_LIT:0> ) ; closed . add ( currentNode ) ; open . remove ( <NUM_LIT:0> ) ; if ( isGoal ( currentNode ) ) { finished = true ; System . out . println ( currentNode . getSolution ( ) ) ; currentNode . printDiff ( ) ; System . out . println ( "<STR_LIT>" + currentNode . getHeight ( <NUM_LIT:0> ) ) ; System . out . println ( "<STR_LIT>" + open . size ( ) ) ; System . out . println ( "<STR_LIT>" + closed . size ( ) ) ; System . out . println ( "<STR_LIT>" + explosionCounter ) ; } else { explosionCounter ++ ; explode ( currentNode ) ; } } if ( ( System . currentTimeMillis ( ) - start ) >= TIME_LIMIT ) { timeUp = true ; } } if ( finished ) { System . out . println ( "<STR_LIT>" + ( System . currentTimeMillis ( ) - start ) ) ; System . out . println ( "<STR_LIT>" ) ; } else if ( failed ) { System . err . println ( "<STR_LIT>" ) ; } else if ( timeUp ) { System . err . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + open . size ( ) ) ; System . out . println ( "<STR_LIT>" + closed . size ( ) ) ; System . out . println ( "<STR_LIT>" + explosionCounter ) ; } } private boolean isGoal ( GPSNode currentNode ) { return currentNode . getState ( ) != null && currentNode . getState ( ) . compare ( problem . getGoalState ( ) ) ; } private boolean explode ( GPSNode node ) { MahjongGPSState state = ( MahjongGPSState ) node . getState ( ) ; System . out . println ( "<STR_LIT>" + state . getBoard ( ) . getPayersCount ( ) + "<STR_LIT>" + state . getBoard ( ) . getTilesCount ( ) ) ; for ( GPSRule rule : problem . getRules ( node . getState ( ) ) ) { GPSState newState = null ; try { newState = rule . evalRule ( node . getState ( ) ) ; } catch ( NotAppliableException e ) { } if ( newState != null && ! checkBranch ( node , newState ) && ! checkOpenAndClosed ( node . getCost ( ) + rule . getCost ( ) , newState ) ) { GPSNode newNode = new GPSNode ( newState , node . getCost ( ) + rule . getCost ( ) ) ; newNode . setParent ( node ) ; addNode ( newNode ) ; } } return true ; } private boolean checkOpenAndClosed ( float cost , GPSState state ) { for ( GPSNode openNode : open ) { if ( openNode . getState ( ) . compare ( state ) && openNode . getCost ( ) < cost ) { return true ; } } for ( GPSNode closedNode : closed ) { if ( closedNode . getState ( ) . compare ( state ) && closedNode . getCost ( ) < cost ) { return true ; } } return false ; } private boolean checkBranch ( GPSNode parent , GPSState state ) { if ( parent == null ) { return false ; } return checkBranch ( parent . getParent ( ) , state ) || state . compare ( parent . getState ( ) ) ; } public abstract void addNode ( GPSNode node ) ; } </s>
|
<s> package gps ; import g4 . MahjongGPSState ; import gps . api . GPSState ; import aga . mahjong . core . Board ; public class GPSNode { private GPSState state ; private GPSNode parent ; private float cost ; private Integer treeLevel ; public GPSNode ( GPSState state , float cost ) { super ( ) ; this . state = state ; this . cost = cost ; this . treeLevel = <NUM_LIT:0> ; } public GPSNode getParent ( ) { return parent ; } public void setParent ( GPSNode parent ) { this . parent = parent ; if ( parent != null ) { this . treeLevel = parent . getTreeLevel ( ) + <NUM_LIT:1> ; } } public GPSState getState ( ) { return state ; } public float getCost ( ) { return cost ; } public Integer getTreeLevel ( ) { return treeLevel ; } @ Override public String toString ( ) { return state . toString ( ) ; } public int getHeight ( int height ) { if ( this . parent == null ) { return height ; } return this . parent . getHeight ( height + <NUM_LIT:1> ) ; } public String getSolution ( ) { if ( this . parent == null ) { return this . state . toString ( ) ; } return this . parent . getSolution ( ) + "<STR_LIT:n>" + this . state ; } @ Override public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = ( int ) ( prime * result + cost ) ; result = prime * result + ( ( parent == null ) ? <NUM_LIT:0> : parent . hashCode ( ) ) ; result = prime * result + ( ( state == null ) ? <NUM_LIT:0> : state . hashCode ( ) ) ; return result ; } @ Override public boolean equals ( Object obj ) { if ( this == obj ) return true ; if ( obj == null ) return false ; if ( getClass ( ) != obj . getClass ( ) ) return false ; GPSNode other = ( GPSNode ) obj ; if ( cost != other . cost ) return false ; if ( parent == null ) { if ( other . parent != null ) return false ; } else if ( ! parent . equals ( other . parent ) ) return false ; if ( state == null ) { if ( other . state != null ) return false ; } else if ( ! state . equals ( other . state ) ) return false ; return true ; } public void printDiff ( ) { if ( this . parent == null ) { return ; } String moved = Board . getMove ( ( ( MahjongGPSState ) this . state ) . getBoard ( ) , ( ( MahjongGPSState ) this . parent . state ) . getBoard ( ) ) ; this . parent . printDiff ( ) ; System . out . println ( moved ) ; } } </s>
|
<s> package gps ; public enum SearchStrategy { BFS ( "<STR_LIT>" ) , DFS ( "<STR_LIT>" ) , IterativeDepth ( "<STR_LIT>" ) , AStar ( "<STR_LIT>" ) , Greedy ( "<STR_LIT>" ) ; public String value ; private SearchStrategy ( String value ) { this . value = value ; } public static SearchStrategy fromString ( String text ) { if ( text != null ) { for ( SearchStrategy s : SearchStrategy . values ( ) ) { if ( text . toUpperCase ( ) . equalsIgnoreCase ( s . value ) ) { return s ; } } } return null ; } } </s>
|
<s> package com . g7 . rules ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; import com . g7 . Jar ; import com . g7 . JarsState ; public class DropThree implements GPSRule { @ Override public GPSState evalRule ( GPSState arg0 ) throws NotAppliableException { JarsState oldJS = ( JarsState ) arg0 ; Jar [ ] jars = oldJS . getJars ( ) ; if ( jars [ <NUM_LIT:2> ] . getUsed ( ) == <NUM_LIT:0> ) { throw new NotAppliableException ( ) ; } JarsState newJS = new JarsState ( jars [ <NUM_LIT:0> ] . getUsed ( ) , jars [ <NUM_LIT:1> ] . getUsed ( ) , <NUM_LIT:0> ) ; return newJS ; } @ Override public float getCost ( ) { return <NUM_LIT:1> ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } } </s>
|
<s> package com . g7 . rules ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; import com . g7 . Jar ; import com . g7 . JarsState ; public class ThreeToTen implements GPSRule { @ Override public GPSState evalRule ( GPSState arg0 ) throws NotAppliableException { JarsState oldJS = ( JarsState ) arg0 ; Jar [ ] jars = oldJS . getJars ( ) ; int qty = Math . min ( jars [ <NUM_LIT:2> ] . getUsed ( ) , jars [ <NUM_LIT:0> ] . getMaxLiters ( ) - jars [ <NUM_LIT:0> ] . getUsed ( ) ) ; if ( qty == <NUM_LIT:0> ) { throw new NotAppliableException ( ) ; } JarsState newJS = new JarsState ( jars [ <NUM_LIT:0> ] . getUsed ( ) + qty , jars [ <NUM_LIT:1> ] . getUsed ( ) , jars [ <NUM_LIT:2> ] . getUsed ( ) - qty ) ; return newJS ; } @ Override public float getCost ( ) { return <NUM_LIT:1> ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } } </s>
|
<s> package com . g7 . rules ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; import com . g7 . Jar ; import com . g7 . JarsState ; public class SevenToTen implements GPSRule { @ Override public GPSState evalRule ( GPSState arg0 ) throws NotAppliableException { JarsState oldJS = ( JarsState ) arg0 ; Jar [ ] jars = oldJS . getJars ( ) ; int qty = Math . min ( jars [ <NUM_LIT:1> ] . getUsed ( ) , jars [ <NUM_LIT:0> ] . getMaxLiters ( ) - jars [ <NUM_LIT:0> ] . getUsed ( ) ) ; if ( qty == <NUM_LIT:0> ) { throw new NotAppliableException ( ) ; } JarsState newJS = new JarsState ( jars [ <NUM_LIT:0> ] . getUsed ( ) + qty , jars [ <NUM_LIT:1> ] . getUsed ( ) - qty , jars [ <NUM_LIT:2> ] . getUsed ( ) ) ; return newJS ; } @ Override public float getCost ( ) { return <NUM_LIT:1> ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } } </s>
|
<s> package com . g7 . rules ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; import com . g7 . Jar ; import com . g7 . JarsState ; public class DropSeven implements GPSRule { @ Override public GPSState evalRule ( GPSState arg0 ) throws NotAppliableException { JarsState oldJS = ( JarsState ) arg0 ; Jar [ ] jars = oldJS . getJars ( ) ; if ( jars [ <NUM_LIT:1> ] . getUsed ( ) == <NUM_LIT:0> ) { throw new NotAppliableException ( ) ; } JarsState newJS = new JarsState ( jars [ <NUM_LIT:0> ] . getUsed ( ) , <NUM_LIT:0> , jars [ <NUM_LIT:2> ] . getUsed ( ) ) ; return newJS ; } @ Override public float getCost ( ) { return <NUM_LIT:1> ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } } </s>
|
<s> package com . g7 . rules ; import com . g7 . Jar ; import com . g7 . JarsState ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; public class TenToSeven implements GPSRule { @ Override public GPSState evalRule ( GPSState arg0 ) throws NotAppliableException { JarsState oldJS = ( JarsState ) arg0 ; Jar [ ] jars = oldJS . getJars ( ) ; int qty = Math . min ( jars [ <NUM_LIT:0> ] . getUsed ( ) , jars [ <NUM_LIT:1> ] . getMaxLiters ( ) - jars [ <NUM_LIT:1> ] . getUsed ( ) ) ; if ( qty == <NUM_LIT:0> ) { throw new NotAppliableException ( ) ; } JarsState newJS = new JarsState ( jars [ <NUM_LIT:0> ] . getUsed ( ) - qty , jars [ <NUM_LIT:1> ] . getUsed ( ) + qty , jars [ <NUM_LIT:2> ] . getUsed ( ) ) ; return newJS ; } @ Override public float getCost ( ) { return <NUM_LIT:1> ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } } </s>
|
<s> package com . g7 . rules ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; import com . g7 . Jar ; import com . g7 . JarsState ; public class DropTen implements GPSRule { @ Override public GPSState evalRule ( GPSState arg0 ) throws NotAppliableException { JarsState oldJS = ( JarsState ) arg0 ; Jar [ ] jars = oldJS . getJars ( ) ; if ( jars [ <NUM_LIT:0> ] . getUsed ( ) == <NUM_LIT:0> ) { throw new NotAppliableException ( ) ; } JarsState newJS = new JarsState ( <NUM_LIT:0> , jars [ <NUM_LIT:1> ] . getUsed ( ) , jars [ <NUM_LIT:2> ] . getUsed ( ) ) ; return newJS ; } @ Override public float getCost ( ) { return <NUM_LIT:1> ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } } </s>
|
<s> package com . g7 . rules ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; import com . g7 . Jar ; import com . g7 . JarsState ; public class SevenToThree implements GPSRule { @ Override public GPSState evalRule ( GPSState arg0 ) throws NotAppliableException { JarsState oldJS = ( JarsState ) arg0 ; Jar [ ] jars = oldJS . getJars ( ) ; int qty = Math . min ( jars [ <NUM_LIT:1> ] . getUsed ( ) , jars [ <NUM_LIT:2> ] . getMaxLiters ( ) - jars [ <NUM_LIT:2> ] . getUsed ( ) ) ; if ( qty == <NUM_LIT:0> ) { throw new NotAppliableException ( ) ; } JarsState newJS = new JarsState ( jars [ <NUM_LIT:0> ] . getUsed ( ) , jars [ <NUM_LIT:1> ] . getUsed ( ) - qty , jars [ <NUM_LIT:2> ] . getUsed ( ) + qty ) ; return newJS ; } @ Override public float getCost ( ) { return <NUM_LIT:1> ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } } </s>
|
<s> package com . g7 . rules ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; import com . g7 . Jar ; import com . g7 . JarsState ; public class ThreeToSeven implements GPSRule { @ Override public GPSState evalRule ( GPSState arg0 ) throws NotAppliableException { JarsState oldJS = ( JarsState ) arg0 ; Jar [ ] jars = oldJS . getJars ( ) ; int qty = Math . min ( jars [ <NUM_LIT:2> ] . getUsed ( ) , jars [ <NUM_LIT:1> ] . getMaxLiters ( ) - jars [ <NUM_LIT:1> ] . getUsed ( ) ) ; if ( qty == <NUM_LIT:0> ) { throw new NotAppliableException ( ) ; } JarsState newJS = new JarsState ( jars [ <NUM_LIT:0> ] . getUsed ( ) , jars [ <NUM_LIT:1> ] . getUsed ( ) + qty , jars [ <NUM_LIT:2> ] . getUsed ( ) - qty ) ; return newJS ; } @ Override public float getCost ( ) { return <NUM_LIT:1> ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } } </s>
|
<s> package com . g7 . rules ; import com . g7 . Jar ; import com . g7 . JarsState ; import gps . api . GPSRule ; import gps . api . GPSState ; import gps . exception . NotAppliableException ; public class TenToThree implements GPSRule { @ Override public GPSState evalRule ( GPSState arg0 ) throws NotAppliableException { JarsState oldJS = ( JarsState ) arg0 ; Jar [ ] jars = oldJS . getJars ( ) ; int qty = Math . min ( jars [ <NUM_LIT:0> ] . getUsed ( ) , jars [ <NUM_LIT:2> ] . getMaxLiters ( ) - jars [ <NUM_LIT:2> ] . getUsed ( ) ) ; if ( qty == <NUM_LIT:0> ) { throw new NotAppliableException ( ) ; } JarsState newJS = new JarsState ( jars [ <NUM_LIT:0> ] . getUsed ( ) - qty , jars [ <NUM_LIT:1> ] . getUsed ( ) , jars [ <NUM_LIT:2> ] . getUsed ( ) + qty ) ; return newJS ; } @ Override public float getCost ( ) { return <NUM_LIT:1> ; } @ Override public String getName ( ) { return "<STR_LIT>" ; } } </s>
|
<s> package com . g7 ; import gps . api . GPSProblem ; import gps . api . GPSRule ; import gps . api . GPSState ; import java . util . ArrayList ; import java . util . List ; import com . g7 . rules . DropSeven ; import com . g7 . rules . DropTen ; import com . g7 . rules . DropThree ; import com . g7 . rules . SevenToTen ; import com . g7 . rules . SevenToThree ; import com . g7 . rules . TenToSeven ; import com . g7 . rules . TenToThree ; import com . g7 . rules . ThreeToSeven ; import com . g7 . rules . ThreeToTen ; public class JarsProblem implements GPSProblem { @ Override public GPSState getGoalState ( ) { return new JarsState ( <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:0> ) ; } @ Override public float getHValue ( GPSState arg0 ) { JarsState js = ( JarsState ) arg0 ; Jar [ ] jars = js . getJars ( ) ; int totalQuantity = jars [ <NUM_LIT:0> ] . getUsed ( ) + jars [ <NUM_LIT:1> ] . getUsed ( ) + jars [ <NUM_LIT:2> ] . getUsed ( ) ; if ( totalQuantity < <NUM_LIT:5> ) return Float . MAX_VALUE ; if ( jars [ <NUM_LIT:0> ] . getUsed ( ) == <NUM_LIT:5> ) { return <NUM_LIT:0> ; } return <NUM_LIT> ; } @ Override public GPSState getInitState ( ) { return new JarsState ( ) ; } @ Override public List < GPSRule > getRules ( GPSState state ) { ArrayList < GPSRule > ret = new ArrayList < GPSRule > ( <NUM_LIT:9> ) ; ret . add ( new DropTen ( ) ) ; ret . add ( new DropSeven ( ) ) ; ret . add ( new DropThree ( ) ) ; ret . add ( new TenToSeven ( ) ) ; ret . add ( new TenToThree ( ) ) ; ret . add ( new SevenToTen ( ) ) ; ret . add ( new SevenToThree ( ) ) ; ret . add ( new ThreeToTen ( ) ) ; ret . add ( new ThreeToSeven ( ) ) ; return ret ; } } </s>
|
<s> package com . g7 ; import gps . api . GPSState ; public class JarsState implements GPSState { public static int STEP ; private Jar [ ] jars = new Jar [ <NUM_LIT:3> ] ; public JarsState ( ) { jars [ <NUM_LIT:0> ] = new Jar ( <NUM_LIT:10> , <NUM_LIT:10> ) ; jars [ <NUM_LIT:1> ] = new Jar ( <NUM_LIT:7> , <NUM_LIT:0> ) ; jars [ <NUM_LIT:2> ] = new Jar ( <NUM_LIT:3> , <NUM_LIT:0> ) ; } public JarsState ( int ten , int seven , int three ) { this . jars [ <NUM_LIT:0> ] = new Jar ( <NUM_LIT:10> , ten ) ; this . jars [ <NUM_LIT:1> ] = new Jar ( <NUM_LIT:7> , seven ) ; this . jars [ <NUM_LIT:2> ] = new Jar ( <NUM_LIT:3> , three ) ; } @ Override public boolean compare ( GPSState var ) { JarsState js = ( JarsState ) var ; Jar [ ] jars = js . getJars ( ) ; if ( this . jars [ <NUM_LIT:0> ] . getUsed ( ) == <NUM_LIT:5> && jars [ <NUM_LIT:0> ] . getUsed ( ) == <NUM_LIT:5> ) return true ; for ( int i = <NUM_LIT:0> ; i < jars . length ; i ++ ) { if ( jars [ i ] . getMaxLiters ( ) != this . jars [ i ] . getMaxLiters ( ) ) return false ; if ( jars [ i ] . getUsed ( ) != this . jars [ i ] . getUsed ( ) ) return false ; } return true ; } public Jar [ ] getJars ( ) { return jars ; } public void setJars ( Jar [ ] jars ) { this . jars = jars ; } public String toString ( ) { return String . format ( "<STR_LIT>" , STEP ++ , this . jars [ <NUM_LIT:0> ] . getUsed ( ) , this . jars [ <NUM_LIT:1> ] . getUsed ( ) , this . jars [ <NUM_LIT:2> ] . getUsed ( ) ) ; } } </s>
|
<s> package com . g7 ; public class Jar { private int maxLiters ; private int used ; public Jar ( int maxLiters , int used ) { this . maxLiters = maxLiters ; this . used = used ; } public int getMaxLiters ( ) { return maxLiters ; } public void setMaxLiters ( int maxLiters ) { this . maxLiters = maxLiters ; } public int getUsed ( ) { return used ; } public void setUsed ( int used ) { this . used = used ; } } </s>
|
<s> package aga . mahjong . core ; import java . util . ArrayList ; public class SolvableArrange implements IArrangeStrategy { public void arrange ( Board board ) { java . util . Random rnd = new java . util . Random ( ) ; ArrayList < Tile > tiles = new ArrayList < Tile > ( TileSet . getAllTiles ( ) ) ; while ( tiles . size ( ) > <NUM_LIT:0> ) { Tile tile1 = tiles . get ( <NUM_LIT:0> ) ; Tile tile2 = tiles . get ( <NUM_LIT:0> ) ; Cell [ ] freePositions = board . getFreePositions ( ) ; if ( freePositions . length == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" ) ; break ; } Position pos1 = freePositions [ rnd . nextInt ( freePositions . length ) ] . getPosition ( ) ; board . setItem ( pos1 , tile1 ) ; freePositions = board . getFreePositions ( ) ; if ( freePositions . length == <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" ) ; break ; } Position pos2 = freePositions [ rnd . nextInt ( freePositions . length ) ] . getPosition ( ) ; board . setItem ( pos2 , tile2 ) ; tiles . remove ( tile1 ) ; tiles . remove ( tile2 ) ; } } } </s>
|
<s> package aga . mahjong . core ; import java . io . Serializable ; public final class Tile implements Serializable { private static final long serialVersionUID = - <NUM_LIT> ; private final TileKind kind ; private final int number ; public TileKind getKind ( ) { return kind ; } public int getNumber ( ) { return number ; } public Tile ( TileKind kind , int number ) { this . kind = kind ; this . number = number ; } @ Override public String toString ( ) { String str = "<STR_LIT>" ; switch ( getKind ( ) ) { case Bamboo : str = "<STR_LIT:B>" ; break ; case Character : str = "<STR_LIT:C>" ; break ; case Dot : str = "<STR_LIT:D>" ; break ; case Dragon : str = "<STR_LIT>" ; break ; case Flower : str = "<STR_LIT:F>" ; break ; case Season : str = "<STR_LIT:S>" ; break ; case Wind : str = "<STR_LIT>" ; break ; } return String . format ( "<STR_LIT>" , str , getNumber ( ) ) ; } public static boolean isMatch ( Tile a , Tile b ) { if ( a . getKind ( ) . equals ( b . getKind ( ) ) ) { if ( a . getKind ( ) . equals ( TileKind . Season ) || a . getKind ( ) . equals ( TileKind . Flower ) ) { return true ; } else { return a . getNumber ( ) == b . getNumber ( ) ; } } else { return false ; } } @ Override public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = prime * result + ( ( kind == null ) ? <NUM_LIT:0> : kind . hashCode ( ) ) ; result = prime * result + number ; return result ; } @ Override public boolean equals ( Object obj ) { if ( this == obj ) return true ; if ( obj == null ) return false ; if ( getClass ( ) != obj . getClass ( ) ) return false ; Tile other = ( Tile ) obj ; if ( kind != other . kind ) return false ; if ( number != other . number ) return false ; return true ; } } </s>
|
<s> package aga . mahjong . core ; import java . io . Serializable ; public final class Cell implements Serializable { private static final long serialVersionUID = <NUM_LIT> ; private final Position position ; private final Tile tile ; public Position getPosition ( ) { return position ; } public Tile getTile ( ) { return tile ; } public Cell ( Position pos , Tile tile ) { this . position = pos ; this . tile = tile ; } @ Override public String toString ( ) { return String . format ( "<STR_LIT>" , getPosition ( ) , getTile ( ) ) ; } @ Override public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = prime * result + ( ( position == null ) ? <NUM_LIT:0> : position . hashCode ( ) ) ; result = prime * result + ( ( tile == null ) ? <NUM_LIT:0> : tile . hashCode ( ) ) ; return result ; } @ Override public boolean equals ( Object obj ) { if ( this == obj ) return true ; if ( obj == null ) return false ; if ( getClass ( ) != obj . getClass ( ) ) return false ; Cell other = ( Cell ) obj ; if ( position == null ) { if ( other . position != null ) return false ; } else if ( ! position . equals ( other . position ) ) return false ; if ( tile == null ) { if ( other . tile != null ) return false ; } else if ( ! tile . equals ( other . tile ) ) return false ; return true ; } } </s>
|
<s> package aga . mahjong . core ; public interface IArrangeStrategy { void arrange ( Board board ) ; } </s>
|
<s> package aga . mahjong . core ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . io . Serializable ; public final class Position implements Serializable { private static final long serialVersionUID = - <NUM_LIT> ; private final int row ; private final int column ; private final int layer ; public int getRow ( ) { return row ; } public int getColumn ( ) { return column ; } public int getLayer ( ) { return layer ; } public Position ( int layer , int row , int column ) { this . layer = layer ; this . row = row ; this . column = column ; } @ Override public String toString ( ) { return String . format ( "<STR_LIT>" , getLayer ( ) , getRow ( ) , getColumn ( ) ) ; } public void write ( OutputStream stream ) throws IOException { stream . write ( ( byte ) layer ) ; stream . write ( ( byte ) row ) ; stream . write ( ( byte ) column ) ; } public static Position read ( InputStream stream ) throws IOException { int lay = stream . read ( ) ; int row = stream . read ( ) ; int col = stream . read ( ) ; return new Position ( lay , row , col ) ; } @ Override public int hashCode ( ) { final int prime = <NUM_LIT:31> ; int result = <NUM_LIT:1> ; result = prime * result + column ; result = prime * result + layer ; result = prime * result + row ; return result ; } @ Override public boolean equals ( Object obj ) { if ( this == obj ) return true ; if ( obj == null ) return false ; if ( getClass ( ) != obj . getClass ( ) ) return false ; Position other = ( Position ) obj ; if ( column != other . column ) return false ; if ( layer != other . layer ) return false ; if ( row != other . row ) return false ; return true ; } } </s>
|
<s> package aga . mahjong . core ; import java . io . IOException ; import java . io . InputStream ; import java . io . OutputStream ; import java . io . Serializable ; import java . util . ArrayList ; public class Layout implements Serializable { private static final long serialVersionUID = - <NUM_LIT> ; protected ArrayList < Position > positions = new ArrayList < Position > ( ) ; protected String name ; protected int layerCount ; protected int rowCount ; protected int columnCount ; public java . util . ArrayList < Position > getPositions ( ) { return positions ; } public String getName ( ) { return name ; } public void setName ( String name ) { this . name = name ; } public int getLayerCount ( ) { return layerCount ; } public int getRowCount ( ) { return rowCount ; } public int getColumnCount ( ) { return columnCount ; } @ Override public String toString ( ) { return getName ( ) ; } public static Layout load ( InputStream stream ) throws IOException { Layout res = new Layout ( ) ; int count = stream . read ( ) ; res . positions = new java . util . ArrayList < Position > ( count ) ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { Position pos = Position . read ( stream ) ; res . getPositions ( ) . add ( pos ) ; res . layerCount = Math . max ( res . layerCount , pos . getLayer ( ) + <NUM_LIT:1> ) ; res . rowCount = Math . max ( res . rowCount , pos . getRow ( ) + <NUM_LIT:1> ) ; res . columnCount = Math . max ( res . columnCount , pos . getColumn ( ) + <NUM_LIT:1> ) ; } return res ; } public void save ( OutputStream stream ) throws IOException { stream . write ( getPositions ( ) . size ( ) ) ; for ( Position pos : getPositions ( ) ) { pos . write ( stream ) ; } } } </s>
|
<s> package aga . mahjong . core ; public class Pair { private final Position position1 ; private final Position position2 ; public Position getPosition1 ( ) { return position1 ; } public Position getPosition2 ( ) { return position2 ; } public Pair ( Position pos1 , Position pos2 ) { position1 = pos1 ; position2 = pos2 ; } @ Override public String toString ( ) { return String . format ( "<STR_LIT>" , getPosition1 ( ) , getPosition2 ( ) ) ; } @ Override public boolean equals ( Object o ) { Pair x = this ; Pair y = ( Pair ) o ; return ( ( x . getPosition1 ( ) . equals ( y . getPosition1 ( ) ) && x . getPosition2 ( ) . equals ( y . getPosition2 ( ) ) ) || ( x . getPosition1 ( ) . equals ( y . getPosition2 ( ) ) && x . getPosition2 ( ) . equals ( y . getPosition1 ( ) ) ) ) ; } @ Override public int hashCode ( ) { return <NUM_LIT:0> ; } } </s>
|
<s> package aga . mahjong . core ; import java . util . ArrayList ; import java . util . Collection ; public class TileSet { private static ArrayList < Tile > list ; public static Collection < Tile > getAllTiles ( ) { if ( list == null ) { list = new java . util . ArrayList < Tile > ( ) ; for ( int n = <NUM_LIT:1> ; n <= <NUM_LIT:4> ; n ++ ) { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:9> ; i ++ ) { list . add ( new Tile ( TileKind . Dot , i ) ) ; } } for ( int n = <NUM_LIT:1> ; n <= <NUM_LIT:4> ; n ++ ) { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:9> ; i ++ ) { list . add ( new Tile ( TileKind . Bamboo , i ) ) ; } } for ( int n = <NUM_LIT:1> ; n <= <NUM_LIT:4> ; n ++ ) { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:9> ; i ++ ) { list . add ( new Tile ( TileKind . Character , i ) ) ; } } for ( int n = <NUM_LIT:1> ; n <= <NUM_LIT:4> ; n ++ ) { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:4> ; i ++ ) { list . add ( new Tile ( TileKind . Wind , i ) ) ; } } for ( int n = <NUM_LIT:1> ; n <= <NUM_LIT:4> ; n ++ ) { for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:3> ; i ++ ) { list . add ( new Tile ( TileKind . Dragon , i ) ) ; } } for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:4> ; i ++ ) { list . add ( new Tile ( TileKind . Season , i ) ) ; } for ( int i = <NUM_LIT:1> ; i <= <NUM_LIT:4> ; i ++ ) { list . add ( new Tile ( TileKind . Flower , i ) ) ; } assert list . size ( ) == <NUM_LIT> ; } return list ; } } </s>
|
<s> package aga . mahjong . core ; public enum TileKind { None , Dot , Character , Bamboo , Wind , Dragon , Season , Flower ; public int getValue ( ) { return this . ordinal ( ) ; } public static TileKind forValue ( int value ) { return values ( ) [ value ] ; } } </s>
|
<s> package aga . mahjong . core ; import java . io . Serializable ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . HashSet ; public class Board implements Serializable { private static final long serialVersionUID = - <NUM_LIT> ; private ArrayList < Position > selection = new ArrayList < Position > ( ) ; private final Layout layout ; private Tile [ ] [ ] [ ] tiles ; private int layerCount , rowCount , columnCount ; private int tilesCount , payersCount ; public static String getMove ( Board a , Board b ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = <NUM_LIT:0> ; i < a . layerCount ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < a . rowCount ; j ++ ) { for ( int k = <NUM_LIT:0> ; k < a . columnCount ; k ++ ) { Tile tile1 = a . getItem ( i , j , k ) ; Tile tile2 = b . getItem ( i , j , k ) ; if ( tile1 == null && tile2 != null ) { sb . append ( String . format ( "<STR_LIT>" , tile2 . toString ( ) , i , j , k ) ) ; } else if ( tile1 != null && tile2 == null ) { sb . append ( String . format ( "<STR_LIT>" , tile1 . toString ( ) , i , j , k ) ) ; } } } } sb . append ( "<STR_LIT:n>" ) ; return sb . toString ( ) ; } public static Pair getMoveInPair ( Board a , Board b ) { Position pos1 = null ; Position pos2 = null ; for ( int i = <NUM_LIT:0> ; i < a . layerCount ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < a . rowCount ; j ++ ) { for ( int k = <NUM_LIT:0> ; k < a . columnCount ; k ++ ) { Tile tile1 = a . getItem ( i , j , k ) ; Tile tile2 = b . getItem ( i , j , k ) ; if ( tile1 == null && tile2 != null ) { if ( pos1 == null ) { pos1 = new Position ( i , j , k ) ; } else { pos2 = new Position ( i , j , k ) ; break ; } } else if ( tile1 != null && tile2 == null ) { if ( pos1 == null ) { pos1 = new Position ( i , j , k ) ; } else { pos2 = new Position ( i , j , k ) ; break ; } } } } } return new Pair ( pos1 , pos2 ) ; } public boolean isValid ( ) { HashMap < String , Integer > map = new HashMap < String , Integer > ( ) ; for ( int i = <NUM_LIT:0> ; i < layerCount ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < rowCount ; j ++ ) { for ( int k = <NUM_LIT:0> ; k < columnCount ; k ++ ) { Tile tile = getItem ( i , j , k ) ; if ( tile == null ) { continue ; } String key = null ; if ( tile . toString ( ) . contains ( "<STR_LIT:S>" ) ) { key = "<STR_LIT:S>" ; } else if ( tile . toString ( ) . contains ( "<STR_LIT:F>" ) ) { key = "<STR_LIT:F>" ; } else { key = tile . toString ( ) ; } Integer amount = map . get ( key ) ; if ( amount == null ) { map . put ( key , <NUM_LIT:1> ) ; } else { map . put ( key , amount + <NUM_LIT:1> ) ; } } } } boolean ret = true ; for ( String key : map . keySet ( ) ) { Integer amount = map . get ( key ) ; if ( amount % <NUM_LIT:2> != <NUM_LIT:0> ) { System . out . println ( "<STR_LIT>" + key + "<STR_LIT>" + amount ) ; ret = false ; break ; } } return ret ; } @ Override public Object clone ( ) throws CloneNotSupportedException { Board clone = new Board ( layout ) ; for ( int i = <NUM_LIT:0> ; i < layerCount ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < rowCount ; j ++ ) { for ( int k = <NUM_LIT:0> ; k < columnCount ; k ++ ) { clone . tiles [ i ] [ j ] [ k ] = tiles [ i ] [ j ] [ k ] ; } } } clone . layerCount = layerCount ; clone . rowCount = rowCount ; clone . columnCount = columnCount ; clone . tilesCount = tilesCount ; clone . payersCount = payersCount ; return clone ; } @ Override public String toString ( ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = <NUM_LIT:0> ; i < layerCount ; i ++ ) { for ( int j = <NUM_LIT:0> ; j < rowCount ; j ++ ) { for ( int k = <NUM_LIT:0> ; k < columnCount ; k ++ ) { if ( tiles [ i ] [ j ] [ k ] == null ) { sb . append ( "<STR_LIT:->" ) ; } else { sb . append ( tiles [ i ] [ j ] [ k ] . toString ( ) ) ; } } sb . append ( "<STR_LIT:n>" ) ; } sb . append ( "<STR_LIT>" + i + "<STR_LIT>" ) ; } return sb . toString ( ) ; } public Tile getItem ( Position pos ) { return tiles [ pos . getLayer ( ) ] [ pos . getRow ( ) ] [ pos . getColumn ( ) ] ; } public void setItem ( Position pos , Tile value ) { setItem ( pos . getLayer ( ) , pos . getRow ( ) , pos . getColumn ( ) , value ) ; } public Tile getItem ( int layer , int row , int column ) { if ( layer < getLayerCount ( ) && row < getRowCount ( ) && column < getColumnCount ( ) && layer >= <NUM_LIT:0> && row >= <NUM_LIT:0> && column >= <NUM_LIT:0> ) { return tiles [ layer ] [ row ] [ column ] ; } else { return null ; } } public void setItem ( int layer , int row , int column , Tile value ) { if ( layer < getLayerCount ( ) && row < getRowCount ( ) && column < getColumnCount ( ) && layer >= <NUM_LIT:0> && row >= <NUM_LIT:0> && column >= <NUM_LIT:0> ) { tiles [ layer ] [ row ] [ column ] = value ; resetStatus ( ) ; } } public java . util . List < Position > getSelection ( ) { return selection ; } public int getLayerCount ( ) { return layerCount ; } public int getRowCount ( ) { return rowCount ; } public int getColumnCount ( ) { return columnCount ; } public Iterable < Position > getAllPositions ( ) { return layout . getPositions ( ) ; } public synchronized int getTilesCount ( ) { if ( tilesCount < <NUM_LIT:0> ) { tilesCount = <NUM_LIT:0> ; for ( Position p : getAllPositions ( ) ) { if ( getItem ( p ) != null ) tilesCount ++ ; } } return tilesCount ; } public int getPayersCount ( ) { if ( payersCount < <NUM_LIT:0> ) { payersCount = getPairs ( ) . length ; } return payersCount ; } public Board ( Layout layout ) { this . layout = layout ; tiles = new Tile [ layout . getLayerCount ( ) ] [ layout . getRowCount ( ) ] [ layout . getColumnCount ( ) ] ; layerCount = layout . getLayerCount ( ) ; rowCount = layout . getRowCount ( ) ; columnCount = layout . getColumnCount ( ) ; resetStatus ( ) ; } public Cell [ ] getFreePositions ( ) { ArrayList < Cell > res = new ArrayList < Cell > ( ) ; for ( Position p : getAllPositions ( ) ) { if ( getItem ( p ) != null && isFree ( p ) ) res . add ( new Cell ( p , this . getItem ( p ) ) ) ; } return res . toArray ( new Cell [ res . size ( ) ] ) ; } public boolean isFree ( Position pos ) { boolean flag1 = true ; boolean flag2 = true ; for ( int row = pos . getRow ( ) - <NUM_LIT:1> ; row <= pos . getRow ( ) + <NUM_LIT:1> ; row ++ ) { if ( getItem ( pos . getLayer ( ) , row , pos . getColumn ( ) - <NUM_LIT:2> ) != null ) { flag1 = false ; } if ( getItem ( pos . getLayer ( ) , row , pos . getColumn ( ) + <NUM_LIT:2> ) != null ) { flag2 = false ; } } if ( flag1 || flag2 ) { if ( pos . getLayer ( ) < getLayerCount ( ) - <NUM_LIT:1> ) { for ( int row = pos . getRow ( ) - <NUM_LIT:1> ; row <= pos . getRow ( ) + <NUM_LIT:1> ; row ++ ) { for ( int col = pos . getColumn ( ) - <NUM_LIT:1> ; col <= pos . getColumn ( ) + <NUM_LIT:1> ; col ++ ) { if ( getItem ( pos . getLayer ( ) + <NUM_LIT:1> , row , col ) != null ) { return false ; } } } } return true ; } else { return false ; } } public Pair [ ] getPairs ( ) { HashSet < Pair > res = new HashSet < Pair > ( ) ; Cell [ ] positions = getFreePositions ( ) ; for ( Cell p : positions ) { for ( Cell q : positions ) { if ( ! p . getPosition ( ) . equals ( q . getPosition ( ) ) && Tile . isMatch ( p . getTile ( ) , q . getTile ( ) ) ) res . add ( new Pair ( p . getPosition ( ) , q . getPosition ( ) ) ) ; } } return res . toArray ( new Pair [ res . size ( ) ] ) ; } private void resetStatus ( ) { payersCount = tilesCount = - <NUM_LIT:1> ; } } </s>
|
<s> package aga . mahjong . core ; import java . util . ArrayList ; public class RandomArrange implements IArrangeStrategy { public void arrange ( Board board ) { java . util . Random rnd = new java . util . Random ( ) ; ArrayList < Tile > initLayout = new ArrayList < Tile > ( ) ; ArrayList < Tile > tiles = new ArrayList < Tile > ( TileSet . getAllTiles ( ) ) ; for ( Position pos : board . getAllPositions ( ) ) { if ( pos . getLayer ( ) > <NUM_LIT:0> ) { break ; } if ( pos . getRow ( ) == <NUM_LIT:0> ) { int i = rnd . nextInt ( tiles . size ( ) ) ; board . setItem ( pos , tiles . get ( i ) ) ; initLayout . add ( tiles . get ( i ) ) ; tiles . remove ( i ) ; } } } } </s>
|
<s> package com . mapr ; public class RpcCounter { } </s>
|
<s> package com . mapr . stats ; import java . util . Random ; public class GammaNormalBayesModel extends BayesianBandit { public GammaNormalBayesModel ( int bandits , Random gen ) { for ( int i = <NUM_LIT:0> ; i < bandits ; i ++ ) { addModelDistribution ( new GammaNormalDistribution ( <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , gen ) ) ; } } } </s>
|
<s> package com . mapr . stats ; import org . apache . mahout . math . jet . random . Normal ; import java . util . Random ; public class NormalDistributionSampler extends DistributionGenerator { private double sd ; private Random gen ; public NormalDistributionSampler ( double sd , Random gen ) { this . sd = sd ; this . gen = gen ; } @ Override public DistributionWithMean nextDistribution ( ) { double mean = gen . nextDouble ( ) ; return new DistributionWithMean ( new Normal ( mean , sd , gen ) , mean ) ; } } </s>
|
<s> package com . mapr . stats ; import org . apache . mahout . math . jet . random . AbstractContinousDistribution ; public abstract class AbstractBayesianDistribution extends AbstractContinousDistribution { @ Override public abstract double nextDouble ( ) ; public abstract void add ( double x ) ; public abstract double nextMean ( ) ; public abstract AbstractContinousDistribution posteriorDistribution ( ) ; } </s>
|
<s> package com . mapr . stats ; abstract class DistributionGenerator { public abstract DistributionWithMean nextDistribution ( ) ; } </s>
|
<s> package com . mapr . stats ; import com . google . common . collect . ImmutableList ; import com . google . common . collect . Lists ; import org . apache . mahout . math . stats . OnlineSummarizer ; import org . uncommons . maths . random . MersenneTwisterRNG ; import java . io . FileNotFoundException ; import java . io . PrintWriter ; import java . lang . reflect . InvocationTargetException ; import java . util . Arrays ; import java . util . Collections ; import java . util . List ; import java . util . Random ; import java . util . concurrent . Callable ; import java . util . concurrent . ExecutorService ; import java . util . concurrent . Executors ; public class BanditTrainer { private static final int BUCKET_SIZE = <NUM_LIT:1> ; public static void main ( String [ ] args ) throws FileNotFoundException , NoSuchMethodException , InvocationTargetException , InstantiationException , IllegalAccessException , InterruptedException { int threads = <NUM_LIT:16> ; if ( args . length > <NUM_LIT:0> ) { threads = Integer . parseInt ( args [ <NUM_LIT:0> ] ) ; } System . out . printf ( "<STR_LIT>" ) ; ExecutorService ex = Executors . newFixedThreadPool ( threads ) ; List < Callable < Integer > > tasks = ImmutableList . of ( new Callable < Integer > ( ) { @ Override public Integer call ( ) { try { totalRegret ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1000> , <NUM_LIT:2> , <NUM_LIT> , new GammaNormalBayesFactory ( ) , new NormalDistributionSampler ( <NUM_LIT> , new Random ( ) ) ) ; System . out . printf ( "<STR_LIT>" ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } return null ; } } , new Callable < Integer > ( ) { @ Override public Integer call ( ) { try { totalRegret ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1000> , <NUM_LIT:2> , <NUM_LIT> , new EpsilonGreedyFactory ( <NUM_LIT> ) , new NormalDistributionSampler ( <NUM_LIT:1> , new Random ( ) ) ) ; System . out . printf ( "<STR_LIT>" ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } return null ; } } , new Callable < Integer > ( ) { @ Override public Integer call ( ) { try { totalRegret ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> , new GammaNormalBayesFactory ( ) , new NormalDistributionSampler ( <NUM_LIT:1> , new Random ( ) ) ) ; System . out . printf ( "<STR_LIT>" ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } return null ; } } , new Callable < Integer > ( ) { @ Override public Integer call ( ) { try { totalRegret ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1000> , <NUM_LIT:10> , <NUM_LIT:1000> , new GammaNormalBayesFactory ( ) , new NormalDistributionSampler ( <NUM_LIT> , new Random ( ) ) ) ; System . out . printf ( "<STR_LIT>" ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } return null ; } } , new Callable < Integer > ( ) { @ Override public Integer call ( ) { try { totalRegret ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1000> , <NUM_LIT:100> , <NUM_LIT:1000> , new GammaNormalBayesFactory ( ) , new NormalDistributionSampler ( <NUM_LIT> , new Random ( ) ) ) ; System . out . printf ( "<STR_LIT>" ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } return null ; } } , new Callable < Integer > ( ) { @ Override public Integer call ( ) { try { totalRegret ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1000> , <NUM_LIT:2> , <NUM_LIT:1000> , new BetaBayesFactory ( ) , new BinomialDistributionSampler ( <NUM_LIT:1> , <NUM_LIT:1> , new Random ( ) ) ) ; System . out . printf ( "<STR_LIT>" ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } return null ; } } , new Callable < Integer > ( ) { @ Override public Integer call ( ) { try { totalRegret ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1000> , <NUM_LIT:100> , <NUM_LIT:1000> , new BetaBayesFactory ( ) , new BinomialDistributionSampler ( <NUM_LIT:1> , <NUM_LIT:1> , new Random ( ) ) ) ; System . out . printf ( "<STR_LIT>" ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } return null ; } } , new Callable < Integer > ( ) { @ Override public Integer call ( ) { try { totalRegret ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1000> , <NUM_LIT:20> , <NUM_LIT:1000> , new BetaBayesFactory ( ) , new BinomialDistributionSampler ( <NUM_LIT:1> , <NUM_LIT:1> , new Random ( ) ) ) ; System . out . printf ( "<STR_LIT>" ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } return null ; } } ) ; ex . invokeAll ( tasks ) ; ex . shutdown ( ) ; System . out . printf ( "<STR_LIT>" ) ; } public static double commitTime ( String outputFile , int n , double p1 , double p2 , int cutoff ) throws FileNotFoundException { PrintWriter out = new PrintWriter ( outputFile ) ; try { Random gen = new Random ( ) ; out . printf ( "<STR_LIT>" ) ; int impressions = <NUM_LIT:0> ; int correct = <NUM_LIT:0> ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:1000> ; j ++ ) { double [ ] p = { p1 , p2 } ; Arrays . sort ( p ) ; BetaBayesModel s = new BetaBayesModel ( ) ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { int k = s . sample ( ) ; out . printf ( "<STR_LIT>" , i , k ) ; if ( i > cutoff ) { impressions ++ ; correct += k ; } final double u = gen . nextDouble ( ) ; boolean r = u <= p [ k ] ; s . train ( k , r ? <NUM_LIT:1> : <NUM_LIT:0> ) ; } } return ( double ) correct / impressions ; } finally { out . close ( ) ; } } @ Deprecated private static void errorRate ( String outputFile ) throws FileNotFoundException { PrintWriter out = new PrintWriter ( outputFile ) ; try { out . printf ( "<STR_LIT>" ) ; Random gen = new Random ( ) ; for ( int n : new int [ ] { <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT:100> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:1000> , <NUM_LIT> , <NUM_LIT> } ) { System . out . printf ( "<STR_LIT>" , n ) ; for ( int j = <NUM_LIT:0> ; j < <NUM_LIT:1000> * ( n < <NUM_LIT> ? <NUM_LIT:10> : <NUM_LIT:1> ) ; j ++ ) { double [ ] p = { gen . nextDouble ( ) , gen . nextDouble ( ) } ; Arrays . sort ( p ) ; BetaBayesModel s = new BetaBayesModel ( ) ; int wins = <NUM_LIT:0> ; int lateWins = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { int k = s . sample ( ) ; final double u = gen . nextDouble ( ) ; boolean r = u <= p [ k ] ; wins += r ? <NUM_LIT:1> : <NUM_LIT:0> ; if ( i > n / <NUM_LIT:2> ) { lateWins += r ? <NUM_LIT:1> : <NUM_LIT:0> ; } s . train ( k , r ? <NUM_LIT:1> : <NUM_LIT:0> ) ; } out . printf ( "<STR_LIT>" , p [ <NUM_LIT:0> ] , p [ <NUM_LIT:1> ] , n , wins , lateWins ) ; } } } finally { out . close ( ) ; } } public static double averageRegret ( String outputFile , int [ ] sizes , int replications , int bandits ) throws FileNotFoundException { PrintWriter out = new PrintWriter ( outputFile ) ; try { double finalMedianRegret = <NUM_LIT:0> ; Random gen = new Random ( ) ; out . printf ( "<STR_LIT>" ) ; for ( int n : sizes ) { System . out . printf ( "<STR_LIT>" , n ) ; OnlineSummarizer summary = new OnlineSummarizer ( ) ; for ( int j = <NUM_LIT:0> ; j < replications ; j ++ ) { double [ ] p = new double [ bandits ] ; for ( int k = <NUM_LIT:0> ; k < bandits ; k ++ ) { p [ k ] = gen . nextDouble ( ) ; } Arrays . sort ( p ) ; BetaBayesModel s = new BetaBayesModel ( bandits , new MersenneTwisterRNG ( ) ) ; int wins = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { int k = s . sample ( ) ; final double u = gen . nextDouble ( ) ; boolean r = u <= p [ k ] ; wins += r ? <NUM_LIT:1> : <NUM_LIT:0> ; s . train ( k , r ? <NUM_LIT:1> : <NUM_LIT:0> ) ; } summary . add ( ( double ) wins / n - p [ bandits - <NUM_LIT:1> ] ) ; } out . printf ( "<STR_LIT>" , n ) ; for ( int quartile = <NUM_LIT:0> ; quartile <= <NUM_LIT:4> ; quartile ++ ) { out . printf ( "<STR_LIT>" , summary . getQuartile ( quartile ) , quartile < <NUM_LIT:4> ? "<STR_LIT:t>" : "<STR_LIT:n>" ) ; } out . flush ( ) ; finalMedianRegret = summary . getMedian ( ) ; } return finalMedianRegret ; } finally { out . close ( ) ; } } public static double totalRegret ( String cumulativeOutput , String perTurnOutput , int replications , int bandits , int maxSteps , BanditFactory modelFactory , DistributionGenerator refSampler ) throws FileNotFoundException { List < OnlineSummarizer > cumulativeRegret = Lists . newArrayList ( ) ; List < OnlineSummarizer > localRegret = Lists . newArrayList ( ) ; List < Integer > steps = Lists . newArrayList ( ) ; List < Integer > localSteps = Lists . newArrayList ( ) ; Random gen = new Random ( ) ; for ( int j = <NUM_LIT:0> ; j < replications ; j ++ ) { BayesianBandit s = modelFactory . createBandit ( bandits , gen ) ; List < DistributionWithMean > refs = Lists . newArrayList ( ) ; for ( int k = <NUM_LIT:0> ; k < bandits ; k ++ ) { refs . add ( refSampler . nextDistribution ( ) ) ; } Collections . sort ( refs ) ; double wins = <NUM_LIT:0> ; int k = <NUM_LIT:0> ; int delta = <NUM_LIT:1> ; double totalRegret = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < maxSteps ; i ++ ) { if ( i > <NUM_LIT> * delta ) { delta = bump ( delta ) ; } int choice = s . sample ( ) ; double r = refs . get ( choice ) . nextDouble ( ) ; totalRegret += refs . get ( bandits - <NUM_LIT:1> ) . getMean ( ) - refs . get ( choice ) . getMean ( ) ; if ( ( i + <NUM_LIT:1> ) % delta == <NUM_LIT:0> ) { if ( cumulativeRegret . size ( ) <= k ) { cumulativeRegret . add ( new OnlineSummarizer ( ) ) ; steps . add ( i + <NUM_LIT:1> ) ; } cumulativeRegret . get ( k ) . add ( totalRegret ) ; k ++ ; } if ( localRegret . size ( ) <= i / BUCKET_SIZE ) { localRegret . add ( new OnlineSummarizer ( ) ) ; localSteps . add ( i ) ; } double thisTrialRegret = refs . get ( bandits - <NUM_LIT:1> ) . getMean ( ) - refs . get ( choice ) . getMean ( ) ; localRegret . get ( i / BUCKET_SIZE ) . add ( thisTrialRegret ) ; wins += r ; s . train ( choice , r ) ; } } printRegret ( cumulativeOutput , cumulativeRegret , steps ) ; printRegret ( perTurnOutput , localRegret , localSteps ) ; return cumulativeRegret . get ( cumulativeRegret . size ( ) - <NUM_LIT:1> ) . getMedian ( ) ; } private static void printRegret ( String outputFile , List < OnlineSummarizer > cumulativeRegret , List < Integer > steps ) throws FileNotFoundException { PrintWriter out = new PrintWriter ( outputFile ) ; try { out . printf ( "<STR_LIT>" ) ; int k = <NUM_LIT:0> ; for ( OnlineSummarizer summary : cumulativeRegret ) { out . printf ( "<STR_LIT>" , steps . get ( k ++ ) , summary . getMean ( ) ) ; } out . flush ( ) ; } finally { out . close ( ) ; } } private static int bump ( int delta ) { int multiplier = <NUM_LIT:1> ; while ( delta >= <NUM_LIT:10> ) { multiplier *= <NUM_LIT:10> ; delta /= <NUM_LIT:10> ; } delta = ( int ) ( <NUM_LIT:4> * delta - delta * delta / <NUM_LIT:3> - <NUM_LIT> ) ; return delta * multiplier ; } } </s>
|
<s> package com . mapr . stats ; import org . apache . mahout . math . jet . random . AbstractContinousDistribution ; public class DistributionWithMean extends AbstractContinousDistribution implements Comparable < DistributionWithMean > { private AbstractContinousDistribution delegate ; private double mean ; public DistributionWithMean ( AbstractContinousDistribution delegate , double mean ) { this . delegate = delegate ; this . mean = mean ; } public double getMean ( ) { return mean ; } @ Override public double nextDouble ( ) { return delegate . nextDouble ( ) ; } @ Override public int compareTo ( DistributionWithMean other ) { return Double . compare ( getMean ( ) , other . getMean ( ) ) ; } } </s>
|
<s> package com . mapr . stats ; import org . apache . mahout . math . jet . random . AbstractContinousDistribution ; import java . util . Random ; public class BetaBinomialDistribution extends AbstractBayesianDistribution { private final Random gen ; private final BetaDistribution bd ; public BetaBinomialDistribution ( double alpha , double beta , Random gen ) { this . gen = gen ; bd = new BetaDistribution ( alpha , beta , gen ) ; } @ Override public double nextDouble ( ) { return gen . nextDouble ( ) < bd . getAlpha ( ) / ( bd . getAlpha ( ) + bd . getBeta ( ) ) ? <NUM_LIT:1> : <NUM_LIT:0> ; } @ Override public void add ( double x ) { if ( x == <NUM_LIT:0.0> ) { bd . setBeta ( bd . getBeta ( ) + <NUM_LIT:1> ) ; } else if ( x == <NUM_LIT:1> ) { bd . setAlpha ( bd . getAlpha ( ) + <NUM_LIT:1> ) ; } else { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } @ Override public double nextMean ( ) { return bd . nextDouble ( ) ; } @ Override public AbstractContinousDistribution posteriorDistribution ( ) { return createBernoulliDistribution ( bd . getAlpha ( ) / ( bd . getAlpha ( ) + bd . getBeta ( ) ) ) ; } private AbstractContinousDistribution createBernoulliDistribution ( final double p ) { return new AbstractContinousDistribution ( ) { @ Override public double nextDouble ( ) { return gen . nextDouble ( ) < p ? <NUM_LIT:1> : <NUM_LIT:0> ; } } ; } } </s>
|
<s> package com . mapr . stats ; import org . apache . mahout . math . DenseMatrix ; import org . apache . mahout . math . Matrix ; import org . apache . mahout . math . Vector ; import org . apache . mahout . math . function . DoubleFunction ; import org . apache . mahout . math . function . Functions ; import org . apache . mahout . math . function . VectorFunction ; public class ContextualBayesBandit { private final Matrix featureMap ; private final Matrix state ; private final int m ; private final BetaDistribution rand ; public ContextualBayesBandit ( Matrix featureMap ) { this ( featureMap , <NUM_LIT:1> , <NUM_LIT:1> ) ; } public ContextualBayesBandit ( Matrix featureMap , double alpha_0 , double beta_0 ) { this . featureMap = featureMap ; m = featureMap . numCols ( ) ; this . state = new DenseMatrix ( m , <NUM_LIT:2> ) ; this . state . viewColumn ( <NUM_LIT:0> ) . assign ( alpha_0 ) ; this . state . viewColumn ( <NUM_LIT:1> ) . assign ( beta_0 ) ; this . rand = new BetaDistribution ( <NUM_LIT:1> , <NUM_LIT:1> ) ; } public Vector samplePi ( ) { return sampleNoLink ( ) . assign ( new LogisticFunction ( ) ) ; } public int sample ( ) { final Vector pi = sampleNoLink ( ) ; return pi . maxValueIndex ( ) ; } private Vector sampleNoLink ( ) { final Vector theta = state . aggregateRows ( new VectorFunction ( ) { final DoubleFunction inverseLink = new InverseLogisticFunction ( ) ; @ Override public double apply ( Vector f ) { return inverseLink . apply ( rand . nextDouble ( f . get ( <NUM_LIT:0> ) , f . get ( <NUM_LIT:1> ) ) ) ; } } ) ; return featureMap . times ( theta ) ; } public void train ( int bandit , boolean success ) { state . viewColumn ( success ? <NUM_LIT:0> : <NUM_LIT:1> ) . assign ( featureMap . viewRow ( bandit ) , Functions . plusMult ( <NUM_LIT:1.0> / m ) ) ; } public class LogisticFunction implements DoubleFunction { @ Override public double apply ( double x ) { return <NUM_LIT:1> / ( <NUM_LIT:1> + Math . exp ( - x ) ) ; } } public class InverseLogisticFunction implements DoubleFunction { @ Override public double apply ( double p ) { return Math . log ( p / ( <NUM_LIT:1> - p ) ) ; } } } </s>
|
<s> package com . mapr . stats ; import java . util . Random ; abstract class BanditFactory { public abstract BayesianBandit createBandit ( int bandits , Random gen ) ; } </s>
|
<s> package com . mapr . stats ; import com . google . common . collect . Lists ; import java . util . List ; public abstract class BayesianBandit { private final List < AbstractBayesianDistribution > bd = Lists . newArrayList ( ) ; public int sample ( ) { double max = Double . NEGATIVE_INFINITY ; int r = - <NUM_LIT:1> ; int i = <NUM_LIT:0> ; for ( AbstractBayesianDistribution dist : bd ) { double p = dist . nextMean ( ) ; if ( p > max ) { r = i ; max = p ; } i ++ ; } return r ; } public void train ( int bandit , double reward ) { bd . get ( bandit ) . add ( reward ) ; } public boolean addModelDistribution ( AbstractBayesianDistribution distribution ) { return bd . add ( distribution ) ; } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.