Reward.emadl 660 Bytes
Newer Older
Nicola Gatto's avatar
Nicola Gatto committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
/* (c) https://github.com/MontiCore/monticore */
package torcs.agent.network;

component Reward {
    ports
        in Q^{29} state,
        in B isTerminal,
        out Q reward;

    implementation Math {
        Q speedX = state(22) * 300;
        Q angle = state(1) * 3.1416;
        Q trackPos = state(21);

        if speedX < 0
            speedX = 0;
        end
    
        reward = (speedX * cos(angle)) - (speedX * sin(angle)) - (speedX * abs(trackPos));

        if abs(trackPos) > 1.0
            reward = -200;
        end

        for i=2:20
            if abs(state(i)) > 1.0
                reward = -200;
            end
        end
    }
}