#include #include #include #include #include #include "higgs.h" using namespace std; const int MONTE_CARLO_COUNT = 256; Move random( Board& board ) { vector move_list = board.generateMoves(); if( move_list.size() == 0 ) return {-1,-1,-1}; return move_list[ rand() % move_list.size() ]; } Move monteCarlo( Board& board ) { vector move_list; int win_max = INT_MIN; int win_count; int neutron = board.neutron; Move best_move; Move random_move; for( Move move: move_list ) { win_count = 0; board.doMove( move ); for( int i = 0; i < MONTE_CARLO_COUNT; i++ ) { Board playground( board ); while( !playground.neutronWin() ) { random_move = random( playground ); if( random_move.ndir == -1 ) break; playground.doMove( random_move ); } if( playground.neutronWin() != 0 ) win_count += (1-2*(board.move_count%2))*playground.neutronWin() > 0; else if( random_move.ndir == -1 ) win_count += ( playground.move_count%2 == 0 ); } board.undoMove( move, neutron ); cerr << move.ndir << " " << win_count << endl;; if( win_count > win_max ) { win_max = win_count; best_move = move; } } return best_move; } Move importMove() { Move move; cin >> move.ndir >> move.p >> move.dir; return move; } void exportMove( Move move ) { cout << move.ndir << " " << move.p << " " << move.dir << endl; } int main() { Board board; Move move; string input; srand( time( NULL ) ); cin >> input; if( input == "go" ) { board.print(); move.ndir = -1; move.p = S-2; move.dir = 4; board.doMove( move ); exportMove( move ); } while( 1 ) { board.print(); board.doMove( importMove() ); board.print(); move = monteCarlo( board ); board.doMove( move ); exportMove( move ); } }