コード例 #1
0
ファイル: Billboard.c プロジェクト: everharder/RotatingMobile
/******************************************************************
* create_board
*
* creates a bill board in direction of XY plane between diagonal points
* (x1, y1, z1) and (x2, y2, z2)
*******************************************************************/
object_gl* create_board(float x1, float y1, float z1, float x2, float y2, float z2){
	object_gl* board = NULL;

	// Initialize a new board
	board = init_board();

	if (board == NULL) 
		return NULL;

	// Define vertexes
	board->vertx_buffer_data[ 0] = x1;
	board->vertx_buffer_data[ 1] = y1;
	board->vertx_buffer_data[ 2] = z1;

	board->vertx_buffer_data[ 3] = x2;
	board->vertx_buffer_data[ 4] = y2;
	board->vertx_buffer_data[ 5] = z2;

	board->vertx_buffer_data[ 6] = x1;
	board->vertx_buffer_data[ 7] = y2;
	board->vertx_buffer_data[ 8] = z1;

	board->vertx_buffer_data[ 9] = x2;
	board->vertx_buffer_data[10] = y1;
	board->vertx_buffer_data[11] = z1;

	// Define normals
	for (int i = 0; i < board->num_vertx; i++){
		board->normal_buffer_data[i*3 + 0] = 0.0;
		board->normal_buffer_data[i*3 + 1] = 0.0;
		board->normal_buffer_data[i*3 + 2] = 1.0;
	}

	// Define UV coordinates for each vertex
	board->color_buffer_data[0] = 0.0 + UV_OFFSET;
	board->color_buffer_data[1] = 0.66;

	board->color_buffer_data[2] = 0.25 + UV_OFFSET;
	board->color_buffer_data[3] = 0.99;

	board->color_buffer_data[4] = 0.0 + UV_OFFSET;
	board->color_buffer_data[5] = 0.99;

	board->color_buffer_data[6] = 0.25 + UV_OFFSET;
	board->color_buffer_data[7] = 0.66;

	// Define index
	board->index_buffer_data[0] = 0;
	board->index_buffer_data[1] = 2;
	board->index_buffer_data[2] = 3;

	board->index_buffer_data[3] = 1;
	board->index_buffer_data[4] = 2;
	board->index_buffer_data[5] = 3;

	// Load texture
	setup_texture(board, "data/dance.bmp");

	return board;
}
コード例 #2
0
ファイル: check_run_program.c プロジェクト: cledo/HaiGo
END_TEST

