Beispiel #1
0
void
vex_adx_server::process_d_sub(int conn_idx, const d_sub &req)
{
    // Update auction context
    auction_context *ctx = &(auctions_ctx_.at(req.id));
    assert(ctx);

    ctx->vds.insert(std::pair<int, vex_decommitment>(conn_idx, req.vd));

    // When full, check consistency, compute auction, and report_outcome(ctx)
    if (ctx->vds.size() == conn_.size() - 1) {


#ifndef NOCC
        // currently NOT using optimized approach
        // To switch: replaces with consistency_and_proof(ctx);
        // and put compute_auction before.
        if (!consistency_check(ctx)) {
//    ctx->outcome = compute_auction(ctx);
            fatal << "Consistency check failed...\n";
        }
#endif
        ctx->outcome = compute_auction(ctx);
        report_outcome(ctx);
    }
}
Beispiel #2
0
void play_against_human(JDict *reference)
{
    int c_hits;
    JDict *jdict = jdict_initialize(reference->length);
    char *c_word = jdict_random_word(reference);
    JottoStatus *status = malloc(sizeof(JottoStatus));
    JottoGuess *hjg = malloc(sizeof(JottoGuess));
    JottoGuess *cjg = malloc(sizeof(JottoGuess));

    status->value = JOTTO_NO_RESULT;

    while (status->value == JOTTO_NO_RESULT) {
	printf("Your guess: ");
    
	humans_turn(hjg, c_word, reference);
	pretty_print_guess(hjg, JOTTO_HUMAN_OFFSET);

	if (hjg->hits == 5) {
	    printf("I get one more guess.\n");
	    status->value |= JOTTO_HUMAN_WON;
	}

	if (jdict->length == 0) {
	    printf("There are no words left.\n");
	    status->value |= JOTTO_COMPUTER_WON;
	}
	else {
	    strncpy(cjg->guess, jdict_random_word(jdict), 6);
	    printf("My guess: %s ", cjg->guess);
	    get_hits_from_human(&cjg->hits);
	    pretty_print_guess(cjg, JOTTO_COMPUTER_OFFSET);
      
	    if (cjg->hits == 5) {
		status->value |= JOTTO_COMPUTER_WON;
	    }
	    else {
		jdict_winnow(jdict, cjg->guess, cjg->hits);
	    }
	}
    }
    report_outcome(status, c_word);
    printf("%s", status->message);
    free(status);
    free(hjg);
    free(cjg);
    jdict_free(jdict);
}
Beispiel #3
0
// Handle a bid submission
void
adx_server::process_b_sub(int conn_idx, const b_sub &sub)
{
  // Update auction context
  auction_context *ctx = &(auctions_ctx_.at(sub.id));
  assert(ctx);

  ctx->bids.insert(std::pair<int, uint32_t>(conn_idx, sub.bid));
  ctx->ad_tags.insert(std::pair<int, std::string>(conn_idx, sub.ad_tag));
  
//  std::cout << "New bid for " << sub.id << ": " << sub.bid << "\n";

  if (ctx->bids.size() == conn_.size() - 1) {
    ctx->outcome = compute_auction(ctx);
    report_outcome(ctx);
  }
}