示例#1
0
void writelog(char* format, ...) {
    
    startlog();
    
    if(logfile == 0)
        return;
    
    char buffer[0xFFF];
    va_list args;
    va_start (args, format);
    vsprintf (buffer,format, args);
    va_end (args);
    
    strcat(buffer, "\n");
    
    int len = strlen(buffer);
    fwrite(buffer, sizeof(char), len, logfile);
    
    endlog();
}
示例#2
0
文件: input.c 项目: Meilka/copter
void handleKeydown (SDLKey key)
{
	float tempin;
//	printf("keydown: %d\n", key);
	if (inputmode > 0 && key != 13)
	{
		userinputbuffer[userinputbufferpos] = (uint8_t)key;
		userinputbufferpos ++;
		if (userinputbufferpos == 128)
		{
			printf("\nuser input buffer overflow\n");
			userinputbufferpos = 0;
		}
	}
	switch (key)
	{
		case SDLK_ESCAPE:
			break;
		case 112: /* P */
			printf("\nType new P value: ");
			inputmode = 1;
			break;
		case 105: /* I */
			printf("\nType new I value: ");
			inputmode = 2;
			break;
		case 100: /* D */
			printf("\nType new D value: ");
			inputmode = 3;
			break;
		case 115: /* S */
			printf("\nCurrent PID values: ");
			printf("P = %f, ", KPin);
			printf("I = %f, ", KIin);
			printf("D = %f\n", KDin);
			printf("    New PID values: ");
			printf("P = %f, ", KPout);
			printf("I = %f, ", KIout);
			printf("D = %f\n", KDout);
			fflush(stdout);
			break;
		case 103: /* G */
			getPID();
			break;
		case 13: /* enter */
			parseuserinput();
			break;
		case 113: /* Q */
			sendP();
			break;
		case 119: /* W */
			sendI();
			break;
		case 101: /* E */
			sendD();
			break;
		case 108: /* L */
			startlog();
			break;
		case 107: /* K */
			printlog();
			break;
	}
}
示例#3
0
void imcsplay(int argc, char **argv) {
    setlinebuf(stdout);
    if (argc < 5 || argc > 7)
	usage();
    char mecolor = '?';
    int megame = 0;
    switch(argv[2][0]) {
    case 'O':
	switch(argv[2][1]) {
	case 'W':
	case 'B':
	case '?':
	    mecolor = argv[2][1];
	    break;
	default:
	    usage();
	}
	break;
    case 'A': {
	char ch = argv[2][1];
	if (isdigit(ch)) {
	    megame = atoi(&argv[2][1]);
	} else if (ch == 'W' || ch == 'B') {
	    mecolor = ch;
	    megame = atoi(&argv[2][2]);
	} else {
	    usage();
	}
	if (megame <= 0)
	    usage();
	break;
    }
    default:
	usage();
    }
    char *meuser = argv[3];
    char *mepassword = argv[4];
    char *host = "imcs.svcs.cs.pdx.edu";
    if (argc > 5)
	host = argv[5];
    int port = 3589;
    if (argc > 6) {
	port = atoi(argv[6]);
	if (port <= 0)
	    usage();
    }
    FILE *nf = netopen(host, port);
    setlinebuf(nf);
    startlog();
    char *greeting = expectcmd(nf, 1, 100, 0);
    (void) strtok(greeting, " ");
    char *pgm = strtok(0, " ");
    assert(!strcmp(pgm, "imcs"));
    char *version = strtok(0, " \r\n");
    if(strcmp(version, "2.5")) {
	fprintf(stderr, "got unexpected imcs version %s\n", version);
	exit(1);
    }
    sendcmd(nf, "me %s %s", meuser, mepassword);
    (void) expectcmd(nf, 1, 201, 0);
    if (megame != 0) {
	if (mecolor == '?')
	    sendcmd(nf, "accept %d", megame);
	else
	    sendcmd(nf, "accept %d %c", megame, mecolor);
	(void) expectcmd(nf, 1, 105, 106, 0);
    } else {
	if (mecolor == '?')
	    sendcmd(nf, "offer");
	else
	    sendcmd(nf, "offer %c", mecolor);
	(void) expectcmd(nf, 1, 103, 0);
	logmsg("waiting for opponent");
	(void) expectcmd(nf, 1, 105, 106, 0);
	logmsg("opponent found");
    }
    struct state s = s0;
    s.cureval = eval(&s);
    if (nttable > 0)
	s.curzhash = zhash(&s);
    while (1) {
	int ch = fgetc(nf);
	int r = ungetc(ch, nf);
	assert(r != EOF);
	if (isdigit(ch)) {
	    s = readstate(nf, 1);
	    s.cureval = eval(&s);
	    if (nttable > 0)
		s.curzhash = zhash(&s);
	    continue;
	}
	switch (ch) {
	case '?': {
	    char *r = getnet(nf, "?");
	    char *q = strtok(r, " ");
	    assert(!strcmp(q, "?"));
	    char *tl = strtok(0, " ");
	    char *tr = strtok(0, " ");
	    assert(tl && tr);
	    int t = readtimems(tl);
	    t = 95 * t / (100 * ((81 - s.ply) / 2));
	    struct move m = idnegamax(&s, t, 0);
	    logmsg("value %d at time %d depth %d for %s\n\n",
		   v0, t, d0, movestr(&m));
	    move(&s, &m, 0);
	    sendcmd(nf, "%s", movestr(&m));
	    printstate(&s, 1);
	    if (ponder)
		(void) idnegamax(&s, 0, nf);
	    continue;
	}
	case '!':
	    assert(fgetc(nf) == '!');
	    int ch;
	    do
		ch = fgetc(nf);
	    while (isspace(ch));
	    ungetc(ch, nf);
	    struct move m = getmove(nf, &s);
	    move(&s, &m, 0);
	    continue;
	case '=':
	    (void) getnet(nf, "=");
	    break;
	case 'X':
	    (void) getnet(nf, "X");
	    break;
	default:
	    (void) getnet(nf, "...");
	    continue;
	}
	break;
    }
    fclose(nf);
}