board_t *board_hash_table_insert(board_hash_table_t *table, board_t *board) { board_t *board_new; board_list_t *list = NULL, *list_new; uint32_t index; uint64_t hash, hash2; if(table == NULL || board == NULL) return NULL; if(table->used >= ((table->size * 3) / 4)) { board_hash_table_expand(table, table->size * 2); } hash = board_hash(board, &hash2); index = hash & (table->size - 1); list = table->data[index]; if(list != NULL) { for(;;) { if(list->hash == hash && list->hash2 == hash2 && board_compare(list->item, board)) { return list->item; } if(list->next == NULL) break; list = list->next; } } board_new = board_clone(board); if(board_new == NULL) return NULL; list_new = malloc(sizeof(*list_new)); if(list_new == NULL) { board_free(board_new); return NULL; } list_new->item = board_new; list_new->hash = hash; list_new->hash2 = hash2; list_new->next = NULL; if(list != NULL) list->next = list_new; else table->data[index] = list_new; table->used++; return NULL; }
int uct_play_random_game(Board * board, Color color) { Color winner; Board * clone = board_clone(board); playout_random_game(clone, color); winner = playout_find_winner(clone); board_free(clone); return winner == color; }
int board_tiltable(int board_size, int** board){ int i,x,y; int different=0; int **board_test_l=board_clone(board_size,board); board_test_l=board_flip(board_test_l,board_size); for(i=0;i<board_size;i++) tilt_line_left(board_size,board_test_l[i]); board_test_l=board_flip(board_test_l,board_size); int **board_test_u=board_clone(board_size,board); for(i=0;i<board_size;i++) tilt_line_left(board_size,board_test_u[i]); for(x=0;x<board_size;x++){ for(y=0;y<board_size;y++){ if(board[x][y]!=board_test_u[x][y]||board[x][y]!=board_test_l[x][y]) {different++;x=board_size;y=board_size;} } } if(!different) {return 0;} return 1; }
Pos uct_search(Board * board, Color color) { int i; UCTNode * root, * ptr; Board * clone; Pos best_move; root = uct_node_new(nil); create_children(root, board, color); LOOP(i, UCT_SIMULATIONS) { clone = board_clone(board); uct_simulate(root, clone, color); //board_print(clone, stdout); board_free(clone); }