Ejemplo n.º 1
0
	bool Request::perform() noexcept
	{
		if (this->handle == nullptr) return false;
		auto is_performed = check_code(curl_easy_perform(this->handle));
		if (!is_performed) return false;
		long http_code = 0;
		curl_easy_getinfo(this->handle, CURLINFO_RESPONSE_CODE, &http_code);
		if (http_code < 200 || http_code > 299) return false;
		return true;
	}
Ejemplo n.º 2
0
Uint8 self_check(){
    
    if(check_code()!=E_OK)
        return E_ERR;
    if(check_rom()!=E_OK)
        return E_ERR;
    if(check_ram()!=E_OK)
        return E_ERR;
    if(check_eeprom()!=E_OK)
        return E_ERR;
    if(check_ad()!=E_OK)
        return E_ERR;
    return E_OK;
}
Ejemplo n.º 3
0
// read sended data by server method
uint32_t data_read(uint32_t buf, int buf_len, int data_num) {
	buf = ntohl(buf);
	/*
	char split[5];
	buf = ntohl(buf);
	int i, j;
	for(i = 0; i < ELEM; i++) {
		for(j = 0; j < BASE; j++) {
			split[j] = buf;
		}
		split[4] = '\0';
		//get_data[i] = split;
	}
	*/
	check_code();
	return buf;
}
Ejemplo n.º 4
0
 nmethod* volatile code() const                 { assert( check_code(), "" ); return (nmethod *)OrderAccess::load_ptr_acquire(&_code); }
