static void player_dialog_ok(GtkWidget *button, PlayerDialog *pd)
{
        int i, index;

        gtk_widget_hide(pd->window);
        index = gtk_combo_box_get_active(GTK_COMBO_BOX(pd->combo));

        /* Search options */
        pd->player->depth =
                   gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pd->depth));
        pd->player->branch =
                  gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pd->branch));
        pd->player->cache =
                     gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pd->cache));
        pd->player->tss =
                       gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(pd->tss));
        for (i = 0; i < SEARCHES; i++)
                if (gtk_toggle_button_get_active(
                                            GTK_TOGGLE_BUTTON(pd->search[i]))) {
                        pd->player->search = i;
                        break;
                }

        /* Marker player */
        if (pd->player == players) {
                AIMoves *moves;

                if (index == PLAYER_HUMAN) {
                        draw_marks(NULL, FALSE);
                        return;
                }
                pd->player->ai = index;
                stop_ai();
                moves = run_ai(players);
                if (opt_print_u)
                        g_debug("AI %s utility %d (0x%x)", ai(index)->s_desc,
                                moves->utility, moves->utility);
                setup_move();
                draw_marks(moves, TRUE);
                return;
        }

        /* White or black player changed */
        if (pd->player->ai != index) {
                pd->player->ai = index;
                stop_ai();
                setup_move();
        }
}
int main(void)
{
    CPU_PRESCALE(0);
    
    setup();
    
    while (TRUE) {
		if (_override) {
			if (_latch)
				shift_sequence();
		} else {
			CLRBIT(PORTB, OVERRIDE);
			
			char pina = poll_buttons(PINA);
			if (ISSET(pina, BTN1)) {
				_override = TRUE;

				setup_move(&seq, DFP);
			} else if (ISSET(pina, BTN2)) {
				_override = TRUE;
				
				setup_move(&seq, BDK);
			} else if (ISSET(pina, BTN3)) {
				_override = TRUE;

				setup_move(&seq, FDFP);
			} else if (ISSET(pina, BTN4)) {
				_override = TRUE;
	
				setup_move(&seq, BDFP);
			}else if (ISSET(pina, DIR_CONTROL)) {
				if (dir == RIGHT_DIR)
					dir = LEFT_DIR;
				else
					dir = RIGHT_DIR;
			}

			_delay_ms(1);
		}			
    }	
}
/* Clear the board and history for a new game */
void new_game(unsigned int size)
{
        tree_view_clear(1);
        clear_history(0);
        set_board_size(size);
        board = NULL;
        go_to_move(0);
        board->moves_left = start_q;
        board->turn = PIECE_BLACK;
        draw_board();
        stop_ai();
        setup_move();
}