' Neurobot v1
'
' My first go at making a bot controlled by 
' something resembling a neural network

' ------------------------------- VARIABLE DECLARATIONS -------------------------------

' 902 - 970 are all freevars

' Weightings

def n1i1 902
def n1i2 903
def n1i3 904

def n2i1 905
def n2i2 906
def n2i3 907

def n3i1 908
def n3i2 909
def n3i3 910

def n4i1 911
def n4i2 912
def n4i3 913

def n5i1 914
def n5i2 915
def n5i3 916

' (output neurons:)

def n6i1 917
def n6i2 918
def n6i3 919

def n7i1 920
def n7i2 921
def n7i3 922

def n8i1 923
def n8i2 924
def n8i3 925

' Connectivity (value range 959 - 963)
' Gives a location for the neuron to look at to see what it's input is

def n1c1 926
def n1c2 927
def n1c3 928

def n2c1 929
def n2c2 930
def n2c3 931

def n3c1 932
def n3c2 933
def n3c3 934

def n4c1 935
def n4c2 936
def n4c3 937

def n5c1 938
def n5c2 939
def n5c3 940

' (output neurons:)

def n6c1 941
def n6c2 942
def n6c3 943

def n7c1 944
def n7c2 945
def n7c3 946

def n8c1 947
def n8c2 948
def n8c3 949

' Biases

def n1b 950
def n2b 951
def n3b 952
def n4b 953
def n5b 954
def n6b 955
def n7b 956
def n8b 957

def n8thresh 958

' n8thresh is the activation threshold for the shoot node

' Outputs

def nout1 959
def nout2 960
def nout3 961
def nout4 962
def nout5 963

' nout6-8 are unused. Their outputs are translated directly to actions

' And the input neurons ... (essentially *.eye5 and *.refeye)

def nin1 964
def nin2 965

' And finally the boolean threshold for the shoot output

' 64 memory locations used in total for the neural net alone: Pretty memory-intensive!

' ------------------------------- INPUT NEURONS -------------------------------

' Input Neuron (eye5)

cond
start
*.eye5 .nin1 store
stop

' Input Neuron (refeye)

cond
start
*.refeye .nin2 store
stop

' ------------------------------- INVISIBLE LAYER NEURONS (5) -------------------------------

' 3 inputs per neuron; public outputs that can be accessed by any neuron in the network
' Neurons can even set their own outputs as an input

' neuron output = sum of (input * connection weighting) * bias

cond
start
*.n1c1 * *.n1i1 mult  *.n1c2 * *.n1i2 mult add *.n1c3 * *.n1i3 mult add *.n1b mult .nout1 store
stop

cond
start
*.n2c1 * *.n2i1 mult  *.n2c2 * *.n2i2 mult add *.n2c3 * *.n2i3 mult add *.n2b mult .nout2 store
stop

cond
start
*.n3c1 * *.n3i1 mult  *.n3c2 * *.n3i2 mult add *.n3c3 * *.n3i3 mult add *.n3b mult .nout3 store
stop

cond
start
*.n4c1 * *.n4i1 mult  *.n4c2 * *.n4i2 mult add *.n4c3 * *.n4i3 mult add *.n4b mult .nout4 store
stop

cond
start
*.n5c1 * *.n5i1 mult  *.n5c2 * *.n5i2 mult add *.n5c3 * *.n5i3 mult add *.n5b mult .nout5 store
stop

' ------------------------------- OUTPUT NEURONS -------------------------------

' Output Neuron (up)

cond
start
*.n6c1 * *.n6i1 mult  *.n6c2 * *.n6i2 mult add *.n6c3 * *.n6i3 mult add *.n6b mult .up store
stop

' Output Neuron (aimdx)

cond
start
*.n7c1 * *.n7i1 mult  *.n7c2 * *.n7i2 mult add *.n7c3 * *.n7i3 mult add *.n7b mult .aimdx store
stop

' Boolean Output Neuron (shoot)

cond
*.n8c1 * *.n8i1 mult  *.n8c2 * *.n8i2 mult add *.n8c3 * *.n8i3 mult add *.n8b mult *.n8thresh >
start
-1 .shoot store
stop

' ------------------------------- NEURAL NETWORK CONFIGURATION -------------------------------

' 902 - 925 need to be set to a random value (weightings)

' 926 - 949 need to be set to a value between 959 - 963 (connectivity)

' 950 - 958 need to be set to a random value (biases)