START_TEST (test_select_command_15)
{
    struct command command_data;

    command_data.id = 0;
    my_strcpy( command_data.name, "play", MAX_TOKEN_LENGTH );
    my_strcpy( command_data.gtp_argv[0], "black", MAX_TOKEN_LENGTH );
    my_strcpy( command_data.gtp_argv[1], "d4", MAX_TOKEN_LENGTH );
    command_data.gtp_argc = 2;

    init_board(BOARD_SIZE_DEFAULT);
    init_known_commands();
    select_command(&command_data);
    fail_unless( get_output_error() == false, "play command identified" );

    command_data.id = 0;
    my_strcpy( command_data.name, "undo", MAX_TOKEN_LENGTH );
    command_data.gtp_argc = 0;

    select_command(&command_data);
    fail_unless( get_output_error() == false, "undo command identified" );

    free_board();
}
コード例 #3
0
ファイル: main.c プロジェクト: 1i7/snippets
int main(void)
{
    uint8_t addr1, addr2; /* i2c addresses */
    uint16_t x, y;
    char buf[128]; /* temporary string buffer for various stuff */

    /* uart stuff */
    char rcvbuf[32], c;
    uint8_t rcvbufpos = 0;

    init_board();
    ov7670_init();

    printf("Camtest says hi!\n");
    printf("System clock: [%d]\n", SystemCoreClock);

    UART0_PrintString("Camtest says hi!\r\n");
    while (1) {
        c = UART0_Getchar();
        if (c == EOF) {
            continue;
        } else if ((c >= 32) && (c <= 126)) {
            rcvbuf[rcvbufpos++] = c;
        } else if (c == 13) {
            rcvbuf[rcvbufpos++] = 0;
            rcvbufpos = 0;
            if (strcmp(rcvbuf, "getimage") == 0) {
                ov7670_readframe();
                UART0_PrintString("OK\r\n");
            } else if (strlen(rcvbuf) >= 9 &&
                    strncmp(rcvbuf, "getline ", 8) == 0) {
                y = atoi(rcvbuf + 8);
                for (x = 0; x < 160; x ++) {
                    UART0_Sendchar(qqvgaframe1[x + (y * 160)]);
                    UART0_Sendchar(qqvgaframe2[x + (y * 160)]);
                }
            } else if (strlen(rcvbuf) == 9 &&
                    strncmp(rcvbuf, "regr 0x", 7) == 0) {
                addr1 = strtoul(rcvbuf + 7, NULL, 16);
                sprintf(buf, "0x%.2x 0x%.2x\r\n", addr1, ov7670_get(addr1));
                printf("%s", buf);
                UART0_PrintString(buf);
            } else if (strlen(rcvbuf) == 14 &&
                    strncmp(rcvbuf, "regw 0x", 7) == 0) {
                strncpy(buf, rcvbuf + 7, 2);
                buf[2] = 0;
                addr1 = strtoul((char *) buf, NULL, 16);
                addr2 = strtoul(rcvbuf + 12, NULL, 16);
                ov7670_set(addr1, addr2);
                sprintf(buf, "0x%.2x 0x%.2x\r\n", addr1, addr2);
                UART0_PrintString(buf);
            } else {
                UART0_PrintString("ERR\r\n");
                printf("Unknown command: [%s]\n", rcvbuf);
            }
        }
    }

    return 0;
}
コード例 #4
0
ファイル: ginput_lld_mouse.c プロジェクト: bhdminh/uGFX
void ginput_lld_mouse_init(void) {
	init_board();

	// Init default values. (From NHD-3.5-320240MF-ATXL-CTP-1 datasheet)
	// Valid touching detect threshold
	write_reg(FT5x06_ID_G_THGROUP, 1, 0x16);

	// valid touching peak detect threshold
	write_reg(FT5x06_ID_G_THPEAK, 1, 0x3C);

	// Touch focus threshold
	write_reg(FT5x06_ID_G_THCAL, 1, 0xE9);

	// threshold when there is surface water
	write_reg(FT5x06_ID_G_THWATER, 1, 0x01);

	// threshold of temperature compensation
	write_reg(FT5x06_ID_G_THTEMP, 1, 0x01);

	// Touch difference threshold
	write_reg(FT5x06_ID_G_THDIFF, 1, 0xA0);

	// Delay to enter 'Monitor' status (s)
	write_reg(FT5x06_ID_G_TIME_ENTER_MONITOR, 1, 0x0A);

	// Period of 'Active' status (ms)
	write_reg(FT5x06_ID_G_PERIODACTIVE, 1, 0x06);

	// Timer to enter ÔidleÕ when in 'Monitor' (ms)
	write_reg(FT5x06_ID_G_PERIODMONITOR, 1, 0x28);
}
コード例 #5
0
ファイル: minimax.c プロジェクト: JDongian/Party
int main(){
    //printf("%s", ANSI_WHITE); 
    //init_board
    //hide_cursor();
    clear_all();
    init_board(BOARD_ROW, BOARD_COL);
    init_board(ANALYSIS_ROW, ANALYSIS_COL);
    move_cursor(20, 0);
    printf("Pick a color: 0(white), 1(black): ");
    int usrcolor;
    scanf("%d", &usrcolor);
    int to_move = 0;
    move_cursor(20, 0);
    //printf("usr_color: %d\n" ,usrcolor);
    while(!check_win(to_move)){
        move_cursor(20, 0);
        //printf("to_move: %d\n", to_move);
        //printf("usrcolor: %d\n", usrcolor);
        //display_board();
        if(usrcolor == to_move){
            move_cursor(20, 0);
            clear_line();
            //printf("user move\n");
            uint16_t move;
            printf("Pick a space to play: ");
            //printf("&uscolor: %p, &move: %p\n", &move);
            scanf("%hd", &move);
            move = 1 << move;
            //printf("move: %d\n", move);
            update_board(move, to_move);
            update_analysis(move, to_move);
        } else {
            //move_cursor(20, 0);
            //printf("computer move\n");
            //printf("%x, %x\n", bboards[0], bboards[1]);
            uint16_t move = best_move(to_move);
            //printf("%x, %x\n", bboards[0], bboards[1]);
            //printf("is_legal(%d): %d\n", move, is_legal(move));
            //printf("bestmove: %x\n", move);
            update_board(move, to_move); 
            update_analysis(move, to_move);
        }
        to_move ^= 1;
    }
    //printf("check_win: %d", check_win(to_move));
    //display_board();
}
コード例 #6
0
ファイル: main.c プロジェクト: johnwbyrd/superpawn
void bench()
{
	int i;
	int t[3];
	double nps;

	/* setting the position to a non-initial position confuses the opening
	   book code. */
	close_book();

	for (i = 0; i < 64; ++i) {
		color[i] = bench_color[i];
		piece[i] = bench_piece[i];
	}
	side = LIGHT;
	xside = DARK;
	castle = 0;
	ep = -1;
	fifty = 0;
	ply = 0;
	hply = 0;
	set_hash();
	print_board();
	max_time = 1 << 25;
	max_depth = 5;
	for (i = 0; i < 3; ++i) {
		think(1);
		t[i] = get_ms() - start_time;
		printf("Time: %d ms\n", t[i]);
	}
	if (t[1] < t[0])
		t[0] = t[1];
	if (t[2] < t[0])
		t[0] = t[2];
	printf("\n");
	printf("Nodes: %d\n", nodes);
	printf("Best time: %d ms\n", t[0]);
	if (!ftime_ok) {
		printf("\n");
		printf("Your compiler's ftime() function is apparently only accurate\n");
		printf("to the second. Please change the get_ms() function in main.c\n");
		printf("to make it more accurate.\n");
		printf("\n");
		return;
	}
	if (t[0] == 0) {
		printf("(invalid)\n");
		return;
	}
	nps = (double)nodes / (double)t[0];
	nps *= 1000.0;

	/* Score: 1.000 = my Athlon XP 2000+ */
	printf("Nodes per second: %d (Score: %.3f)\n", (int)nps, (float)nps/243169.0);

	init_board();
	open_book();
	gen();
}
コード例 #7
0
ファイル: main.c プロジェクト: Rodobmx/Aviator
int main( void )
{
    init_board();
    init_aviator();
    
    // Boucle infinie, le jeux est sur timer
    while(1);
}
コード例 #8
0
void restorDefaultSettings(){
	settings.gameMode = TWO_PLAYERS;
	game_board.isBlackTurn = 0;
	settings.isUserBlack = 0;
	settings.minmax_depth = 1;

	init_board(game_board.board);
}
コード例 #9
0
ファイル: game.c プロジェクト: bpa/gamed
void start_placing(GameInstance *g, const Server *s) {
	g->accepting_players = false;
	msg_command.command = SR_CMD_START_PLACING;
	s->tell_all(g, (char*)&msg_command, 4);
	init_board(g, s);
	give_game_status(g, s, NULL);
	strcpy(g->status, "Placing armies");
}
コード例 #10
0
ファイル: coder1.c プロジェクト: lakshmananvelusamy/Hacks
int main() {

   init_board(); /* Initialise the internal board */

   sampleMethod(); /* Function where game is played */
 
   return 0;
}
コード例 #11
0
ファイル: loop.c プロジェクト: lukasmonk/irina
void begin(void)
{
    init_hash();
    init_data();
    init_board();
    setbuf(stdout, NULL);
    setbuf(stdin, NULL);
}
コード例 #12
0
ファイル: board.c プロジェクト: viktoria97/elsys.project2014
void game_begin(struct board_t *board, int *side, int *AI) {
	char filename[30];
	char ch = '0';	
	int dice1, dice2;
	int i;
	struct card_t drawed_card;
	srand(time(NULL));
	init_board(board);
	do {
		system("clear");
		printf("Do you want to play against AI BOT (1 - YES / 0 - NO)? ");
		scanf("%d", AI);
	} while(*AI != 0 && *AI != 1);
	printf("Enter player1's name: ");
	scanf("%s", board->pl[0].name);
	if( !(*AI) ) {
		printf("Enter player2's name: ");
		scanf("%s", board->pl[1].name);
	} else {
		strcpy(board->pl[1].name, "AI(BOT)");
	}
	board->pl[0].hp = MAX_HP;
	board->pl[1].hp = MAX_HP;
	printf("%s's is choosing deck: ", board->pl[0].name);
	scanf("%s", filename);
	while( !load_deck_from_file(board, 0, filename) ) {
		printf("(invalid file name) %s's is choosing deck: ", board->pl[0].name);
		scanf("%s", filename);
	}
	printf("%s's is choosing deck: ", board->pl[1].name);
	scanf("%s", filename);
	while( !load_deck_from_file(board, 1, filename) ) {
		printf("(invalid file name) %s's is choosing deck: ", board->pl[1].name);
		scanf("%s", filename);
	}
	system("clear");
	do {
		dice1 = rand() % 6 + 1;
		dice2 = rand() % 6 + 1;
		printf("%s threw %d out of 6!\n", board->pl[0].name, dice1);
		printf("%s threw %d out of 6!\n\n", board->pl[1].name, dice2);
	} while(dice1 == dice2);
	if(dice1 > dice2) {
		printf("%s will begin first!\n", board->pl[0].name);
		*side = 0;
	} else {
		printf("%s will begin first!\n", board->pl[1].name);
		*side = 1;
	}
	for(i = 0; i < 5; i++) {
		if(draw_card(&board->pl[0].deck, &drawed_card)) board->pl[0].hand.card[board->pl[0].hand.top++] = drawed_card;
		if(draw_card(&board->pl[1].deck, &drawed_card)) board->pl[1].hand.card[board->pl[1].hand.top++] = drawed_card;	
	}
	printf("Press any key to continue...\n");
	ch = getchar();
	ch = getchar();
	system("clear");
}
コード例 #13
0
ファイル: aocmd.c プロジェクト: cjecho/RTAI
int main(void)
{
	double omega = (2.0*M_PI*SIN_FREQ*SAMP_TIME)/1.0E9;
	RTIME until;
	RT_TASK *task;

	lsampl_t data[NCHAN*2];
	long k, sinewave, retval = 0;

	signal(SIGKILL, endme);
	signal(SIGTERM, endme);

	start_rt_timer(0);
	task = rt_task_init_schmod(nam2num("MYTASK"), 1, 0, 0, SCHED_FIFO, 0xF);
	printf("COMEDI CMD TEST BEGINS: SAMPLING FREQ: %d, RUN TIME: %d.\n", SAMP_FREQ, RUN_TIME);

	if (init_board()) {;
		printf("Board initialization failed.\n");
		return 1;
	}
	do_cmd();

	mlockall(MCL_CURRENT | MCL_FUTURE);
	rt_make_hard_real_time();

	until = rt_get_cpu_time_ns() + (long long)RUN_TIME*1000000000;
	for (k = 0; k < SAMP_FREQ*RUN_TIME && !end; k++) {
		sinewave =  (long)(maxdata/4*sin(k*omega));
		data[0] = (lsampl_t)(  sinewave + maxdata/2);
		data[1] = (lsampl_t)(- sinewave + maxdata/2);
		while (rt_comedi_command_data_write(dev, subdev, NCHAN, data) != NCHAN) {
			rt_sleep(nano2count(SAMP_TIME/2));
		}
		if (k == TRIGSAMP) {
			rt_comedi_trigger(dev, subdev);
		}
	}

	while (until > rt_get_cpu_time_ns()) {
		rt_sleep(nano2count(100000));
	}
	comedi_cancel(dev, subdev);
	comedi_close(dev);
	comedi_data_write(dev, subdev, 0, 0, AREF_GROUND, 2048);
	comedi_data_write(dev, subdev, 1, 0, AREF_GROUND, 2048);
	printf("COMEDI TEST ENDS.\n");

	if (retval < 0) {
		printf("rt_comedi_wait_timed overruns: %d\n", abs(retval));
	}

	stop_rt_timer();
	rt_make_soft_real_time();
	rt_task_delete(task);

	return 0;
}
コード例 #14
0
ファイル: spi.c プロジェクト: navr32/aery32
int main(void)
{
	volatile uint16_t rd0, rd1;		// Received data 0 and 1

	init_board();
	aery_gpio_init_pin(LED, GPIO_OUTPUT|GPIO_HIGH);

	aery_gpio_init_pins(
		porta,          /* pointer to port register address */
		SPI0_GPIO_MASK, /* pin mask */
		GPIO_FUNCTION_A /* options */
	);
	aery_gpio_init_pins(porta, SPI1_GPIO_MASK, GPIO_FUNCTION_B);

	/* Init SPI0 as master. The chip select pin 0 of SPI0 is set to work in
	 * spi mode 0 and 16 bits wide shift register. */
	aery_spi_init_master(spi0 /* pointer to spi register address */);
	aery_spi_setup_npcs(
		spi0,      /* pointer to spi register address */
		0,         /* chip select line number */
		SPI_MODE0, /* spi mode */
		16         /* spi shift register width in bits */
	);
	aery_spi_enable(spi0);

	/* Init SPI1 as master. The chip select pin 2 of SPI1 is set to work in
	 * spi mode 1 and 8 bits wide shift register.
	 */
	aery_spi_init_master(spi1);
	aery_spi_setup_npcs(spi1, 2, SPI_MODE1, 8);
	aery_spi_enable(spi1);

	for (;;) {
		/* Single 16 bit spi transmission. The word 0x5155 is transmitted
		 * by using SPI0 peripheral and chip select pin 0. The return value
		 * is the received data.
		 */
		rd0 = aery_spi_transmit(
			spi0,   /* pointer to the spi register address */
			0x5155, /* word to be transmitted */
			0,      /* chip select pin which to use */
			true    /* is the last transmission */
		);

		/* Partially transfer 24 bit word in 8 bits wide chunks by using
		 * SPI1 peripheral and chip select pin 2. Note that two of the
		 * first transmission indicate that they weren't the last ones to
		 * keep the chip select pin low.
		 */
		rd1 = aery_spi_transmit(spi1, 0x51, 2, false);
		rd1 |= aery_spi_transmit(spi1, 0x55, 2, false) << 8;
		rd1 |= aery_spi_transmit(spi1, 0xF3, 2, true) << 16;
	}

	return 0;
}
コード例 #15
0
ファイル: loop.c プロジェクト: lukasmonk/irina
void set_position(char *line)
{
    char *ini_moves;
    char *ini_fen;
    char *ini_startpos;
    int from, sz;

    strip(line);

    ini_moves = strstr(line, "moves");
    ini_fen = strstr(line, "fen");
    ini_startpos = strstr(line, "startpos");

    if (ini_startpos)
    {
        init_board();
    }
    else if (ini_fen)
    {
        fen_board(ini_fen + 4);
    }

    if (ini_moves)
    {
        for (from = 6, sz = 0; ini_moves[from]; from++)
        {
            if (ini_moves[from] == ' ')
            {
                if (sz >= 4)
                {
                    do_move(ini_moves, from - sz, sz);
                }
                sz = 0;
            }
            else
            {
                sz++;
            }
        }
        if (sz >= 4)
        {

            do_move(ini_moves, from - sz, sz);
        }
    }


    /*
     * position [fen <fenstring> | startpos ]  moves <move1> .... <movei>
     * set up the position described in fenstring on the internal board and
     * play the moves on the internal chess board.
     * if the game was played  from the start position the string "startpos" will be sent
     * Note: no "new" command is needed. However, if this position is from a different game than
     * the last position sent to the engine, the GUI should have sent a "ucinewgame" inbetween.
     */
}
コード例 #16
0
ファイル: gol.c プロジェクト: jjacobson93/comp280-labs
int main(int argc, char **argv) {
	if (argc < 3) {
		printf("Usage: ./gol <infile> <print>\n");
		return 0;
	}

	FILE *f = fopen(argv[1], "r");
	int to_print = strtol(argv[2], NULL, 10);

	// Check if we opened the file
	if (f != NULL) { 
		int num_rows = 0;
		int num_cols = 0;
		int num_iterations = 0;
		int num_pairs = 0;
		double total_time = 0.0;
		
		// read numbers
		fscanf(f, "%d\n%d\n%d\n%d", &num_rows, &num_cols, &num_iterations, &num_pairs);

		// set up board
		board_t *board = init_board(f, num_rows, num_cols, num_pairs);

		// set up timing
		struct timeval start_time;
		struct timeval end_time;
		gettimeofday(&start_time, NULL);

		// run iterations
		int i = num_iterations;
		while (board_next(board, &i)) {
			if (to_print) {
				print_board(board, num_iterations - i);
				usleep(200000);
				clear(num_rows + 4);
			}
			i--;
		}

		// get end time
		gettimeofday(&end_time, NULL);
		total_time = ((end_time.tv_sec + (end_time.tv_usec/1000000.0)) - (start_time.tv_sec + (start_time.tv_usec/1000000.0)));

		// print final board
		print_board(board, num_iterations);

		printf("total time for %d iteration%s of %dx%d world is %f sec\n", num_iterations, (num_iterations != 1) ? "s" : "", num_rows, num_cols, total_time);
		fclose(f);
		board_free(board);
	} else {
		printf("There was an error opening '%s'\n", argv[1]);
		return 1;
	}

	return 0;
}
コード例 #17
0
ファイル: main.c プロジェクト: JonHarder/gameOfLife
board clone_board(board b) {
  board newboard = init_board(b->height, b->width);
  int i,j;
  for(i=0; i<b->height; i++) {
    for(j=0; j<b->width; j++) {
      newboard->cells[i][j] = b->cells[i][j];
    }
  }
  return newboard;
}
コード例 #18
0
static void othello_init(void)
{
	g_iGameLevel = Class - 1;

	cur_col = 3;
	cur_row = 2;
	BlackPoint = 2;
	WhitePoint = 2;
	init_board(&chess_board);
}
コード例 #19
0
ファイル: main.c プロジェクト: williamlagos/serial
int
main(int argc, char *argv[])
{
	int		 i, c, done;
	int		 offset;
	char	 buf[128], str[64];
	short	 temp;

	i = 0;
	offset = 0;
	init_board();

read_input:
	if (IS_PRESSED(BUTTON1)) {
		UART0_puts("_BALANCE:1_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON2)) {
		UART0_puts("_RECHARGE:1:", 64);
		escrevenum(leds_state);
		UART0_puts("_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON3)) {
		UART0_puts("_DISCHARGE:1:", 64);
		escrevenum(leds_state);
		UART0_puts("_", 64);
		UART0_gets(str, sizeof(str));
		LCD_command(1);
		LCD_puts(str, sizeof(str));
		LCD_putchar('\n');
		temp = read_temp();
		show_temperature(temp);
	} else if (IS_PRESSED(BUTTON4)) {
		leds_state++;
		UPDATE_LED();
		uwait(1000);
	} else if (IS_PRESSED(BUTTON5)) {
		leds_state--;
		UPDATE_LED();
		uwait(1000);
	}
	goto read_input;

	/* NOTREACHED */
	return (0);
}
コード例 #20
0
ファイル: ui_game_othello.c プロジェクト: github188/1521
void othello_initial(BOOL BOW)
{
  control_t *p_mbox, *p_info;

  p_info = ui_game_get_ctrl(ROOT_ID_OTHELLO, GAME_INFO_ID);
  p_info = ctrl_get_child_by_id(p_info, 6);

  g_iGameLevel =
    (text_get_content(p_info) == IDS_GAME_EASY) ? OTHELLO_GAME_LEVEL_PRM :
    (text_get_content(p_info) ==
     IDS_GAME_NORMAL ? OTHELLO_GAME_LEVEL_JUR : OTHELLO_GAME_LEVEL_SER);

  p_info = ctrl_get_child_by_id(p_info->p_parent, 2);

  ctrl_default_proc(p_info, MSG_LOSTFOCUS, 0, 0);
  ctrl_paint_ctrl(p_info, TRUE);
  p_mbox = ui_game_get_ctrl(ROOT_ID_OTHELLO, GAME_BOARD_ID);
  ctrl_default_proc(p_mbox, MSG_GETFOCUS, 0, 0);

  cur_col = 3;
  cur_row = 2;
  BlackPoint = 2;
  WhitePoint = 2;

  if (!BOW) //if user is white, cpu first
  {
    init_board(&chess_board, FALSE);
    cpu_color = CHESS_BLACK;
    computer_play(&chess_board, callback);
    get_chess_score(&chess_board, &WhitePoint, &BlackPoint);
    othello_game = OTHELLO_HAPPY;
  }
  else
  {
    init_board(&chess_board, TRUE);
    cpu_color = CHESS_WHITE;
    othello_game = OTHELLO_HAPPY;
  }

  othello_update_status();
  othello_draw_background(TRUE);
}
コード例 #21
0
ファイル: main.c プロジェクト: portoedu/Tic-Tac-Toe-Engine
int main()
{

    /* Gera variáveis globais : board e melhor jogada */

    int i, caso, exit=0;
    char num;

    char **board = (char **) malloc (sizeof(char *) * 3);
    for (i=0; i<3; i++) {
        board[i] = (char *) malloc (sizeof(char) * 3);
    }


    while (exit != 5) {
        cabecario();
        /* Inicia o jogo printando as instruções de uso e inicializando o tabuleiro */

        init_board(board);
        /* Joga o jogo */

        printf("\t\t\t\t\t\t Escolha uma opção de jogo: \n");
        printf("\t\t\t\t\t\t |1- Um jogador\n");
        printf("\t\t\t\t\t\t |2- Dois jogadores\n");
        printf("\t\t\t\t\t\t |3- Ganhadores Anteriores\n");
        printf("\t\t\t\t\t\t |4- Créditos\n");
        printf("\t\t\t\t\t\t |5- Sair\n");
        scanf(" %c", &num);
        caso= letrapranum(num);
        switch(caso)
        {
        case 1:
            umjogador(board);
            break;
        case 2:
            doisjogadores(board);
            break;
        case 3:
            leiaarq();
            break;
        case 4:
            credit();
            break;
        case 5:
            system("clear");
            exit = 5;
            break;
        default:
            printf("Inválido");
        }
    }

    return 0; // Controle nunca deve chegar aqui
}
コード例 #22
0
int main(){
  //define board and init it
  int board[MAX_QUEENS];
  int size=getsize(1,MAX_QUEENS);
  init_board(board,size);

  //Solve board
  printf("\nSolutions to an %dx%d board:\n----------------------------\n",size,size);  
  solve(board,0,size);

  return 0;
}
コード例 #23
0
ファイル: go11.c プロジェクト: KitAiProject/Go
int main()
{
//srand( (unsigned)time( NULL ) );
  init_board();

  if ( 0 ) { selfplay(); return 0; }
  if ( 0 ) { test_playout(); return 0; }

  gtp_loop();

  return 0;
}
コード例 #24
0
ファイル: xomain.c プロジェクト: quatrix/kernel-tic-tak-toe
int init_module(void)
{
        Major = register_chrdev(0, DEVICE_NAME, &fops);

	if (Major < 0) {
	  printk(KERN_ALERT "Registering char device failed with %d\n", Major);
	  return Major;
	}

	printk(KERN_INFO "'mknod /dev/%s c %d 0'.\n", DEVICE_NAME, Major);
	init_board();

	return SUCCESS;
}
コード例 #25
0
ファイル: my2048.c プロジェクト: bnlb/C_Playground
int main(void) {
  int board[SIZE][SIZE] = { 0 };
  int empty_spot[2];

  // Ensure rand() returns random value.
  srand(time(NULL));

  init_board(board);
  print_board(board);
  printf("Up: 'k' Down: 'j' Left: 'h' Right: 'l'\n");

  while(1) {
    if (has_move_left(board)) {
      perform_user_action(board);
      if (!board_full(board)) add_tile(board);
      print_board(board);
    } else {
      print_board(board);
      printf("You're all done! Loading new game.\n");
      init_board(board);
    }
  }
}
コード例 #26
0
ファイル: game.cpp プロジェクト: Black-wingsvV/GwanKei
 Game::Game(const Layout& layout_S, const Layout& layout_N, bool EW /*=1*/) {
   if(!EW) {
     layout[convert_orient_to_player(South)] = layout_S;
     layout[convert_orient_to_player(North)] = layout_N;
     enabled[convert_orient_to_player(South)] = true;
     enabled[convert_orient_to_player(North)] = true;
   } else {
     layout[convert_orient_to_player(East)] = layout_S;
     layout[convert_orient_to_player(West)] = layout_N;
     enabled[convert_orient_to_player(East)] = true;
     enabled[convert_orient_to_player(West)] = true;
   }
   init_board();
 }
コード例 #27
0
ファイル: queenN.c プロジェクト: ywang2014/ProgramLearning
// 解决N皇后问题
int queen(int n)
{
	int count = 0;
	int a[MAX_LENGTH];
	init_board(a, n);
	int i = 0;
	while ( 1 )
	{
		if ( a[i] < n )
		{
			// 如果皇后的位置尚未超出棋盘范围
			// 需要检查第i行的皇后是否与前i-1行的皇后冲突
			if ( is_conflict(a, i) )
			{
				// 如果冲突,尝试下一个位置
				a[i]++;
				continue;
			}
			if ( i >= n - 1 )
			{
				// 如果已经到最后一行,也即找到一个解,首先输出它
				count++;
				print_board(a, n);
				// 然后尝试当前行的皇后的下一个位置
				a[n-1]++;
				continue;
			}
			// 没有冲突,尝试下一行
			i++;
			continue;
		}
		else
		{
			// 皇后的位置已经超出棋盘范围
			// 那么该行的皇后复位
			a[i] = 0; // 可以省略...??
			// 回退到上一行
			i--;
			if ( i < 0 )
			{
				// 已经不能再退了,函数结束
				return count;
			}
			// 尝试上一行的皇后的下个位置
			a[i]++;
			continue;
		}
	}
}
コード例 #28
0
/**
 * @brief   Low level GDISP driver initialization.
 *
 * @notapi
 */
bool_t gdisp_lld_init(void) {
  // Initialize your display
  init_board();

  // Hardware reset.
  setpin_reset(TRUE);
  delay_ms(10);
  setpin_reset(FALSE);
  delay_ms(1);

  write_cmd(ST7565_LCD_BIAS_7);
  write_cmd(ST7565_ADC_NORMAL);
  write_cmd(ST7565_COM_SCAN_INC);
  set_display_start_line(0);

  set_contrast(32);
  write_cmd(ST7565_RESISTOR_RATIO | 0x3);

  // turn on voltage converter (VC=1, VR=0, VF=0)
  write_cmd(ST7565_POWER_CONTROL | 0x04);
  delay_ms(50);
  // turn on voltage regulator (VC=1, VR=1, VF=0)
  write_cmd(ST7565_POWER_CONTROL | 0x06);
  delay_ms(50);
  // turn on voltage follower (VC=1, VR=1, VF=1)
  write_cmd(ST7565_POWER_CONTROL | 0x07);
  delay_ms(50);

  display_on();
  write_cmd(ST7565_ALLON_NORMAL);
  invert_display(0);// Disable Inversion of display.

  write_cmd(ST7565_RMW);
  gdisp_lld_display();

  // Initialize the GDISP structure
  GDISP.Width = GDISP_SCREEN_WIDTH;
  GDISP.Height = GDISP_SCREEN_HEIGHT;
  GDISP.Orientation = GDISP_ROTATE_0;
  GDISP.Powermode = powerOn;
  GDISP.Contrast = 50;
#if GDISP_NEED_VALIDATION || GDISP_NEED_CLIP
  GDISP.clipx0 = 0;
  GDISP.clipy0 = 0;
  GDISP.clipx1 = GDISP.Width;
  GDISP.clipy1 = GDISP.Height;
#endif
  return TRUE;
}
コード例 #29
0
int main()
{
	struct board_t board;
	int winner = 0;
	int pTurn = 0;
	int pCard = 0;
	int mLane = 0;
	struct card_t generatedCard;
	struct deck_t generatedDeck = GenerateMultipleCards(30);
	WriteGeneratedDeckToFile(&generatedDeck,"idiocracy.csv");
	generatedCard = GenerateCard();
	print_card(generatedCard,1);
	// INIT STUFF HERE !
	if (!init_board(&board)) {
		printf("Error.File Not Found! WTF, DO NOT TOUCH THE DATA !\n");
		return -1;
	}
	// =================
	winner = 0;
	while(winner == 0) {
		pCard = 0;
		turn_begin(&board.Player[pTurn]);
		//Print Board Here !
		PrintBoard(board);
		//==================
		if (pTurn == 0) 
		while (pCard != 6) {
			printf("Choose card:");
			scanf("%d",&pCard);
			if (pCard !=6 && board.Player[pTurn].Open_Spots_Hand[pCard-1] != 1) {
				printf("\nChoose lane:");
				scanf("%d",&mLane);
				int result = play_card(&board,pTurn,pCard-1,mLane-1);
						PrintBoard(board);
			}		
			
		}
		else RunSimpleAI(&board,pTurn);
		turn_end(&board,pTurn);
		if (board.Player[pTurn].health <= 0) {				
			winner = 1-pTurn;		
			break;	
		}		
		pTurn = 1-pTurn;				
	}
	printf("\n\nWinner is Player: %d\n\n",winner+1);
	
	return 0;
}
コード例 #30
0
ファイル: eluosi.c プロジェクト: yumm007/C
int main(void)
{
   int ret, c;

   ret = fb_open();
   if (ret != 0) {
	fprintf(stderr, "fb_open() error.\n");
		exit(1);
   }
   
	init_board();

   fb_close();
   return 0;
}