Ejemplo n.º 1
0
//matching making, dequeue first two elements of playerlist
int matchmaking(struct queue_list *playerlist, struct queue_list *battlelist)
{
	struct battle *b;
	struct node *p1 = playerlist->front;
	struct player *c1 = p1->content;
	struct node *temp = playerlist->front->next;
	struct player *c2 = temp->content;

	
	if (!p1 || !temp)
	{
		printf("Not enough player!\n");
		return -1;
	}

	while ((c1->prev_id == c2->prev_id) && temp)
	{

		temp = temp->next;
		c2 = temp->content;
	}
    
    if (!temp)
	{
		printf("Cannot find match\n");
		return -1;
	}

	b = createcombat(c1, c2);
	enqueue_list(battlelist, b);
	dequeue_list(playerlist, p1);
	remove_ele(playerlist, temp)
	return 1;

}
Ejemplo n.º 2
0
/*=================================
 * fix_nodes -- Fix all nodes on fix list
 *  (uses list from check_nodes)
 *================================*/
static void
fix_nodes (void)
{
    if (!tofix) return;
    while (!is_empty_list(tofix)) {
        STRING key = dequeue_list(tofix);
        RECORD rec = key_to_record(key);
        strfree(&key);
        lock_record_in_cache(rec);
        process_record(rec);
        unlock_record_from_cache(rec);
    }
}
Ejemplo n.º 3
0
/*==========================================
 * check_ghosts -- Process all names & refns
 *  checking (& optionally fixing) ghosts
 * Created: 2001/01/01, Perry Rapp
 *=========================================*/
static void
check_ghosts (void)
{
    tofix = create_list();
    soundexseq = create_indiseq_sval();
    /* soundexseq is used inside cgn_callback, across calls */
    traverse_names(cgn_callback, NULL);
    finish_and_delete_nameset();

    if (todo.fix_ghosts) {
        NAMEREFN_REC * rec;
        while (!is_empty_list(tofix)) {
            rec = (NAMEREFN_REC *) dequeue_list(tofix);
            remove_name(rec->namerefn, rec->key);
            ++errs[rec->err].fix_count;
            free_namerefn(rec);
        }
    }

    ASSERT(is_empty_list(tofix));
    ASSERT(!soundexseq);

    soundexseq = create_indiseq_sval();
    /* soundexseq is used inside cgr_callback, across calls */
    traverse_refns(cgr_callback, NULL);
    finish_and_delete_refnset();

    if (todo.fix_ghosts) {
        NAMEREFN_REC * rec;
        while (!is_empty_list(tofix)) {
            rec = (NAMEREFN_REC *) dequeue_list(tofix);
            remove_refn(rec->namerefn, rec->key);
            free_namerefn(rec);
        }
    }

    destroy_list(tofix);
    tofix=0;
}