chncyhn / flappybird-qlearning-bot

Flappy Bird Bot using Reinforcement Learning
MIT License
416 stars 94 forks source link

learn.py does not print out number of iterations and score #11

Closed DenseLance closed 4 years ago

DenseLance commented 4 years ago

When I ran learn.py, I realised the only thing that was printed is "Q-values updated on local file." The code for learn.py, line 179-182, which does not work:

def showGameOverScreen(crashInfo):
    if VERBOSE:
        score = crashInfo['score']
        print(str(bot.gameCNT - 1) + " | " + str(score))

I would need to obtain the number of iterations and score quickly through learn.py, so please do help me to solve this problem as soon as possible. Thank you.

Also, line 35 of learn.py has a small mistake; it should be --iter instead of iter to pass the argument for iteration:

parser.add_argument('--iter', type=int, default=5000, help='number of iterations to run')

chncyhn commented 4 years ago

Hello @DenseLance, you can see there that you need to pass --verbose command line flag to be able to see the iterations. Can you try with this?

I'm able to see the results per iteration: image

Thanks for pointing out the --iter issue. I'll push a fix soon, wanted to move some things around as well.

chncyhn commented 4 years ago

Pushed the fix.

DenseLance commented 4 years ago

I just started Python only recently, so I'm not sure what that means, so do forgive my ignorance. It shows the following when I try to run learn.py with a default of 4 iterations. q-learning

My Q-values in the qvalues JSON file were updated after the code was ran.

Thank you if you could help me solve this issue.

Edit: I figured out the mistake. For line 36, it should be verbose instead of --verbose Result (these are after I reset the q-values): qvalue -1

Hence, For what I mentioned earlier, the code for lines 179-182 could be:

def showGameOverScreen(crashInfo):
    if VERBOSE:
        score = crashInfo['score']
        print(str(bot.gameCNT) + " | " + str(score))

This allows the iterations to start at 1 instead of 0 (it's neater this way to me, I guess. If you don't like it, it's also fine by me)

Thanks for helping!