diff --git a/src/autotest.py b/src/autotest.py index fea451c..c3e64a0 100755 --- a/src/autotest.py +++ b/src/autotest.py @@ -122,8 +122,9 @@ for i in range(0,10): fn.close() print(lines) total_round+=1 - if lines[0]=='YOU WIN!\n': - win_round+=1 + if len(lines)>0: + if lines[0]=='YOU WIN!\n': + win_round+=1 print("win rate: "+str(win_round/total_round),win_round,total_round) input("Press Enter to continue...") @@ -168,6 +169,7 @@ while True: # check the output print(lines) total_round+=1 - if lines[0]=='YOU WIN!\n': - win_round+=1 + if len(lines)>0: + if lines[0]=='YOU WIN!\n': + win_round+=1 print("win rate: "+str(win_round/total_round),win_round,total_round) \ No newline at end of file diff --git a/src/include/client.h b/src/include/client.h index 5e251c1..f15d722 100644 --- a/src/include/client.h +++ b/src/include/client.h @@ -57,6 +57,7 @@ void InitGame() { namespace Client { const unsigned int RndSeed = std::random_device{}(); std::mt19937 RawRnd(RndSeed); // a basic random generator +const double RawRnd_max = 4294967295.0; const int max_size = 35; char game_map[max_size][max_size]; // store the raw game map in format of char std::queue > @@ -489,6 +490,9 @@ std::pair SimpleGuess() { } } std::pair best_guess = TotalRandomGuess(); + bool allow_a_guess = true; + const double guess_begin_consideration_ratio = 0.95; + const double guess_tightness_parameter = 10; for (int i = 0; i < rows; i++) for (int j = 0; j < columns; j++) if (map_status[i][j] == 0) { @@ -499,6 +503,15 @@ std::pair SimpleGuess() { if (this_prob < current_prob) { best_guess.first = i; best_guess.second = j; + } else if ((double)(total_known) / (rows * columns) > + guess_begin_consideration_ratio && + allow_a_guess) { + if (exp(-(this_prob - current_prob) * guess_tightness_parameter) < + RawRnd() / RawRnd_max) { + best_guess.first = i; + best_guess.second = j; + allow_a_guess = false; + } } } return best_guess;