void updateQValue() { // newQ = oldQ + learningRate * (target - oldQ) // target = reward + discountFactor * maxQ(nextState) if (nextState >= 0 && nextState < numStates && currState >= 0 && currState < numStates) { float target = reward + gamma * Q[nextState][nextMaxQ]; float error = target - Q[currState][action]; Q[currState][action] = Q[currState][action] + alpha * error; } } int findMaxQIndex(int row) { int index = 0; // υποθετικά η μέγιστη τιμή είναι στη θέση 0 if (row >= 0 && row < numStates) // ελέγχουμε αν το row είναι εντός του πίνακα, καλού κακού { if (Q[row][index] < Q[row][1]) // αν η θέση 1 έχει μεγαλύτερη τιμή, παίρνουμε αυτή ως index index = 1; if (Q[row][index] < Q[row][2]) // αν η θέση 2 έχει μεγαλύτερη τιμή, παίρνουμε αυτή ως index index = 2; } return index; }