aboutsummaryrefslogtreecommitdiff
path: root/photon.cc
diff options
context:
space:
mode:
Diffstat (limited to 'photon.cc')
-rwxr-xr-xphoton.cc86
1 files changed, 86 insertions, 0 deletions
diff --git a/photon.cc b/photon.cc
new file mode 100755
index 0000000..977a50b
--- /dev/null
+++ b/photon.cc
@@ -0,0 +1,86 @@
+#include <iostream>
+#include <vector>
+#include <climits>
+#include <cstdlib>
+#include <ctime>
+#include "higgs.h"
+
+using namespace std;
+
+const int MONTE_CARLO_COUNT = 256;
+
+Move random( Board& board ) {
+ vector<Move> 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> 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 );
+ }
+} \ No newline at end of file