Adding a new input algorithm involves some tweaking of the code, because it changes the structure of the neural networks by requiring extra input nodes. The framework will expect exactly four values from the algorithm: one for each direction. It is possible to diverge from this method, but it will require a lot of code altering. The following steps illustrate how to add a new input algorithm called "FeelingLuckyInput".
The files below already contain code which implements the current input algorithms. It is wise to add your code so that the order in which the various input algorithms are called is the same in all files. In other words: add the new input algorithm below the code of the pre-existing algorithms.
public static boolean[] enableFeelingLuckyInput = {true, false, true};
The above code will enable the new input algorithm for the DODGE and HUNT networks, yet disable it for the ROBERT network.
In the same file, raise the value of numAlgorithms by one.
In PacMan.java, we need to change the network specifications. Go to the line that says "// neural network specifications" and add the following code inside the for-loop:
if (Globals.enableFeelingLuckyInput[i] == true) {
inputs[i]++;
}
Which loosely translates to: if this new input algorithm is enabled, you will need one extra input node for the corresponding neural network.
globalVars += Globals.enableFeelingLuckyInput[i] + ",";
This will make sure that the algorithm will still be enabled/disabled after loading a neural network file.
~~~~~~~~~~~~~~~
if (Globals.enableFeelingLuckyInput[netID] == true) {
FeelingLucky fl = new FeelingLucky();
fl.getFeeling(Game);
stateRep[i + 0] = fl.result[0];
stateRep[i + 1] = fl.result[1];
stateRep[i + 2] = fl.result[2];
stateRep[i + 3] = fl.result[3];
if (Globals.showVisualisation == true && Globals.showCharter == true) {
chart.alterData("FeelingLuckyInput", "Left", stateRep[i + 0]);
chart.alterData("FeelingLuckyInput", "Right", stateRep[i + 1]);
chart.alterData("FeelingLuckyInput", "Up", stateRep[i + 2]);
chart.alterData("FeelingLuckyInput", "Down", stateRep[i + 3]);
}
i += 4;
}
~~~~~~~~~~~~
This will present the neural networks with the proper resulting variable from your new input algorithm and plot it if needed.