Ejemplo n.º 1
0
static char	*concatenate(char *path, char *pwd)
{
	char	*extract;
	char	*tmp;

	while ((extract = ft_strdupchr(path, '/')))
	{
		if (!ft_strcmp(extract, ".."))
		{
			tmp = ft_strrchr(pwd, '/');
			ft_bzero(tmp, ft_strlen(tmp));
			move_str(&path, 3, -3, ft_strlen(path));
			ft_bzero(path + ft_strlen(path) - 3, 3);
		}
		else
		{
			pwd = ft_freejoin(pwd, "/");
			pwd = ft_freejoin(pwd, extract);
			move_str(&path, ft_strlen(extract) + 1, -(ft_strlen(extract) + 1),
					ft_strlen(pwd));
		}
		ft_strdel(&extract);
	}
	if (ft_strcmp(pwd, "/"))
		pwd = ft_freejoin(pwd, "/");
	return (ft_freejoin(pwd, path));
}
Ejemplo n.º 2
0
GTPResponse HavannahGTP::gtp_history(vecstr args){
	string ret;
	vector<Move> hist = game.get_hist();
	for(unsigned int i = 0; i < hist.size(); i++)
		ret += move_str(hist[i]) + " ";
	return GTPResponse(true, ret);
}
Ejemplo n.º 3
0
GTPResponse HavannahGTP::play(const string & pos, int toplay){
	if(toplay != game.toplay())
		return GTPResponse(false, "It is the other player's turn!");

	if(game.getboard().won() >= 0)
		return GTPResponse(false, "The game is already over.");

	Move m = parse_move(pos);

	if(!game.valid(m))
		return GTPResponse(false, "Invalid move");

	move(m);

	log(string("play ") + (toplay == 1 ? 'w' : 'b') + ' ' + move_str(m, false));

	if(verbose >= 2)
		logerr("Placement: " + move_str(m) + ", outcome: " + game.getboard().won_str() + "\n" + game.getboard().to_s(colorboard));

	return GTPResponse(true);
}
Ejemplo n.º 4
0
static int kbdctx_refresh_keymap(kbdctx *kc) {
        idev_session *s;
        idev_device *d;
        Iterator i, j;
        kbdmap *km;
        int r;

        if (kc->kbdmap &&
            streq_ptr(kc->locale_x11_model, kc->last_x11_model) &&
            streq_ptr(kc->locale_x11_layout, kc->last_x11_layout) &&
            streq_ptr(kc->locale_x11_variant, kc->last_x11_variant) &&
            streq_ptr(kc->locale_x11_options, kc->last_x11_options))
                return 0 ;

        move_str(&kc->last_x11_model, &kc->locale_x11_model);
        move_str(&kc->last_x11_layout, &kc->locale_x11_layout);
        move_str(&kc->last_x11_variant, &kc->locale_x11_variant);
        move_str(&kc->last_x11_options, &kc->locale_x11_options);

        log_debug("idev-keyboard: new default keymap: [%s / %s / %s / %s]",
                  kc->last_x11_model, kc->last_x11_layout, kc->last_x11_variant, kc->last_x11_options);

        /* TODO: add a fallback keymap that's compiled-in */
        r = kbdmap_new_from_names(&km, kc, kc->last_x11_model, kc->last_x11_layout,
                                  kc->last_x11_variant, kc->last_x11_options);
        if (r < 0)
                return log_debug_errno(r, "idev-keyboard: cannot create keymap from locale1: %m");

        kbdmap_unref(kc->kbdmap);
        kc->kbdmap = km;

        HASHMAP_FOREACH(s, kc->context->session_map, i)
                HASHMAP_FOREACH(d, s->device_map, j)
                        if (idev_is_keyboard(d))
                                keyboard_update_kbdmap(keyboard_from_device(d));

        return 0;
}
Ejemplo n.º 5
0
int main(void){
	int i;
	int ccr;
	int count = 500;
	double angles[3];
	
	
	sys_clk_configure();
  
  gpio_configure();
	
	timer_1_configure();
	
	robot_pos[0] = 15;
	robot_pos[1] = 15;
	
	
	// servo 1
	// 90, or straight down, 1150 maybe
	// left 45: 725
	// right 45: 1475
	
	
	// servo 1 angle 500 + 7.2222x
	
	// servo 2
	// straight 0 degrees : 2500
	// 90 = 1750
	// 45 = 2125
	// 2500 - 8.333x
	
	// servo 3
	// straight 0 degrees: 500
	// 90 degrees : 1225
	// 45 degrees : 863
	// 500 + 8x
	
	move_str(10, 20, 0, &angles[0]);
//	move_str(5, 20, 0, &angles[0]);
//	move_str(20, 20, 0, &angles[0]);
//	move_str(20, 10, 0, &angles[0]);
//	move_str(5, 10, 0, &angles[0]);
	
	
		
  // Dead loop & program hangs here
	while(1);
	
}
Ejemplo n.º 6
0
/* Let's make the iPod think about ;-) */
void computer_play(void)
{
	if (!is_mini) {
		pz_draw_header("computer play");
	}

	/* think about the move and make it */
	//sleep(1);
	printf("think\n");
	think(2);

	//sleep(1);
	if (!pv[0][0].u) {
		printf("No legal moves\n");
		if (!is_mini) {
			pz_draw_header ("No legal moves");
		}
	}

	sprintf(cpu_move,"%s", move_str(pv[0][0].b));

	makemove(pv[0][0].b);
	ply = 0;
	gen_moves();
	if (in_check(LIGHT)) {
		if (is_mini) {
			draw_message("     ", "Check");
		}
		else {
			pz_draw_header("Check");
		}
	}
	else
	{
		if (is_mini) {
			draw_message("     ", "Play");
		}
		else {
			pz_draw_header("Your Turn");
		}
	}
}
Ejemplo n.º 7
0
/* ***********************************************************/
int main(int argc, char* argv[])
{
        GR_EVENT event;
	GR_WM_PROPERTIES props;

	int computer_side;
	char s[256];
	int i;
	BOOL found;
	char temp[50];	

        if (GrOpen() < 0) {
                fprintf(stderr, "tuxchess: cannot open graphics\n");
                exit(1);
        }

	load_images();

        master = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, BM_WIDTH, BM_HEIGHT, 0, WHITE, WHITE);
        board = GrNewWindow((GR_WINDOW_ID) master, 0, 0, 394, 394, 0, WHITE, WHITE);
        text = GrNewWindow((GR_WINDOW_ID) master, 0, 393, 394, 20, 0, BLACK, BLACK); 

        GrSelectEvents(master, GR_EVENT_MASK_CLOSE_REQ | GR_EVENT_MASK_EXPOSURE | GR_EVENT_MASK_BUTTON_DOWN);

	props.flags = GR_WM_FLAGS_PROPS | GR_WM_FLAGS_TITLE;
	props.props = GR_WM_PROPS_BORDER | GR_WM_PROPS_CAPTION | GR_WM_PROPS_CLOSEBOX;
	props.title = TITLE;
	GrSetWMProperties(master, &props);

	/* eliminate white background*/
	props.flags = GR_WM_FLAGS_PROPS;
	props.props = GR_WM_PROPS_NOBACKGROUND;
	GrSetWMProperties(board, &props);

        GrMapWindow(master);
        GrMapWindow(board);
        GrMapWindow(text);
                                   
        gc = GrNewGC();
        text_gc = GrNewGC();

	init();
	gen();
	max_time = 1 << 25;
	max_depth = 4;

	if (argc > 1)
		computer_side = side;	/* computer plays white */
	else
	{
		computer_side = EMPTY;	/* human plays white */
		gprintf("Make a move...");
	}

        for (;;) 
	{

		if (side == computer_side) 
		{
			/* think about the move and make it */
			think(0);
			if (!pv[0][0].u) {
				gprintf("No legal moves");
				computer_side = EMPTY;
				continue;
			}
			
			sprintf(temp,"Computer's move: %s\n", move_str(pv[0][0].b));
			gprintf(temp);
			makemove(pv[0][0].b);
			ply = 0;
			gen();
			print_board();
			print_result();
			continue;
		}
		
                GrGetNextEvent(&event);
                switch(event.type) 
		{
			case GR_EVENT_TYPE_CLOSE_REQ:
				GrClose();
				exit(0);
				/* no return*/
			case GR_EVENT_TYPE_EXPOSURE:
				print_board();
				gprintf(NULL);
				break;
			case GR_EVENT_TYPE_BUTTON_DOWN:
				mouse_hit(event.button.x, event.button.y);
				break;
		}

		if (to != 999)
		{

			/* loop through the moves to see if it's legal */
			found = FALSE;
			for (i = 0; i < first_move[1]; ++i)
				if (gen_dat[i].m.b.from == from && gen_dat[i].m.b.to == to) 
				{
					found = TRUE;

					/* get the promotion piece right */
					if (gen_dat[i].m.b.bits & 32)
						switch (s[4]) 
						{
							case 'N':
								break;
							case 'B':
								i += 1;
								break;
							case 'R':
								i += 2;
								break;
							default:
								i += 3;
								break;
						}
					break;
				} /* if */

			if (!found || !makemove(gen_dat[i].m.b))
				gprintf("Illegal move.\n");
			else 
			{
				ply = 0;
				gen();
				print_board();
				print_result();
				computer_side = side;
				to = 999;
			}
		} /* if to != 999 */
	} /* for (;;) */

	return(0); /* never reached */
}
Ejemplo n.º 8
0
int mainConsoleChess(int pick_side)
{
	int computer_side;
	char s[256];
	int m;

	printf("\n");
	printf("Phung Nhat Huy and Pham Duy Hung's Console Chess\n");
	printf("\n");
	printf("Type \"help\" to displays a list of commands.\n");
	printf("\n");
	init_hash();
	init_board();
	gen();
	computer_side = EMPTY;
	max_time = 1 << 25;
	max_depth = 4;
	for (;;) {
		if (side == computer_side) {  /* computer's turn */
			
			/* think about the move and make it */
			//think(1);
			if (!pv[0][0].u) {
				printf("(no legal moves)\n");
				computer_side = EMPTY;
				continue;
			}
			printf("Your enermy's move: %s\n", move_str(pv[0][0].b));
			makemove(pv[0][0].b);
			ply = 0;
			gen();
			print_result();
			continue;
		}

		/* get user input */
		printf("ConsoleChess > ");
		if (scanf("%s", s) == EOF)
			return 0;
		if (!strcmp(s, "on")) {
			computer_side = side;
			continue;
		}
		if (!strcmp(s, "off")) {
			computer_side = EMPTY;
			continue;
		}
		if (!strcmp(s, "undo")) {
			if (!hply)
				continue;
			computer_side = EMPTY;
			takeback();
			ply = 0;
			gen();
			continue;
		}
		if (!strcmp(s, "new")) {
			computer_side = EMPTY;
			init_board();
			gen();
			continue;
		}
		if (!strcmp(s, "d")) {
			print_board();
			continue;
		}
		/*if (!strcmp(s, "bench")) {
			computer_side = EMPTY;
			bench();
			continue;
		}*/
		if (!strcmp(s, "bye")) {
			printf("Thanks for playing. Enjoy!\n");
			break;
		}
		if (!strcmp(s, "help")) {
			printf("on - computer plays for the side to move\n");
			printf("off - computer stops playing\n");
			printf("undo - takes back a move\n");
			printf("new - starts a new game\n");
			printf("d - display the board\n");
			printf("bye - exit the program\n");
			printf("Enter moves in coordinate notation, e.g., e2e4, e7e8Q (for promote moving)\n");
			continue;
		}

		/* maybe the user entered a move? */
		m = parse_move(s);
		if (m == -1 || !makemove(gen_dat[m].m.b))
			printf("Illegal move.\n");
		else {
			ply = 0;
			gen();
			print_result();
		}
	}
	//close_book();
	return 0;
}
Ejemplo n.º 9
0
int book_move()
{
	char line[256];
	char book_line[256];
	int i, j, m;
	int move[50];  /* the possible book moves */
	int count[50];  /* the number of occurrences of each move */
	int moves = 0;
	int total_count = 0;

	if (!book_file || hply > 25)
		return -1;

	/* line is a string with the current line, e.g., "e2e4 e7e5 g1f3 " */
	line[0] = '\0';
	j = 0;
	for (i = 0; i < hply; ++i)
		j += sprintf(line + j, "%s ", move_str(hist_dat[i].m.b));

	/* compare line to each line in the opening book */
	fseek(book_file, 0, SEEK_SET);
	while (fgets(book_line, 256, book_file)) {
		if (book_match(line, book_line)) {

			/* parse the book move that continues the line */
			m = parse_move(&book_line[strlen(line)]);
			if (m == -1)
				continue;
			m = gen_dat[m].m.u;

			/* add the book move to the move list, or update the move's
			   count */
			for (j = 0; j < moves; ++j)
				if (move[j] == m) {
					++count[j];
					break;
				}
			if (j == moves) {
				move[moves] = m;
				count[moves] = 1;
				++moves;
			}
			++total_count;
		}
	}

	/* no book moves? */
	if (moves == 0)
		return -1;

	/* Think of total_count as the set of matching book lines.
	   Randomly pick one of those lines (j) and figure out which
	   move j "corresponds" to. */
	j = rand() % total_count;
	for (i = 0; i < moves; ++i) {
		j -= count[i];
		if (j < 0)
			return move[i];
	}
	return -1;  /* shouldn't get here */
}
Ejemplo n.º 10
0
int main()
{
	int computer_side;
	char s[256];
	int m;

	printf("\n");
	printf("Tom Kerrigan's Simple Chess Program (TSCP)\n");
	printf("version 1.81, 2/5/03\n");
	printf("Copyright 1997 Tom Kerrigan\n");
	printf("\n");
	printf("\"help\" displays a list of commands.\n");
	printf("\n");
	init_hash();
	init_board();
	open_book();
	gen();
	computer_side = EMPTY;
	max_time = 1 << 25;
	max_depth = 4;
	for (;;) {
		if (side == computer_side) {  /* computer's turn */
			
			/* think about the move and make it */
			think(1);
			if (!pv[0][0].u) {
				printf("(no legal moves)\n");
				computer_side = EMPTY;
				continue;
			}
			printf("Computer's move: %s\n", move_str(pv[0][0].b));
			makemove(pv[0][0].b);
			ply = 0;
			gen();
			print_result();
			continue;
		}

		/* get user input */
		printf("tscp> ");
		if (scanf("%s", s) == EOF)
			return 0;
		if (!strcmp(s, "on")) {
			computer_side = side;
			continue;
		}
		if (!strcmp(s, "off")) {
			computer_side = EMPTY;
			continue;
		}
		if (!strcmp(s, "st")) {
			scanf("%d", &max_time);
			max_time *= 1000;
			max_depth = 32;
			continue;
		}
		if (!strcmp(s, "sd")) {
			scanf("%d", &max_depth);
			max_time = 1 << 25;
			continue;
		}
		if (!strcmp(s, "undo")) {
			if (!hply)
				continue;
			computer_side = EMPTY;
			takeback();
			ply = 0;
			gen();
			continue;
		}
		if (!strcmp(s, "new")) {
			computer_side = EMPTY;
			init_board();
			gen();
			continue;
		}
		if (!strcmp(s, "d")) {
			print_board();
			continue;
		}
		if (!strcmp(s, "bench")) {
			computer_side = EMPTY;
			bench();
			continue;
		}
		if (!strcmp(s, "bye")) {
			printf("Share and enjoy!\n");
			break;
		}
		if (!strcmp(s, "xboard")) {
			xboard();
			break;
		}
		if (!strcmp(s, "help")) {
			printf("on - computer plays for the side to move\n");
			printf("off - computer stops playing\n");
			printf("st n - search for n seconds per move\n");
			printf("sd n - search n ply per move\n");
			printf("undo - takes back a move\n");
			printf("new - starts a new game\n");
			printf("d - display the board\n");
			printf("bench - run the built-in benchmark\n");
			printf("bye - exit the program\n");
			printf("xboard - switch to XBoard mode\n");
			printf("Enter moves in coordinate notation, e.g., e2e4, e7e8Q\n");
			continue;
		}

		/* maybe the user entered a move? */
		m = parse_move(s);
		if (m == -1 || !makemove(gen_dat[m].m.b))
			printf("Illegal move.\n");
		else {
			ply = 0;
			gen();
			print_result();
		}
	}
	close_book();
	return 0;
}
Ejemplo n.º 11
0
void xboard()
{
	int computer_side;
	char line[256], command[256];
	int m;
	int post = 0;

	signal(SIGINT, SIG_IGN);
	printf("\n");
	init_board();
	gen();
	computer_side = EMPTY;
	for (;;) {
		fflush(stdout);
		if (side == computer_side) {
			think(post);
			if (!pv[0][0].u) {
				computer_side = EMPTY;
				continue;
			}
			printf("move %s\n", move_str(pv[0][0].b));
			makemove(pv[0][0].b);
			ply = 0;
			gen();
			print_result();
			continue;
		}
		if (!fgets(line, 256, stdin))
			return;
		if (line[0] == '\n')
			continue;
		sscanf(line, "%s", command);
		if (!strcmp(command, "xboard"))
			continue;
		if (!strcmp(command, "new")) {
			init_board();
			gen();
			computer_side = DARK;
			continue;
		}
		if (!strcmp(command, "quit"))
			return;
		if (!strcmp(command, "force")) {
			computer_side = EMPTY;
			continue;
		}
		if (!strcmp(command, "white")) {
			side = LIGHT;
			xside = DARK;
			gen();
			computer_side = DARK;
			continue;
		}
		if (!strcmp(command, "black")) {
			side = DARK;
			xside = LIGHT;
			gen();
			computer_side = LIGHT;
			continue;
		}
		if (!strcmp(command, "st")) {
			sscanf(line, "st %d", &max_time);
			max_time *= 1000;
			max_depth = 32;
			continue;
		}
		if (!strcmp(command, "sd")) {
			sscanf(line, "sd %d", &max_depth);
			max_time = 1 << 25;
			continue;
		}
		if (!strcmp(command, "time")) {
			sscanf(line, "time %d", &max_time);
			max_time *= 10;
			max_time /= 30;
			max_depth = 32;
			continue;
		}
		if (!strcmp(command, "otim")) {
			continue;
		}
		if (!strcmp(command, "go")) {
			computer_side = side;
			continue;
		}
		if (!strcmp(command, "hint")) {
			think(0);
			if (!pv[0][0].u)
				continue;
			printf("Hint: %s\n", move_str(pv[0][0].b));
			continue;
		}
		if (!strcmp(command, "undo")) {
			if (!hply)
				continue;
			takeback();
			ply = 0;
			gen();
			continue;
		}
		if (!strcmp(command, "remove")) {
			if (hply < 2)
				continue;
			takeback();
			takeback();
			ply = 0;
			gen();
			continue;
		}
		if (!strcmp(command, "post")) {
			post = 2;
			continue;
		}
		if (!strcmp(command, "nopost")) {
			post = 0;
			continue;
		}
		m = parse_move(line);
		if (m == -1 || !makemove(gen_dat[m].m.b))
			printf("Error (unknown command): %s\n", command);
		else {
			ply = 0;
			gen();
			print_result();
		}
	}
}
Ejemplo n.º 12
0
string HavannahGTP::move_str(int x, int y, int hguic){
	return move_str(Move(x, y), hguic);
}
Ejemplo n.º 13
0
GTPResponse HavannahGTP::gtp_all_legal(vecstr args){
	string ret;
	for(Board::MoveIterator move = game.getboard().moveit(); !move.done(); ++move)
		ret += move_str(*move) + " ";
	return GTPResponse(true, ret);
}