public void Calculate(double[] input, bool output) { Values = new double[Length]; for (int k = 0; k < Length; k++) { for (int j = 0; j < InputLength; j++) { Values[k] += ((Weights[k, j]) * input[j]); } if (!output) { Values[k] += Biases[k]; Values[k] = ActivationFunctions.Tanh(Values[k]); } else { Values[k] = Values[k]; } } }
public double Score(Board board, bool useNeurons) { var input = new double[8, 8]; //Flip a copy of the board to always have self at bottom for scoring purposes Piece[,] temp = Serializer.DeepClone(board.Pieces); /*if (player.IsW) { temp = Serializer.DeepClone(board.Pieces); } * else { temp = ArrayInverse(board.Pieces); }*/ for (int i = 0; i < 8; i++) { for (int ii = 0; ii < 8; ii++) { //Set piece values equal to standard chess piece values Piece p = temp[i, ii]; //Don't have to set empty piece = 0 b/c array initialization does it automatically if (p is Empty) { continue; } if (p is Pawn) { input[i, ii] = 1; } if (p is Knight || p is Bishop) { input[i, ii] = 3; } if (p is Rook) { input[i, ii] = 5; } if (p is Queen) { input[i, ii] = 9; } if (p is King) { input[i, ii] = 15; } //Set opposite color piece values to negative if (p.Player.IsW != player.IsW) { input[i, ii] *= -1; } } } if (useNeurons) { //Normalize everything input = ActivationFunctions.Normalize(input, 8, 8); return(Run(input)); } //Count the value of pieces left on the board else { int sum = 0; foreach (int i in input) { sum += i; } return(sum); } }