Esempio n. 1
0
    // Breed new Organisms
    void isBreeding(const int& breedType, const Point& point){
        int randomNum;
        bool checks[4] = { false };

        while(checks[0] == false || checks[1] == false || checks[2] == false || checks[3] == false){                                // Loops till it breeds
            randomNum = generate() % 4;

            while(checks[randomNum] && (checks[0] == false || checks[1] == false || checks[2] == false || checks[3] == false))      // Loops till it find Number that was not selected before
                randomNum = generate() % 4;

            Point tempPoint = getOneSidePoint(breedType, point, randomNum);                                                         // Gets the new point for the Organism to spawn in

            if(checkMovementIsValid(breedType, tempPoint)){                                                                         // If location is valid, spawn Organism to new location
                if(breedType == 1 && gameboard(tempPoint.getX(), tempPoint.getY()) == 2)                                            // Remove Ant if Doodlebug spawns on same location
                    GameFunctions::removeFromList(2, tempPoint);

                if(breedType == 1)                                                                                                  // Adds new Doodlebug/Ant to list
                    doodlebug_Population.push_back(Doodlebug(new Point(tempPoint), new SeekAnt()));
                else if(breedType == 2)
                    ant_Population.push_back(Ant(new Point(tempPoint), new MoveRandom()));

                gameboard(tempPoint.getX(), tempPoint.getY(), breedType);                                                           // Set Organism on Grid
                break;
            }
            else
                checks[randomNum] = true;                                                                                           // Flag number if location is invalid
        }
    }
Esempio n. 2
0
    // Spawn Organism into empty blocks
    void spawnInOrganisms(const int& amountDoodlebug, const int& amountAnts){
        for(int i = 0; i < amountDoodlebug; i++){                                                   // Generate Doodlebugs in empty blocks
            int xTemp, yTemp;

            do{                                                                                     // Loops until an empty block is found
                xTemp = (generate() % gameboard.getGrid_X());
                yTemp = (generate() % gameboard.getGrid_Y());
            }while(gameboard.getGridBlock(xTemp, yTemp) != 0);

            gameboard(xTemp, yTemp, 1);

            doodlebug_Population.push_back(Doodlebug(new Point(xTemp, yTemp), new SeekAnt()));
        }

        for(int i = 0; i < amountAnts; i++){                                                        // Generate Ants in empty blocks
            int xTemp, yTemp;

            do{                                                                                     // Loops until an empty block is found
                xTemp = (generate() % gameboard.getGrid_X());
                yTemp = (generate() % gameboard.getGrid_Y());
            }while(gameboard.getGridBlock(xTemp, yTemp) != 0);

            gameboard(xTemp, yTemp, 2);
            ant_Population.push_back(Ant(new Point(xTemp, yTemp), new MoveRandom()));
        }
    }
Esempio n. 3
0
File: Board.cpp Progetto: wesklei/IA
void Board::populateBoard() {

    int dead_ants = 0;
    int live_ants = 0;
    int x_pos, y_pos;
    while (dead_ants < this->ANTS_DEAD) {

        do {
            x_pos = random(minBoardAcess, maxBoardAcess);
            y_pos = random(minBoardAcess, maxBoardAcess);
        } while (!(this->board[x_pos][y_pos].state == FREE));

        this->board[x_pos][y_pos].state = ANT_DEAD;
        dead_ants++;
    }

    while (live_ants < this->ANTS_LIVE) {

        do {
            x_pos = random(minBoardAcess, maxBoardAcess);
            y_pos = random(minBoardAcess, maxBoardAcess);
        } while (!(this->board[x_pos][y_pos].state == FREE));

        this->board[x_pos][y_pos].state = ANT_NONCARRING;

        this->liveAntsInBoard[live_ants] = Ant(x_pos, y_pos);
        std::cout << "[" << this->liveAntsInBoard[live_ants].x_pos << "," << this->liveAntsInBoard[live_ants].y_pos << "]" << std::endl;
        live_ants++;
    }
}
Esempio n. 4
0
void Map::flash() {
    sort(ants.begin(), ants.end(), cmp);
    for (int i = 0; i < ants.size(); ) {
        int same = 1;
        while (i + same < ants.size() && ants[i] == ants[i + same])
            same++;
        for (int j = 1; j < same; j++) {
            merge(ants[i].foods, ants[i + j].foods);
        }
        for (int j = 1; j < same; j++) {
            ants[i + j].foods = ants[i].foods;
        }
        i += same;
    }
    int food[x][y];
    for (int i = 0; i < x; i++)
        for (int j = 0; j < y; j++)
            food[i][j] = 0;
    for (int i = 0; i < foods.size(); i++)
        food[foods[i].x][foods[i].y] = foods[i].food;
    for (int i = 0; i < ants.size(); i++) {
        Ant &ant = ants[i];
        if (food[ant.x][ant.y] != 0) {
            merge(ant.foods, std::vector<Food>(1, Food(ant.x, ant.y, food[ant.x][ant.y])));
            if (ant.food == 0) {
                ant.food++;
            }
        }
        if (ant == home) {
            home.food += ant.food;
            ant.food = 0;
        }
        ant.action(*this);
    }
    while (home.food >= antValue) {
        home.food -= antValue;
        ants.push_back(Ant(home.x, home.y));
    }
}
void StageWaveManager::MakeEnemy()
{
	switch (enemyType)
	{
	case EnemyType::ANT_:
		GameManager::enemys.push_back(Ant(*UIManager::textureManager.Find(TextureID::_ANT),
			                              *UIManager::textureManager.Find(TextureID::_DEAD_EFFECT),
			                              waitTime + DEFAULT_WAIT_TIME));
		break;
	case EnemyType::MUMMY_:
		GameManager::enemys.push_back(Mummy(*UIManager::textureManager.Find(TextureID::_MUMMY),
			                                *UIManager::textureManager.Find(TextureID::_DEAD_EFFECT),
		 	                                waitTime + DEFAULT_WAIT_TIME));
		break;
	case EnemyType::DRAGON_:
		GameManager::enemys.push_back(Dragon(*UIManager::textureManager.Find(TextureID::_DRAGON),
			                                 *UIManager::textureManager.Find(TextureID::_DEAD_EFFECT),
			                                 waitTime + DEFAULT_WAIT_TIME));
		break;
	default:
		std::cout << "Don't make Enemy!! Please Check!" << std::endl;
		break;
	}
}