Last active
December 10, 2018 05:09
-
-
Save marty1885/db650f150e913e22fbfdd54cfc12a467 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
//Initialize both AI | |
RNNPlayer player1; | |
HTMPlayer player2; | |
int rnn_last_move = 0; | |
int htm_last_move = 0; | |
size_t rnn_win = 0; | |
size_t draw = 0; | |
size_t htm_win = 0; | |
int num_games = 1000*100; | |
for(int i=0;i<num_games;i++) { | |
//Run RNN | |
auto rnn_out = player1.compute(htm_last_move); | |
int rnn_pred = xt::argmax(rnn_out)[0]; | |
//Run HTM | |
auto htm_out = player2.compute(rnn_last_move); | |
int htm_pred = xt::argmax(htm_out)[0]; //convert prediction to move (Ex: predicted scissors, than the move is rock) | |
int rnn_move = predToMove(rnn_pred); | |
int htm_move = predToMove(htm_pred); | |
int winner_algo = winner(rnn_move, htm_move); //computes the winner | |
std::cout << "Round " << i << std::endl; | |
std::cout << "RNN pred: " << rnn_out << ", HTM pred: " << ::softmax(htm_out) << std::endl; | |
std::cout << "RNN: " << move2String(rnn_move) << ", " << "HTM: " << move2String(htm_move) | |
<< ", Winner: "<< (winner_algo==1?"RNN":(winner_algo==0?"draw":"HTM")) << std::endl; | |
std::cout << std::endl; | |
rnn_last_move = rnn_move; | |
htm_last_move = htm_move; | |
if(winner_algo == 1) | |
rnn_win += 1; | |
else if(winner_algo == 0) | |
draw += 1; | |
else | |
htm_win += 1; | |
} | |
std::cout << "After all the battles" << std::endl; | |
std::cout << "RNN Wins " << rnn_win << " times, " << (float)rnn_win/num_games << "%\n"; | |
std::cout << "HTM Wins " << htm_win << " times, " << (float)htm_win/num_games << "%\n"; | |
std::cout << "draw: " << draw << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment