Пример #1
0
void timeStep() {
    time_step += 1;
    addFood();
    moveBugs();
    killDeadBugs();
    reproduceBugs();
    percent_straight = 100 * total_straight / bug_list.size() / GENE_TOTAL;
    percent_left = 100 * total_left / bug_list.size() / GENE_TOTAL;
    percent_right = 100 * total_right / bug_list.size() / GENE_TOTAL;
    percent_back = 100 * total_back / bug_list.size() / GENE_TOTAL;
}	
Пример #2
0
/* Makes sure bugs eat the food they move on top of */
TEST(MovementTests, EatingTest)
{
    bug_list.clear();
    bug_list.push_back(initBug(0, 0, 2));
    initWorld();

    world[0][1] = FOOD;
    moveBugs();

    ASSERT_EQ(world[0][1], 0);
    ASSERT_EQ(bug_list.size(), 1);
    ASSERT_EQ(bug_list[0].health, START_HEALTH + EAT_HEALTH - MOVE_HEALTH);
}
Пример #3
0
TEST(BugKillingTests, SimpleBugKillingTest)
{
    bug_list.clear();
    bug_list.push_back(initBug(0, 0, 2, MOVE_HEALTH));
    bug_list.push_back(initBug(0, 0, 4, MOVE_HEALTH * 2));
    initWorld();

    moveBugs();
    killDeadBugs();

    ASSERT_EQ(bug_list.size(), 1);
    ASSERT_EQ(world[0][0], EMPTY);
    ASSERT_EQ(world[0][1], EMPTY);
    ASSERT_EQ(world[1][0], 0);
}
Пример #4
0
TEST(BugKillingTests, NoSkipBugKillingTest) {
	bug_list.clear();
	bug_list.push_back(initBug(0, 0, NORTH, MOVE_HEALTH));
	bug_list.push_back(initBug(0, 0, SOUTH, MOVE_HEALTH));
	bug_list.push_back(initBug(0, 0, WEST, MOVE_HEALTH * 2));
	initWorld();

	moveBugs();
	killDeadBugs();

	ASSERT_EQ(bug_list.size(), 1);
	ASSERT_EQ(world[0][0], EMPTY);
	ASSERT_EQ(world[WORLD_SIZE-1][0], EMPTY);
	ASSERT_EQ(world[1][0], EMPTY);
	ASSERT_EQ(world[0][WORLD_SIZE-1], 0);
}
Пример #5
0
TEST(BugKillingTests, RemoveLastBugIfDead) {
	bug_list.clear();
	bug_list.push_back(initBug(0, 0, EAST, 0));
	bug_list.push_back(initBug(0, 1, EAST, MOVE_HEALTH * 3));
	bug_list.push_back(initBug(0, 2, EAST, MOVE_HEALTH * 3));
	bug_list.push_back(initBug(0, 3, EAST, 0));
	initWorld();

	moveBugs();
	killDeadBugs();

	ASSERT_EQ(bug_list.size(), 2);
	ASSERT_EQ(world[0][1], EMPTY);
	ASSERT_GE(world[0][2], 0);
	ASSERT_GE(world[0][3], 0);
	ASSERT_EQ(world[0][4], EMPTY);
}
Пример #6
0
/* Makes sure bugs move properly in all directions */
TEST(MovementTests, SimpleMovementTest)
{
    bug_list.clear();

    for (int i = 0; i < 8; i++)
    {
        Bug b = initBug(0, 0, i);
        bug_list.push_back(b);
    }
    initWorld();

    moveBugs();
    ASSERT_EQ(bug_list.size(), 8);
    ASSERT_EQ(world[0][0], EMPTY);

    int i = 0;
    for (auto &bug : bug_list)
    {
        ASSERT_EQ(bug.x, newX(0, i));
        ASSERT_EQ(bug.y, newY(0, i));
        ASSERT_EQ(world[bug.x][bug.y], i++);
    }
}
Пример #7
0
/* Makes sure bugs update their direction properly for all directions */
TEST(MovementTests, SimpleDirectionTest)
{
    bug_list.clear();

    for (int i = 0; i < 8; i++)
    {
        Bug b = initBug(0, 0, 0);
        memset(b.genes, 0, ARRAYSIZE(b.genes));
        b.genes[i] = GENE_TOTAL;

        bug_list.push_back(b);
    }
    initWorld();

    moveBugs();
    ASSERT_EQ(bug_list.size(), 8);

    // Each bug's direction should now be i
    int i = 0;
    for (auto &bug : bug_list)
    {
        ASSERT_EQ(bug.dir, i++);
    }
}