示例#1
0
文件: winper.c 项目: andybug/elocfb
void algo_winper(void)
{
	struct team *t1, *t2;
	struct result *result;
	int i;

	for (i = 0; i < num_results; i++) {
		result = results + i;

		t1 = find_team(&team_map, result->home_key);
		t2 = find_team(&team_map, result->away_key);

		if (result->home_pts > result->away_pts) {
			if (t1)
				t1->wins++;

			if (t2)
				t2->losses++;
		} else {
			if (t1)
				t1->losses++;

			if (t2)
				t2->wins++;
		}
	}

	for (i = 0; i < num_teams; i++)
		teams[i].winper = (float)teams[i].wins /
		                  (teams[i].wins + teams[i].losses);
}
示例#2
0
文件: elo.c 项目: andybug/elocfb
void algo_elo(void)
{
	int i;
	struct team *t1, *t2;
	double exp1, exp2;
	double t1win, t2win;

	seed_elo();

	for (i = 0; i < num_results; i++) {
		t1 = find_team(&team_map, results[i].home_key);
		t2 = find_team(&team_map, results[i].away_key);

		if (!t1 || !t2)
			continue;

		exp1 = 1.0 / (1.0 + pow(10, (t2->elo - t1->elo) / 400.0));
		exp2 = 1.0 / (1.0 + pow(10, (t1->elo - t2->elo) / 400.0));

		if (results[i].home_pts > results[i].away_pts) {
			t1win = 1.0;
			t2win = 0.0;
		} else {
			t1win = 0.0;
			t2win = 1.0;
		}

		t1->elo += (short)(ELO_KFACTOR * (t1win - exp1));
		t2->elo += (short)(ELO_KFACTOR * (t2win - exp2));
	}
}
示例#3
0
文件: team.c 项目: jsthibault/Zappy
t_bool		init_team(t_kernel *kernel)
{
    size_t	i;

    if (!(kernel->game.teams = list_create()))
        return (FALSE);
    for (i = 0; i < kernel->options.nb_team_names; i++)
    {
        if (!find_team(kernel, kernel->options.team_names[i]))
        {
            if (FALSE == add_team(kernel, kernel->options.team_names[i]))
                return (FALSE);
        }
        else
            logger_warning("{TEAM} %s already exists");
    }
    return (TRUE);
}
示例#4
0
int main(void)
{
    int sd, newSd;              //Socket descriptors sd is the one main listens on newSd is the one clients gets.
    struct sockaddr_in cliAddr; //Information about the client
    socklen_t cliLen;           //
    char buffer[32];

    pthread_t server_db_print;  //Debug print thread information
    pthread_t bullet_hit;
    struct client clientInfo[MAX_PLAYERS];  // Where all necessary information about the client is stored
    
    int clientSlot;             // Stores in slot the new connection is going to get 
    
    int i;
    
    load_map_collision_array();
    
    // Init tcp
    sd = tcp_init();
    if (sd == -1)
    {
        return ERROR;           // Exits if error
    }

    //Cleares the Clients structs and makes it ready for use.
    for (i = 0; i < MAX_PLAYERS; i++)
    {
        clear_client_struct(&clientInfo[i]);
    }
    redpoints = 0;
    bluepoints = 0;
    
    //Starts the debug print thread
    pthread_create(&server_db_print,NULL,debeugger_print_thread,clientInfo);
    
    pthread_create(&bullet_hit,NULL,bullet_hit_thread,clientInfo);

    
    while (1)
    {
        cliLen = sizeof(cliAddr);
        newSd = accept(sd, (struct sockaddr *) &cliAddr, &cliLen);
        
        if (newSd == -1)
        {
            perror("accept");
            continue;
        }
        
        //Finds the first free slot
        clientSlot = find_free_slot(clientInfo, MAX_PLAYERS);
                
        if(clientSlot==-1)
        {
            send(newSd,"No free slots, try again later!\n", sizeof("No free slots, try again later!\n"), 0);
            close(newSd); // Close the socket descriptor to indicate to client that
            continue;     // we have no more space for it. Then goto beginning of loop.
        }
        
        clientInfo[clientSlot].free = 1;            // Sets the client slot so it is taken
        clientInfo[clientSlot].sd = newSd;          // Gives the slot the socket descriptor
        clientInfo[clientSlot].mySlot = clientSlot; // Gives the Slot number 
        clientInfo[clientSlot].team = find_team(clientInfo, MAX_PLAYERS);  //Finds a team and givs in to the client
        
        // Gets the clients ip address and stores it
        inet_ntop(cliAddr.sin_family, &cliAddr.sin_addr, clientInfo[clientSlot].client_ip_addr, sizeof (clientInfo[clientSlot].client_ip_addr));
        
        sprintf(buffer, "%d", clientSlot);
        send(newSd, buffer, sizeof(buffer), 0);
        
        //Main thread for the connected client, Main programm will continue serv new connections
        pthread_create( &clientInfo[clientSlot].threadId, NULL, client_handler_function, &(clientInfo[clientSlot]));        
    }

    //This will never happen unless we quit the programm
    
    
    pthread_cancel(server_db_print);
    pthread_cancel(bullet_hit);
    // Will never happen
    close(sd);

    return 0;
}