void completeGame(GoState& s, StaticVector<GoMove, MAX_GAME_LENGTH>& move_seq, RNG &rng) { bool game_over = false; unsigned int moves = 0; while (!game_over) { moves++; GoMove move = selectMove(s, rng); assert(s.isValidMove(move)); if (move.isPass() && s.getPreviousMoveWasPass()) { game_over = true; } s.makeMove(move); move_seq.push_back(move); } }
int main(int argc, char** argv) { char fromXChar, toXChar, fromYChar, toYChar; int useIPC; ipc_memory *ipc; myDNA = malloc(sizeof(dna)); if (myDNA == null) { printf("Unable to allocate memory for my DNA!\n"); exit(1); } myDNA->noBasePair = 0.984120; // After 47 evolutions myDNA->oneBasePair = 0.576126; myDNA->twoBasePair = 0.315090; myDNA->threeBasePair = -0.972065; myDNA->lineLengthBasePair = 0.020435; myDNA->currentMarginBasePair = 0.660055; // Initial stuff gameBoard = null; possibleMovesFound = 0; useIPC = 0; if (DEBUG) { printf("\n"); } // Make sure we have arguments if ((argc < 2) || (argc > 4)) { printf("Error: bad command line arguments. Please call as:\n"); printf("\t/path/to/program /path/to/input [/path/to/output] [/path/to/dna]\n"); printf("\t/path/to/program --ipc key_number\n"); exit(1); } if (strncmp(argv[1], "--ipc", 5) == 0) { if (argc == 3) { // Key is in the command line, so let's get it if(sscanf(argv[2], "%d", &useIPC) != 1) { // We couldn't load it printf("Unable to load the IPC key. Given '%s'.\n", argv[3]); exit(1); } } else { // We didn't get enough info printf("Error: bad command line arguments for IPC. Please call as:\n"); printf("\t/path/to/program /path/to/input [/path/to/output] [/path/to/dna]\n"); printf("\t/path/to/program --ipc key_number\n"); exit(1); } } // Read the input file if (useIPC) { // Set up the IPC shared memory ipc = null; ipc = (ipc_memory *) shmat(useIPC, 0, 0); if (ipc == (ipc_memory *) -1) { printf("Unable to get shared memory: error %d\n", errno); exit(1); } // Now set the stuff that readInputFile would do for us me = ipc->player; boardHeight = ipc->height; boardWidth = ipc->width; gameBoard = (int *) &(ipc->gameBoard); playerOneScore = ipc->pOneScore; playerOneTimeLeft = ipc->pOneTime; playerTwoScore = ipc->pTwoScore; playerTwoTimeLeft = ipc->pTwoTime; if (me == 1) { him = 2; ourScore = &playerOneScore; ourTime = &playerOneTimeLeft; hisScore = &playerTwoScore; hisTime = &playerTwoTimeLeft; } else { him = 1; hisScore = &playerOneScore; hisTime = &playerOneTimeLeft; ourScore = &playerTwoScore; ourTime = &playerTwoTimeLeft; } } else { readInputFile(argv[1]); } // Read our DNA if they gave it to us if (useIPC) { // We get the DNA through the IPC myDNA = &(ipc->theDNA); } else { // Load the DNA from a file if given if (argc == 4) { loadDNA(argv[3]); } } // Initialize other stuff memset(possibleMoves, 0, MAX_POSSIBLE_MOVES * sizeof(move *)); // Clear out the possible moves array // Generate a list of possible moves generateMoveList(); if (DEBUG) { printf("We found %d possible moves.\n\n", possibleMovesFound); } // Seed the RNG srand((unsigned) time(NULL)); // Time to start processing. selectMove(); // Figure out our move // Print out the move if (useIPC) { // Since we are using IPC, things are easy copyMove(&finalMove, &(ipc->chosenMove)); } else { fromXChar = columnToChar(finalMove.from_x); toXChar = columnToChar(finalMove.to_x); fromYChar = '1' + finalMove.from_y; toYChar = '1' + finalMove.to_y; if (argc == 2) { // Just print out the result printf("%c%c %c%c\n", fromXChar, fromYChar, toXChar, toYChar); } else { // They want our output put into a file, so we'll have to do that. FILE *out = null; out = fopen(argv[2], "w"); if (out == null) { // We couldn't open the file, so complain printf("Unable to open output file! Error %d.\n", errno); printf("%c%c %c%c\n", fromXChar, fromYChar, toXChar, toYChar); } else { // We opened the file, write out stuff and quit. fprintf(out, "%c%c %c%c\n", fromXChar, fromYChar, toXChar, toYChar); fclose(out); } } } if (DEBUG) { printBoard(gameBoard); printf("%c%c %c%c\n", fromXChar, fromYChar, toXChar, toYChar); } // Clean up the possible move list if (possibleMovesFound > 0) { int i; for (i = 0; i < possibleMovesFound; i++) { free(possibleMoves[i]); } } // Detatch from the shared memory if we are using it if (useIPC) { shmdt(ipc); } // Now return return 0; }