示例#1
0
文件: bench.c 项目: cutechess/sloppy
void
bench(void)
{
	Chess chess;
	SearchData sd;
	S64 timer;
	int npos = 0;
	int nfen = (int)(sizeof(bench_fen) / sizeof(char*));
	
	double avg_bfactor;
	double t_elapsed;
	double hhit_rate;
	U64 nnodes_all;	/* num. of all nodes (main + qs) */
	int nps;	/* nodes (all types) per second */
	int i;
	
	init_chess(&chess);
	init_search_data(&sd);
	chess.max_depth = 8;
	chess.increment = 60000;

	printf("Running benchmark at search depth %d...\n", chess.max_depth);
	timer = get_ms();
	progressbar(nfen, 0);
	for (i = 0; i < nfen; i++) {
		const char *fen = bench_fen[i];
		if (strlen(fen) <= 1)
			continue;
		if (!fen_to_board(&chess.board, fen)) {
			id_search(&chess, NULLMOVE);
			if (chess.sd.cmd_type != CMDT_CONTINUE) {
				printf("Benchmark cancelled by user\n");
				return;
			}

			sd.nnodes += chess.sd.nnodes;
			sd.nqs_nodes += chess.sd.nqs_nodes;
			sd.nhash_probes += chess.sd.nhash_probes;
			sd.nhash_hits += chess.sd.nhash_hits;
			sd.bfactor += chess.sd.bfactor;
			npos++;
			progressbar(nfen, npos);
		} else
			printf("\nInvalid FEN string: %s\n", fen);
	}

	timer = get_ms() - timer;
	t_elapsed = timer / 1000.0;
	avg_bfactor = sd.bfactor / npos;
	hhit_rate = (sd.nhash_hits * 100.0) / sd.nhash_probes;
	nnodes_all = sd.nnodes + sd.nqs_nodes;
	nps = (double)nnodes_all / ((double)timer / 1000.0);
	printf("\n\nBenchmark finished in %.2f seconds.\n", t_elapsed);
	printf("Main nodes searched: %" PRIu64 "\n", sd.nnodes);
	printf("Quiescence nodes searched: %" PRIu64 "\n", sd.nqs_nodes);
	printf("Total nodes per second: %d\n", nps);
	printf("Average branching factor: %.2f\n", avg_bfactor);
	printf("Hash table hit rate: %.2f%%\n", hhit_rate);
}
示例#2
0
/* mouse_work */
int mouse_work(fb_info fb_inf, int x_start, int y_start)
{
    int mfd = -1;
    u8_t buf[8];
    mouse_event_t mevent;

again:
    fb_draw_board(fb_inf, x_start, y_start);
    init_chess();

    m_x = fb_inf.w / 2;
    m_y = fb_inf.h / 2;
        
    mouse_open(NULL, &mfd);

    fb_save_cursor(fb_inf, m_x, m_y);
    p_x = m_x;   
    p_y = m_y;  
    fb_draw_cursor(fb_inf, m_x, m_y);
        
    for(;;)
     {
        if (read(mfd, buf, sizeof(buf)) != -1)
         {
            mouse_parse(buf, &mevent);

            m_x += mevent.x;
            m_y += mevent.y;
                           
            if((m_x >= 0) && (m_x < fb_inf.w - C_WIDTH) && (m_y >= 0) && (m_y < fb_inf.h - C_HEIGHT))
              {
                fb_restore_cursor(fb_inf, p_x, p_y);
                fb_save_cursor(fb_inf, m_x, m_y); 
                p_x = m_x;   
                p_y = m_y;
//                fb_draw_cursor(fb_inf, m_x, m_y);
              }
            else
             {
                m_x -= mevent.x;
                m_y -= mevent.y;
             }

            switch (mevent.button)
            {
                case 1:
                    if ((win_flag == 0) && (mouse_work_flag == 1))
                    {
                        chess_item = p_get_chess_item(fb_inf, x_start, y_start);
                        if ((chess_item.x != -1) && (chess_item.y != -1) && (chess[chess_item.x][chess_item.y] == 0))
                        {
                            fb_draw_chess(fb_inf, x_start + chess_item.y * GRID_SIZE, y_start + chess_item.x * GRID_SIZE, CHESS_SIZE, WHITE_CHESS_COLOR);
                            fb_save_cursor(fb_inf, m_x, m_y); 
                            p_x = m_x;   
                            p_y = m_y;
                            send_flag = 1;
                        }
                    }
                    break;

                case 2:
                    if (win_flag == 1)
                     {
                        win_flag = 0;
                        goto again;
                     }
                    break;
                     
                case 3:
                    break;

                default:
                    break;
            }

            fb_draw_cursor(fb_inf, m_x, m_y);
        }

        if (draw_chess_flag == 1)
        {
            draw_chess_flag = 0;
            fb_restore_cursor(fb_inf, p_x, p_y);
            fb_draw_chess(fb_inf, x_start + recv_chessitem.y * GRID_SIZE, y_start + recv_chessitem.x * GRID_SIZE, CHESS_SIZE, BLACK_CHESS_COLOR);
            if (is_p_win == 1)
            {
                is_p_win = 0;
                display_string_ch("你输了!", fb_inf.w / 3, fb_inf.h / 2, fb_inf, 0x0000FF00);
                win_flag = 1;
            }
            fb_save_cursor(fb_inf, m_x, m_y); 
            p_x = m_x;   
            p_y = m_y;
            fb_draw_cursor(fb_inf, m_x, m_y);
        }

        if (is_c_win == 1)
        {
            is_c_win = 0;
            display_string_ch("你赢了!", fb_inf.w / 3, fb_inf.h / 2, fb_inf, 0x0000FF00);
            fb_save_cursor(fb_inf, m_x, m_y); 
            p_x = m_x;   
            p_y = m_y;
            fb_draw_cursor(fb_inf, m_x, m_y);
            win_flag = 1;
        }
        usleep(30000);	
    }

    return 0;
}