NNComplexEvaluationFunction extends NNEvaluationFunction<T> { @Override protected double[] gameStateToArray(GameState gs, int playerToEvaluate) { pgs = gs.getPhysicalGameState(); substrateSize = pgs.getHeight()*pgs.getWidth(); int numInputs = substrateSize*numSubstrates; if(areSubsActive[MY_RESOURCE_PROPORTION]) { numInputs = numInputs - substrateSize + 1; } double[] inputs = new double[numInputs]; for(int i = 0; i < numSubstrates; i++){ double[][] twoDimensionalSubArray = inputSubstrates.get(i).getInputs(gs,playerToEvaluate); assert twoDimensionalSubArray.length > 0 : "length < 0"; int thisSubstrateSize = twoDimensionalSubArray.length * twoDimensionalSubArray[0].length; int thisWidth = twoDimensionalSubArray.length; for(int j = 0; j < thisSubstrateSize; j++){ inputs[(i*substrateSize)+j] = twoDimensionalSubArray[j%thisWidth][j/thisWidth]; } } return inputs; } NNComplexEvaluationFunction(); @Override String[] sensorLabels(); @Override int getNumInputSubstrates();  }
@Test public void testGameStateToArray() { double[] bluePerspective = cef.gameStateToArray(gs, 0); double[] redPerspective = cef.gameStateToArray(gs, 1); double[] expectedBlueValues = new double[]{ 1,0,1,-1, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 1,0,0,0, 0,0,-1,0, 0,0,0,0, 1,0,1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,-1, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,-1,0, 0,0,0,0, 1,0,1,0, 1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,-1, 0,0,0,0, 0,0,-1,0, 0,0,0,0, 1,0,1,-1, 1,0,0,0, 0,0,-1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, -1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,1, fadedValues[3],fadedValues[2],fadedValues[1],fadedValues[2], fadedValues[2],fadedValues[1],fadedValues[0],fadedValues[1], fadedValues[1],fadedValues[0], 1 , 0, fadedValues[2],fadedValues[1],fadedValues[0], 0, resourceWorkerSqrt,0,halfHpHeavy,-workerSqrt, 0,0,0,0, 0,0,0,0, 0,0,0,0, fadedValues[3],0,fadedValues[1],0, 0,0,0,0, 0,0,0,0, 0,0,0,0, -resourceScore, }; double[] expectedRedValues = new double[]{ -1,0,-1,1, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, -1,0,0,0, 0,0,1,0, 0,0,0,0, 0,0,0,1, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,1,0, 0,0,0,0, -1,0,-1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, -1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,0, 0,0,1,0, 0,0,0,0, -1,0,-1,0, -1,0,0,0, 0,0,0,0, 0,0,0,0, -1,0,-1,1, -1,0,0,0, 0,0,1,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, -1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 0,0,0,1, fadedValues[0], fadedValues[1], fadedValues[2], fadedValues[3], 1, fadedValues[0], fadedValues[1], fadedValues[2], fadedValues[0], fadedValues[1], fadedValues[2], 0, fadedValues[1], fadedValues[2], fadedValues[3], 0, -resourceWorkerSqrt,0,-halfHpHeavy,workerSqrt, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,fadedValues[3], 0,0,0,0, 0,0,0,0, 0,0,0,0, resourceScore, }; assertArrayEquals(bluePerspective, expectedBlueValues, EPSILON); assertArrayEquals(redPerspective, expectedRedValues, EPSILON); }