[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/Eshaancoding/DQN/master/train.cpp [Back]  [Original]

#include "Agent.cpp"
#include "Pong.cpp"
#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;

void gotoxy(int x,int y)    
{
    printf("%c[%d;%df",0x1B,y,x);
}

// Parameters
int BATCHES = 32; // number of training data trained per frame 
double LR = 0.001; // 0.001 Learning rate for the neural networks
int MEM_CAP = 10000; // 1 000 000 replay mem capacity
int FRAME_REACH = 10000; // 5 000 frames till epsilon reaches 0.05
int TARGET_UPDATE = 5000; // 1000 frames for target net to update with net, and also saves neural network parameters every 5000 iter
vector layout ({8, 50, 3}); // Neural Network layout
int gameWidth = 7;
int gameHeight = 12; // if you want to alter width or height try to play around with the reward system
int episodes = 0;
// main
int main () {
    Pong game = Pong(gameWidth, gameHeight); // PASS
    Agent agent = Agent(layout, LR, MEM_CAP, FRAME_REACH, TARGET_UPDATE, BATCHES); 
    vector current_state = game.return_state(); 
    int max_score = 0;
    int reward_count = 0;
    float avg_reward = 0;
    ofstream ofs;
    ofs.open("reward.txt", std::ofstream::out | std::ofstream::trunc); // clear txt file
    ofs.close();
    system("clear");
    while (episodes < 20000) {
        int action = agent.action(current_state);
        int reward = game.act(action);
        vector next_state = game.return_state();
        if (reward != 0) {
            avg_reward += reward; 
            reward_count += 1;
        }
        if (game.is_done) {
            episodes += 1;
            // save reward to .txt
            if (avg_reward != 0) {
                avg_reward /= reward_count;
                ofstream myfile;
                myfile.open ("reward.txt", ios::app);
                myfile 

Web Proxy Viewer  |  New URL  |  Original Page