예제 #1
0
int main(void) {
    int r;

    if (transmit_all(1, HI, sizeof(HI)-1) != 0) {
        _terminate(0);
    }
    
    while(1){
        if (transmit_all(1, ASK, sizeof(ASK)-1) != 0) {
            _terminate(0);
        }
        r = check();
        if (r == -1){
            break;
        }
        else if (r == 0){
            if (transmit_all(1, NO, sizeof(NO)-1) != 0) {
                _terminate(0);
            }
        }
        else{
            if (transmit_all(1, YES, sizeof(YES)-1) != 0) {
                _terminate(0);
            }
        }
    }
    return 0;
}
예제 #2
0
zoom_filter_t * make_compound_sample_zoom(compounds_sample_t *s){
	zoom_filter_t *zf = new_zoom_filter(n_elements_from_sampsz(s->sample_size));
	if(zf == NULL){
		char * m = "failed new zdf";
		transmit_all(STDOUT, m, strlen(m));
		return NULL;
	}


	for(int i =0; i < s->sample_size; ++i){
		int sample_idx = get_chem_ref_at_idx(s, i);
		if(sample_idx > N_FORMULAS-1 ){
			// todo free zf
			char * m = "failed new zdf2";
			transmit_all(STDOUT, m, strlen(m));
			zoom_free(zf);
			return NULL;
		}

		char * cn = chem_formulas[sample_idx].compound_name;
		hash_pair_t *hp = hash_pair_buf(cn, strlen(cn) );
		zoom_add(hp, zf);
		
		// todo check number transmitted


	}
	return zf;
}
예제 #3
0
int turn(player *current){
    int r, c;
    char input[4];
    int location;
    print(*current, TURN);
#ifdef PATCHED
    if (receive_delim(0, input, sizeof(input), '\n', &rxlen) != 0) {
        _terminate(0);
    }
#else
    if (receive_delim(0, input, 16, '\n', &rxlen) != 0) {
        _terminate(0);
    }
#endif
    if (rxlen == 0 || input[0] == 'q')
        return 1;
    location = input[0] - '0';
//char buf[4];
//buf[0] = '\n'; buf[1] = 'p'; buf[2] = location + '0'; buf[3] = '\n'; transmit_all(2, buf, 4);
    if(input[0] > '9' || input[0] < '1'){
	     if (transmit_all(1, INVAL, sizeof(INVAL)-1) != 0) {
	         _terminate(0);
	     }
    }
    else{
	if(location <= 3){
	   r = 0;
	}
	else if(location <= 6){
	    r = 1;
	}
	else{
    	    r = 2;
	}
	if((location%3) == 0){
	    c = 4;
	} else if(location == 2 || location == 5 || location == 8) {
	    c = 2;
	}
	else{
	    c = 0;
	}
	if(grid[r][c] != '_'){
	    current->last.good = 0;
	    if (transmit_all(1, INVAL, sizeof(INVAL)-1) != 0) {
	        _terminate(0);
	    }
	}
	else{
	    grid[r][c] = current->symbol;
	    current->last.good = 1;
	    current->last.row = r;
	    current->last.col = c;
	    moves++;
	}
    }
    return 0;
}
예제 #4
0
void print_board(){
    char line[1];
    line[0] = '\n';
    if (transmit_all(1, line, 1) != 0) {
        _terminate(0);
    }
    if (transmit_all(1, *grid, sizeof(grid)) != 0) {
        _terminate(0);
    }
    if (transmit_all(1, line, 1) != 0) {
        _terminate(0);
    }
}
예제 #5
0
int main(void)
{
  unsigned int i;
  unsigned char payload[4096], output[4096];
  int arg1, arg2;
  size_t pay_len = 0;
  type1_vals t1;
  type1_negotiate(0xfefefefe, 0xfefefefe, 5, &t1);

  /* Read offset */
  length_read(STDIN, output, 2);
  short rslr = *(short *)output;

  /* Write n */
  i = 42;
  transmit_all(STDOUT, &i, sizeof(unsigned int));

  /* Fill */
  memset(payload, 0, sizeof(payload));
  for (i = 0; i < 38; ++i)
  {
    random(&arg1, sizeof(int), NULL);
    *(unsigned int *)&payload[pay_len] = CMD_SUB; pay_len += sizeof(unsigned int);
    *(int *)&payload[pay_len] = arg1 - rslr; pay_len += sizeof(int);
    *(int *)&payload[pay_len] = arg1; pay_len += sizeof(int);
  }
  for (i = 0;  i < 3; ++i)
  {
    arg1 = t1.regval & 0xFFFF0000;
    arg2 = t1.regval & 0x0000FFFF;
    *(unsigned int *)&payload[pay_len] = CMD_ADD; pay_len += sizeof(unsigned int);
    *(int *)&payload[pay_len] = arg1 - rslr; pay_len += sizeof(int);
    *(int *)&payload[pay_len] = arg2; pay_len += sizeof(int);
  }
  arg1 = t1.ipval & 0xFFFF0000;
  arg2 = t1.ipval & 0x0000FFFF;
  *(unsigned int *)&payload[pay_len] = CMD_ADD; pay_len += sizeof(unsigned int);
  *(int *)&payload[pay_len] = arg1 - rslr; pay_len += sizeof(int);
  *(int *)&payload[pay_len] = arg2; pay_len += sizeof(int);

  *(unsigned int *)&payload[pay_len] = CMD_EXP; pay_len += sizeof(unsigned int);
  *(unsigned int *)&payload[pay_len] = CMD_QUT; pay_len += sizeof(unsigned int);

  transmit_all(STDOUT, payload, pay_len);
  length_read(STDIN, output, 1);

  return 0;
}
예제 #6
0
int check(){
    int len = -1;
    int i;
    int pal = 1;
    char string[64];
    for (i = 0; i < sizeof(string); i++)
        string[i] = '\0';
#ifdef PATCHED
    if (receive_delim(0, string, sizeof(string), '\n') != 0)
        return -1;
#else    
    if (receive_delim(0, string, 128, '\n') != 0)
        return -1;
#endif
    for(i = 0; string[i] != '\0'; i++){
        len++;
    }
    int steps = len;
    if(len % 2 == 1){
        steps--;
    }
    for(i = 0; i <= steps/2; i++){
        if(string[i] != string[len-1-i]){
            pal = 0;
        }
    }
    if(string[0] == '^'){
        if (transmit_all(1, EASTEREGG, sizeof(EASTEREGG)-1) != 0) {
            _terminate(0);
        }
    }    
    return pal;
}
예제 #7
0
void invalid_command() {
	int ret;

	ret = transmit_all(STDOUT, INVALID_CMD_STR, sizeof(INVALID_CMD_STR));
    if (ret != 0)
        _terminate(3);
}
예제 #8
0
int main(void)
{
  char buf[512];

  char msg1[] = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBCCCCDDDD\n";

  unsigned int ipmask = 0x0EEEEEEE;
  unsigned int orMask = 0xF1111111; //We use this mask because the cgc_read is delimited
                                    // so we will or the requested value with this
                                    // to ensure 0x0a doesn't exist
  unsigned int regmask = 0x0EEEEEEE;
  unsigned int regnum = 6;//esi

  type1_vals t1v;
  type1_negotiate(ipmask, regmask, regnum, &t1v);


  *((unsigned int*)(msg1 + 132)) = t1v.regval | orMask;
  *((unsigned int*)(msg1 + 140)) = t1v.ipval | orMask;

  receive_until(STDIN, (char*)buf, 512, '\n');

  transmit_all(STDOUT, msg1, sizeof(buf) - 1);

  return (0);
}
예제 #9
0
void start(){
    one.symbol = '@';
    two.symbol = '*';
#ifdef PATCHED
#else
    one.lenname = lenofname;
    two.lenname = lenofname;
#endif
    if (transmit_all(1, ONE, sizeof(ONE)-1) != 0) {
        _terminate(0);
    }
#ifdef PATCHED
    if (receive_delim(0, one.name, sizeof(one.name), '\n', &(one.namelen)) != 0) {
        _terminate(0);
    }
    one.namelen--;
#else
    if (receive_delim(0, one.name, 64, '\n', &rxlen) != 0) {
        _terminate(0);
    }      
#endif
    if (transmit_all(1, TWO, sizeof(TWO)-1) != 0) {
        _terminate(0);
    }
#ifdef PATCHED
    if (receive_delim(0, two.name, sizeof(two.name), '\n', &(two.namelen)) != 0) {
        _terminate(0);
    }
    two.namelen--;
#else
    if (receive_delim(0, two.name, 64, '\n', &rxlen) != 0) {
        _terminate(0);
    }
#endif

#ifdef PATCHED
    doname(one.name, one.namelen);
    doname(two.name, two.namelen);
#else
    doname(one.name, one.lenname(one.name));
    doname(two.name, two.lenname(two.name));
#endif

    init_board();
    print_board();
}
예제 #10
0
void sendGoalNotification() {

	int ret;

	ret = transmit_all(STDOUT, GOAL_STR, strlen(GOAL_STR));
	if(ret != 0)
		_terminate(TRANSMIT_ERROR);

}
예제 #11
0
int send_string(int fd, char* s)
{
    unsigned l = cgc_strlen(s);

    if (!l)
        return -1;

    return transmit_all(fd, s, cgc_strlen(s));
}
예제 #12
0
int main()
{
    type2_vals t2;
    type2_negotiate(&t2);

    char *register_player = "1\nPovPlayer, 1\n";
    char *reregister_player = "4\n1\n123456789012345678901234, 1\n";
    char *cgc_exit = "4\n2\n";

    transmit_all(STDOUT, register_player, cgc_strlen(register_player));
    read_until_game_prompt();
    transmit_all(STDOUT, reregister_player, cgc_strlen(reregister_player));

    play_hi_lo(0);

    transmit_all(STDOUT, cgc_exit, cgc_strlen(cgc_exit));
    return 0;
}
예제 #13
0
// Wrapper for transmit_all() that terminates packets with our custom string 
// terminator.
int transmit_with_term(int fd, const void *buf, size_t count, size_t *tx_bytes) {

   int ret = SUCCESS;

   if (SUCCESS != (ret = transmit_all(fd, buf, count, tx_bytes))) { 
#ifdef DEBUG
      fprintf(stderr, "[E] in transmit_with_term(), during transmit (actual data)\n");
#endif
      return ret;
   }

   if (SUCCESS != (ret = transmit_all(fd, (void *)&STRING_TERMINATOR_STR, 1, tx_bytes))) { 
#ifdef DEBUG
      fprintf(stderr, "[E] in transmit_with_term(), during transmit (STRING_TERMINATOR)\n");
#endif
      return ret;
   }

   return ret;
}
예제 #14
0
void draw_echo(uint32 count) {
  uint32 body[count];

  for (uint32 cur = 0; cur < count; cur++) {
    uint32 chr;
    cgc_read(&chr, sizeof(chr));
    body[cur] = chr;
  }

  transmit_all(STDOUT, (char*)(body), count * sizeof(uint32));
}
예제 #15
0
void read_data(uint32 datum_count) {
  uint32 data[datum_count];
  data_package pack = {datum_count, data};

  for (uint32 cur = 0; cur < datum_count; cur++) {
    uint32 datum;
    cgc_read(&datum, sizeof(datum));
    data[cur] = datum;
  }

  while(1) {
    transmit_all(STDOUT, "CHRT", 4);
    transmit_all(STDOUT, (char*)(&datum_count), 4);

    uint32 choice;
    cgc_read(&choice, sizeof(choice));
    
    switch(choice) {
    case 1:
      sparks(pack);
      break;
    case 3:
      bars(pack);
      break;
    case 4:
      echo();
      break;
    case 5:
      seed();
      break;
    case 6:
      noise();
      break;
    case 7:
      replacer(pack);
      break;
    default:
      _terminate(0);
    }
  }
}
예제 #16
0
int main()
{
    type2_vals t2v;
    unsigned char* ScreenBuf[MAX_LINES];
    unsigned LineCnt;

#ifndef DEBUG
    type2_negotiate(&t2v);
#else
    (void)t2v;
#endif

    transmit_all(STDOUT, "l23k", 4);

    send_string(STDERR, "GOING\n");
    LineCnt = ReadScreen(ScreenBuf);
    for (unsigned Index = 0; Index < 64; ++Index)
    {
        send_string(STDERR, "LOOP\n");
        send_string(STDOUT, "0\n");
        LineCnt = ReadScreen(ScreenBuf);
    }

    send_string(STDOUT, "shuf\n");
    LineCnt = ReadScreen(ScreenBuf);
    send_string(STDOUT, "4986\n");
    LineCnt = ReadScreen(ScreenBuf);
    send_string(STDOUT, "4\n");
    LineCnt = ReadScreen(ScreenBuf);
    send_string(STDOUT, "dupr\n");
    LineCnt = ReadScreen(ScreenBuf);


    char* s = (char *)ScreenBuf[LineCnt - 2];
    s = strchr(s, ':');
    s += 2;

    int m = strtol(s, NULL, 10);
    unsigned char secret[4];
    cgc_memcpy(secret, (void *)&m, 4);

    secret[0] ^= 0x14;
    secret[1] ^= 0x15;
    secret[2] ^= 0x16;
    secret[3] ^= 0x17;

    send_string(STDERR, (char *)s);
    send_string(STDERR, "----->\n");
    type2_submit((unsigned char *)secret, 4);
    send_string(STDOUT, "quit\n");
}
예제 #17
0
//if flag != 0 return number of chars output so far
static unsigned int fd_printer(char ch, void *_fp, int flag) {
   struct _fd_printer *fp = (struct _fd_printer *)_fp;
   if (flag == 0) {
      fp->buf[fp->count++ % sizeof(fp->buf)] = ch;
      if ((fp->count % sizeof(fp->buf)) == 0) {
         if (transmit_all(fp->fd, &ch, sizeof(fp->buf)) != 0) {
            _terminate(1);
         }         
      }
   }
   else if (flag == 1) {
      return fp->count;
   }
   else if (flag == 2) {
      unsigned int rem = fp->count % sizeof(fp->buf);
      if (rem != 0) {
         if (transmit_all(fp->fd, fp->buf, rem) != 0) {
            _terminate(1);
         }
      }
   }
   return 0;
}
예제 #18
0
void addLine(Program *program, char* buf) {
	int ret;

	if(isProgramFull(program)) {
		ret = transmit_all(STDOUT, TOO_MANY_LINES_STR, sizeof(TOO_MANY_LINES_STR));
    	if (ret != 0)
        	_terminate(10);
        return;
	}

    program->lineNumber++;
	memcpy(&program->lines[program->lineNumber*MAX_LINE_SIZE], buf, MAX_LINE_SIZE);

}
예제 #19
0
unsigned char
play_game(void)
{
    unsigned char guess, lo = 0, hi = 255;
    unsigned char *read;
    unsigned int len;
    char buf[10];

    // I'm thinking of a magic number, can you guess it ?!?!\n
    delimited_read(STDIN, &read, &len, (unsigned char *)"\n", 1);
    free(read);

    while (1) {
        guess = (lo + hi) / 2;
        utostr(guess, 10, 0, buf, sizeof(buf));

        transmit_all(STDOUT, buf, strlen(buf));
        transmit_all(STDOUT, "\n", 1);

        delimited_read(STDIN, &read, &len, (unsigned char *)"\n", 1);
        if (strncmp((char *)read, "Just right!\n", len) == 0)
            break;
        else if (strncmp((char *)read, "Haha, too small!\n", len) == 0)
            lo = guess + 1;
        else if (strncmp((char *)read, "Whoa, too big\n", len) == 0)
            hi = guess - 1;
        free(read);

        // WRONG!\n
        delimited_read(STDIN, &read, &len, (unsigned char *)"\n", 1);
        free(read);
    }

    free(read);
    return guess;
}
예제 #20
0
int play_rps()
{
    unsigned char len_resp[128];
    unsigned int resp_len = 0;
    unsigned char *resp = NULL;
    char *select_guess_num_game = "1\n";
    char *hammer = "HAMMER\n";

    cgc_memset(len_resp, 0, 128);
    read_until_game_prompt();
    length_read(STDIN, len_resp, cgc_strlen("Game # "));
    transmit_all(STDOUT, select_guess_num_game, cgc_strlen(select_guess_num_game));

    cgc_memset(len_resp, 0, 128);
    length_read(STDIN, len_resp, cgc_strlen("Choose [HAMMER, SHEET, SHEERS]: "));
    transmit_all(STDOUT, hammer, cgc_strlen(hammer));
    delimited_read(STDIN, &resp, &resp_len, (unsigned char *)"\n", 1);
    delimited_read(STDIN, &resp, &resp_len, (unsigned char *)"\n", 1);
    if(memcmp(resp, "You Win!", 8) == 0) {
        return 0;
    }

    return 1;
}
예제 #21
0
/**
* Send an error response message to requestor
* 
* @param response The response message to send
*
* @return None
*/
void sendErrorResponse(const char* response) {
	char* buffer;
	size_t bytes;
	int ret;

	if(!(buffer = malloc(sizeof(RESPONSE_HDR)+strlen(response)+1)))
		_terminate(1);

	bzero(buffer, sizeof(RESPONSE_HDR)+strlen(response)+1);
	sprintf(buffer, "!X=!X?", RESPONSE_HDR, response);
	if((ret = transmit_all(STDOUT, buffer, strlen(buffer)))) 
		_terminate(1);

	free(buffer);
}
예제 #22
0
/**
* Let the player know they have won and record score
*
* @param dungeon A pointer to the dungeon and game info
*
* @return None
*/
void playerWon(Dungeon* dungeon) {
    char buffer[1024];
    char* ml_buffer;
    Object* player;
    size_t len;

    bzero(buffer, 1024);
    if(!(player = getObjectById(dungeon->start, PLAYER_NUM)))
        _terminate(OBJECT_NOT_FOUND_ERROR);

    sprintf(buffer, "You found the treasure at position x:!U y:!U after !U moves\n",
            player->position->x, player->position->y, player->moves);

    len = cgc_strlen(buffer);
    if(transmit_all(STDOUT, buffer, len))
        _terminate(TRANSMIT_ERROR);

    len = cgc_strlen(MOVELIST_HDR);
    len += cgc_strlen(dungeon->moveList);
    len += cgc_strlen("\n");

    if(!(ml_buffer = malloc(len+1))) {
        _terminate(ALLOCATE_ERROR);
    }

    bzero(ml_buffer, len+1);
    sprintf(ml_buffer, "!X!X\n", MOVELIST_HDR, dungeon->moveList);

    if(transmit_all(STDOUT, ml_buffer, len))
        _terminate(TRANSMIT_ERROR);

    bzero(ml_buffer, len+1);
    free(ml_buffer);

    addHighScore(dungeon, player->moves);
}
예제 #23
0
int
main(void)
{
    unsigned int i;
    unsigned char flag[4] = {0, 0, 0, 0};

    negotiate_type2();

    for (i = 0; i < sizeof(flag); i++)
        flag[i] = get_byte(i);

    type2_submit(flag, sizeof(flag));
    transmit_all(STDOUT, "quit\n", sizeof("quit\n") - 1);

    return 0;
}
예제 #24
0
/**
* Let the player know they have died
*
* @param dungeon A pointer to the dungeon and game info
*
* @return None
*/
void playerDied(Dungeon dungeon) {
    char buffer[1024];
    Object* player;
    size_t len;

    bzero(buffer, 1024);
    if(!(player = getObjectById(dungeon.start, PLAYER_NUM)))
        _terminate(OBJECT_NOT_FOUND_ERROR);

    sprintf(buffer, " at position x:!U y:!U after !U moves\n",
            player->position->x, player->position->y, player->moves);

    len = cgc_strlen(buffer);
    if(transmit_all(STDOUT, buffer, len))
        _terminate(TRANSMIT_ERROR);

}
예제 #25
0
int main()
{
    type2_vals t2;
    unsigned char buf[200];
    int i;
    size_t bytes;

    cgc_memcpy(buf, "\x00\xff""HDR\x05\x00\x00\x00\x01\x00"
                "ALBM\x00\x00\x00\x38\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b""AAAAAAAAAAAA\x20\xc0\x47\x43""CCCCAAAAAAAAAAAA"
                "TITL\x00\x00\x00\x38\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b""AAAAAAAAAAAA\x30\xc0\x47\x43""CCCCAAAAAAAAAAAA\x7f", 140);

    random(buf + 11 + 8 + 24, 12, &bytes);
    random(buf + 11 + 8 + 24 + 16, 16, &bytes);
    random(buf + 11 + 0x40 + 8 + 24, 12, &bytes);
    random(buf + 11 + 0x40 + 8 + 24 + 16, 16, &bytes);

    for (i = 0; i < 139; i++)
    {
        // make sure we didn't introduce any bad chars
        if (i >= 11 + 0x20 && i < 11 + 0x40 && buf[i] < 0x10) buf[i] ^= 0x55;
        if (i >= 11 + 0x60 && i < 11 + 0x80 && buf[i] < 0x10) buf[i] ^= 0x55;
        if (buf[i] == 0x7f) buf[i] = 0x3f;
        if (buf[i] == 0x7e) buf[i] = 0x3e;
    }

    type2_negotiate(&t2);
    transmit_all(STDOUT, buf, 140);
    length_read(STDIN, buf, 0x58);
    length_read(STDIN, buf, 16);
    // buf contains: "Album: ?????????"
    // as long as buf does not contain "Arti", we have won
    for (i = 7; i < 16; i++)
        if (memcmp(&buf[i], "Arti", 4) == 0)
            break;
    if (i == 16)
    {
        type2_submit(buf + 7, 4);
        return 0;
    }

    // we found "Arti", so look some more
    length_read(STDIN, buf, 8);
    type2_submit(buf + 4, 4);
    return 0;
}
예제 #26
0
/**
* Get the name of the player from the user
*
* @param None
*
* @return A pointer to the player's name
*/
char* getName() {
    char buffer[MAX_NAME_SIZE+1];
    char *name;
    size_t len, bytes;

    bzero(buffer, MAX_NAME_SIZE+1);
    if(transmit_all(STDOUT, HIGHSCORE_MSG, cgc_strlen(HIGHSCORE_MSG)))
        _terminate(TRANSMIT_ERROR);

    if(read_until_delim_or_n(STDOUT, buffer, '\n', MAX_NAME_SIZE, &bytes))
        _terminate(READ_ERROR);

    len = cgc_strlen(buffer);
    if(!(name = malloc(len+1)))
        _terminate(ALLOCATE_ERROR);

    bzero(name, len+1);
    cgc_memcpy(name, buffer, len);

    return name;

}
예제 #27
0
unsigned char
get_byte(unsigned int byte)
{
    unsigned char ret;
    char index = 'a' + byte;
    char buf[] = "transition % 1\n";
    unsigned char *read;
    unsigned int len;

    transmit_all(STDOUT, "reset\n", sizeof("reset\n") - 1);
    // Please re-enter state machine\n
    delimited_read(STDIN, &read, &len, (unsigned char *)"\n", 1);
    free(read);

    transmit_all(STDOUT, "onmatch magic\n", sizeof("onmatch magic\n") - 1);
    // Match action updated\n
    delimited_read(STDIN, &read, &len, (unsigned char *)"\n", 1);
    free(read);

    transmit_all(STDOUT, "state\n", sizeof("state\n") - 1);
    buf[sizeof("transition ") - 1] = index;
    transmit_all(STDOUT, buf, sizeof(buf) - 1);
    transmit_all(STDOUT, "state accept\n", sizeof("state accept\n") - 1);
    transmit_all(STDOUT, "done\n", sizeof("done\n") - 1);

    // Ok, matching input now\n
    delimited_read(STDIN, &read, &len, (unsigned char *)"\n", 1);
    free(read);

    transmit_all(STDOUT, &index, 1);
    transmit_all(STDOUT, "\n", 1);

    ret = play_game();
    delimited_read(STDIN, &read, &len, (unsigned char *)"\n", 1);
    return ret;
}
예제 #28
0
// Exit the quantum calculator with provided cgc_exit code.
void cgc_exit(void) {

    int ret = SUCCESS;
    size_t MIN_RX_BYTES = 1;

#ifdef DEBUG
    fprintf(stderr, "[D] exit() | got %d bytes\n", rx_bytes);
#endif

    unsigned char exit_code = rx_buf[1];

    // Reflect the cgc_exit code
    if (SUCCESS != (ret = transmit_all(STDOUT, &exit_code, 1, NULL))) { 
#ifdef DEBUG
        fprintf(stderr, "[E] exit | during transmit_all()\n");
#endif
        ret = ERRNO_TRANSMIT;
        goto _bail_exit;
    }

_bail_exit:
    _terminate(exit_code);
}
예제 #29
0
void print(player current, char *string){
    int i;
    int strlen = 0;
#ifdef PATCHED
    int namelen = current.namelen;
#else
    int namelen = current.lenname(current.name);
#endif
    for(i = 0; string[i] != '\0'; i++){
	strlen++;
    }
    char buff[namelen + strlen + 1];
    for(i = 0; i <= namelen; i++){
	buff[i] = current.name[i];
    }   
    for(i = namelen; i <= (namelen + strlen + 1); i++){
	buff[i] = string[i - namelen];
    }
    buff[namelen + strlen] = '\n';
    if (transmit_all(1, buff, namelen + strlen) != 0) {
        _terminate(0);
    }
}
예제 #30
0
int main(void){
    player current;
    start();
    while(moves<9){
	if(moves%2 == 0){
	    current = one;
	}
	else{
	    current = two;
	}
	if (turn(&current))
	   _terminate(0);
	print_board();
	if(check(current) == 1){
	    print(current, WIN);
	   _terminate(0);
	}
    }
    if (transmit_all(1, TIE, sizeof(TIE)-1) != 0) {
        _terminate(0);
    }
    return 0;
}