Ejemplo n.º 5
0
int do_game(){
  int c, x, y, r, player, turn;
  char code[6], prev_code[6];

  // ------------------------------------------------------------
  // start!
   
  show_board();

  player = first_player;
  turn = 0;
  prev_code[0] = 0;

  while(prompt(player, code, prev_code, 
	       !check_possibility(player, turn), turn)){
    move m;
    int e, x_offset, y_offset;
    if(code[0] == 0) return TERMINATE_WRONG;  // ctrl+d

    // retry if invalid code
    while(!check_code(code)){
      if(interactive(player)){
	prompt(player, code, prev_code, FALSE, turn);
      } else {
	printf("Invalid move on serial port.\n");
	return player;
      }
      if(code[0] == 0) return TERMINATE_WRONG;
    }
    if(code[0] == 0) return TERMINATE_WRONG;  // ctrl+d
    if(prev_code[0] == 0) strcpy(p1move1, code);
    if(strcmp(prev_code, "0000") == 0 &&
       strcmp(code,      "0000") == 0){
      printf("Both pass!\n");

      show_hint = FALSE;

      if(! (check_possibility(player, turn) ||
	    check_possibility(next_player(player), turn-1))){
	return TERMINATE_NORMAL;
      }
      return TERMINATE_NORMAL; // is this OK?
    }

    strcpy(prev_code, code);

    // pass
    if(strcmp(code, "0000") == 0){
      if(turn >= 2){
	player = next_player(player);
	turn++;
	continue;
      } else {
	printf("First move must not be a pass.\n");
	return player;
      }
    }

    m = decode_code(code);

    c = m.piece;
    r = m.rotate;
    x_offset = m.x-2;
    y_offset = m.y-2;
    

    if((e = check_move(player, turn, m)) != 0){
      show_error(e);
      return player; 
    }
  
    // OK, now place the move
    for(y=0; y<5; y++){
      for(x=0; x<5; x++){
        int b;
        b = pieces[c][0][rotate[r][y][x]];
        if (b==1)
          board[y_offset+y][x_offset+x] = player;
      }
    }
    available[player-1][c] = 0;

    if(remaining_size(player)==0){
      printf("Player %d won the game, since the player has no more pieces.\n",
	     player);
      return TERMINATE_NORMAL;
    }
  
    // show the board & next player
    show_board();
    player = next_player(player);
    turn++;
  }

  printf("Player %d timed out.\n", player);
  return player;
}
Ejemplo n.º 6
0
int main(int argc, char const* argv[]) {


	int sock, error;
	uint32_t get_data;
	uint32_t stock_data[ELEM];
	uint32_t default_data[ELEM];

	char host[16];
	char port[16];
	strcpy(host, argv[1]);
	strcpy(port, argv[2]);

	sock = makesock(port);
	printf("sock : %d\n", sock);

	int i;

	// game start
	while(true) {
		get_data = getData(&sock, stock_data);
		if(stock_data[1] == LIST) {
			printf("can connect to game.\n");
			break;
		}
	}

	bool list_flag = false;
	uint32_t math;
	uint32_t buy_id;
	uint32_t code = stock_data[1];
	uint32_t value;
	uint32_t key = stock_data[0];
	int turn = 0;
	uint32_t budget = 10000;

	// company and my_stock
	uint32_t my_stock[COMPANY];
	struct Company company[COMPANY];
	struct Company tmp_company[COMPANY];
	int j;
	for(j = 0; j < COMPANY; j++) {
		my_stock[j] = 0;
		default_data[j] = stock_data[j];
		company[j].id = j;
		company[j].price = stock_data[3+j*2];
		company[j].ave = stock_data[3+j*2];
		company[j].pattern = 0;
		company[j].prev_pattern = 0;
	}
	print_company_info(company);

	printf("\n");
	printf("game start.\n");
	printf("begin *** budget: %u, key: %u, code: %x\n", budget, key, stock_data[1]);

	int read_len;
	uint32_t tmp_data[ELEM];
	int s;
	bool is_minus = true;
	bool is_math = true;

	// doing game
	for(s = 0; s < TURNS; s++) {

		int a;
		read_len = -1;
		turn++;
		int n = 0;

		//list_flag = true;
		printf("\n ====== begin turn %d. before request. ======\n", s+1);
		for(i = 0; i < 5; i++) {
			
			if(key == 0 && code == END) {
				printf("my_lank is ....... %u\n", tmp_data[2]);
				exit(-1);
				break;
			}



			bool check_flag = false;

			if(turn == 1) {
				math = 10;
				buy_id = i;
				code = PURCHASE;
				check_flag = true;
			} else if(turn >= 59) {
					math = my_stock[i+n];
					buy_id = i+n;
					code = SALE;
					check_flag = true;
					n = 5;
			} else {
				int c;
				uint32_t m;
				for(c = n; c < COMPANY; c++) {
					
					m = 100;
					if(company[i].pattern < company[i].prev_pattern) {
						while(m <= 0) {
							if(is_minus_budget(budget, value, m) == true) {
								break;
							}
							m--;
						}
						if(m == 0) {
							continue;
						}
						math = m;
						buy_id = i;
						code = PURCHASE;
						check_flag = true;
						n = c;
						printf("buy check: company_id: %u, math: %u\n", buy_id, math);
						break;
					}
					if(company[i].pattern > company[i].prev_pattern) {
						math = my_stock[i];
						buy_id = i;
						code = SALE;
						check_flag = true;
						n = c;
						printf("sale check: company_id: %u, math: %u\n", buy_id, math);
						break;
					}
				}
			}

			if(check_flag == false) {
				continue;
			}

		
			request(&sock, &key, &math, &buy_id, &code);
			int l = getData(&sock, tmp_data);
			check_code(&tmp_data[1]);
			value = company[buy_id].price;
			if(tmp_data[1] != ACCEPT) {
				printf("\nnot accepted request.\n");
			} else {
				printf("\naccepted request.\n");
				status(&budget, my_stock, &turn, &buy_id, &code, &math, &value);
				//status(&budget, my_stock, &turn, &math, &buy_id, &code, &value);
			}
		}

		printf("\n ------- stayng ------\n");

		//while(list_flag == true) {
		while(1) {

			read_len = getData(&sock, tmp_data);
			check_code(&tmp_data[1]);
			code = tmp_data[1];
			if(code == ACCEPT || code == ERR_CODE || code == ERR_KEY || code == ERR_REQ || code == ERR_ID || code == ERR_PUR || code == ERR_SAL) {
				continue;
			}
			if(code != LIST) {
				continue;
			} else {
				dump_data(tmp_data);
				key = tmp_data[0];
				code = tmp_data[1];
				set_company_info(tmp_data, company, &turn);
				print_company_info(company);
				//list_flag = false;
				break;
			}
		}
		
		// read list
		printf("result -> budget: %u, turn: %d, key: %u, code: %x\n", budget, turn, tmp_data[0], tmp_data[1]);
		printf("turn %d end\n", s + 1);
	}
	
	return 0;
}
Ejemplo n.º 7
0
	bool
	Request::set(CURLoption option, struct curl_slist * value) noexcept
	{
		if (this->handle == nullptr) return false;
		return check_code(curl_easy_setopt(this->handle, option, value));
	}