Пример #1
0
// Generates the AI attack and places in the human's game board
int ai_make_move(void) {
	int attack_index = NONE;
	
	//check if this is our first move
	if(last_attack == NONE && last_hit == NONE) {
		//it's our first move, so pick a random index to attack
		attack_index = get_random_index();
	}
	else {
		//it's not our first move, check to see if we have gotten a last hit
		//use a counter to check cardinal directions
		if(last_hit && (locality_count < 4)) {
			switch(locality_count) {
				case 0:	attack_index = get_index(last_hit, 0, player2);
						break;
				case 1:	attack_index = get_index(last_hit, 1, player2);
						break;
				case 2:	attack_index = get_index(last_hit, 2, player2);
						break;
				case 3: attack_index = get_index(last_hit, 3, player2);
						break;
				default: printf("Invalid direction\n");
			}
		}
		else {
			attack_index = get_random_index();
		}
	}
	if(attack_index == NONE)
		attack_index = get_random_index();
	last_attack = attack_index;
	ai_make_attack(attack_index);
	return attack_index;
}
Пример #2
0
double approximate_clustering_coefficient(sfn_t const *const sfn,
        int const num_samples)
{
    sfn_anim("F\n");

    double cc = 0.0;

    for (int k = 0; k < num_samples; ++k)
    {
        sfn_node_t const *const i =
                &sfn->nodes[get_random_index(sfn->num_nodes - 1)];

        if (i->degree < 2)
        {
            continue;
        }

        sfn_node_t const *const j =
            i->neighbours[get_random_index(i->degree - 1)];

        sfn_node_t const *n;

        do
        {
            n = i->neighbours[get_random_index(i->degree - 1)];
        } while (j->id == n->id);

        if (sfn->adjacency[j->id * sfn->max_nodes + n->id])
        {
            cc += 1.0;
            sfn_anim("C %zu green\nC %zu green\nC %zu green\n",
                    i->id, j->id, n->id);
            sfn_anim("E %zu %zu green\nE %zu %zu green\nE %zu %zu green\nF\n",
                    i->id, j->id, i->id, n->id, j->id, n->id);
            sfn_anim("C %zu white\nC %zu white\nC %zu white\n",
                    i->id, j->id, n->id);
            sfn_anim("E %zu %zu black\nE %zu %zu black\nE %zu %zu black\n",
                    i->id, j->id, i->id, n->id, j->id, n->id);
        }
        else
        {
            sfn_anim("C %zu red\nC %zu red\nC %zu red\n",
                    i->id, j->id, n->id);
            sfn_anim("E %zu %zu red\nE %zu %zu red\nF\n",
                    i->id, j->id, i->id, n->id);
            sfn_anim("C %zu white\nC %zu white\nC %zu white\n",
                    i->id, j->id, n->id);
            sfn_anim("E %zu %zu black\nE %zu %zu black\n",
                    i->id, j->id, i->id, n->id);
        }
    }

    return cc / (double)num_samples;
}