GNOME Bugzilla – Bug 732136
Easy AI is better than medium AI when running tests
Last modified: 2014-07-18 21:46:24 UTC
TEST: ai-test... (pid=7005) /AI/Draw: OK /AI/Random: OK /AI/Take Win/Horizontal Win: OK /AI/Take Win/Vertical Win: OK /AI/Take Win/Forward Diagonal Win: OK /AI/Take Win/Backward Diagonal Win: OK /AI/Avoid Loss/Horizontal Loss: OK /AI/Avoid Loss/Vertical Loss: OK /AI/Avoid Loss/Forward Diagonal Loss: OK /AI/Avoid Loss/Backward Diagonal Loss: OK /AI/AI vs AI/Easy vs Medium: ** ERROR:../../src/test-ai.c:496:test_easy_vs_medium: assertion failed: (easy_wins <= NUMBER_GAMES/2) FAIL GTester: last random seed: R02S1e6398470bf113549bd7d6d2287d5fff (pid=7012) /AI/AI vs AI/Easy vs Hard: OK /AI/AI vs AI/Medium vs Hard: OK FAIL: ai-test I expected I would be able to reproduce this by running 'gtester --seed=R02S1e6398470bf113549bd7d6d2287d5fff test-ai' but running with the same random seed for some reason does not end in the same result. I'm not sure why.
Nikhar, can you take a look at this?
Created attachment 281139 [details] [review] Bug fix
Review of attachment 281139 [details] [review]: Looks pretty good, just a few changes please. After you fix these, please add a SEPARATE patch to fix the indentation throughout the file: should be four spaces per indent, with no tab characters. ::: src/test-ai.vala @@ +22,3 @@ const int NUMBER_GAMES = 5; +const int MAXIMUM_GAMES = 100; +int games_contested; Er, no, I don't think we need a global variable for this. @@ +183,3 @@ +/* Repeatedly contest between the two AI until either easier win ratio is less than a threshold + or maximum numbers of contests have been played.*/ +private int repeat_contests (string easier, string harder) You'll want to make this function return void, and take two additional out parameters: one for the number of times the easier AI won, and one for the games played. Then you won't need the global variable. (Notice also that it's not clear from your comment or the name of this function what the return value is -- when that's unavoidable, you should add a comment.) @@ +191,3 @@ + { + if (easy_wins <= games_contested/4) + break; This should be merged into the loop guard: while (games_contested <= MAXIMUM_GAMES && easy_wins > games_contested/4) @@ +204,1 @@ + assert (easy_wins <= games_contested/4); Let's use a constant instead of leaving magic 4s everywhere
Created attachment 281142 [details] [review] Bug fix
Created attachment 281143 [details] [review] Converted tabs to spaces
Great