Ai*
Ai::Create(TCODZip& zip) {
    ai_type type = (ai_type)zip.getInt();
    Ai* ai = nullptr;

    switch(type) {
		case AI_TYPE_PLAYER:
		{
			ai = new PlayerAi();
		} break;

		case AI_TYPE_ORC:
		{
			ai = new OrcAi();
		} break;

		case AI_TYPE_ORC_BEG_FOR_MERCY:
		{
			ai = new OrcAiBegForMercy(nullptr);
		} break;
    }

    ai->Load(zip);

    return(ai);
}
Beispiel #2
0
/**
 * Activates next player. 
 */
void WindowLocations::nextPlayer() {
	Player *player;
	
	playerInTurn++;
	player = gameEngine.getPlayer(playerInTurn);
	
	if (playerInTurn < gameEngine.getPlayerCount()) {
		this->textPlayer->setText(gameEngine.getPlayer(playerInTurn)->getName());
	} else {
		//If this was the last player
		this->textPlayer->clear();
		this->textTip->clear();
		this->butNext->setText("Finish");
	}
	
	//If it's an AI, let it choose it's position
	if (player) {
		Ai *ai;
		ai = player->getAI();
		if (ai) {
			ai->selectStartingLocation();
			nextPlayer();
		}
	}
}
Beispiel #3
0
Ai *Ai::create(TCODZip &zip) {
	AiType type = (AiType)zip.getInt();
	Ai *ai = NULL;
	switch(type) {
		case PLAYER: ai = new PlayerAi(); break;
		case MONSTER: ai = new MonsterAi(); break;
		case CONFUSED_MONSTER: ai = new ConfusedMonsterAi(0,NULL); break;
	}
	ai->load(zip);
	return ai;
}
Beispiel #4
0
Bid SpecificBidAi::bid(Ai const& ai)
{
  Contracts const& contracts = ai.rules().contracts();
  if (ai.last_non_pass().is_pass() && bid_ < contracts.reserved_bids()) {
    return Bid(0);
  }
  if (bid_ >= ai.last_non_pass() &&
     (bid_ > ai.last_non_pass() || ai.position() == position_forehand)) {
    return bid_;
  }
  return Bid::pass;
}
Beispiel #5
0
int main(int ac, char** av) {
    Ai topClass;
    std::string path;

    if (ac >= 2) {
        for (int i = 1; i < ac; i++) {
            path = av[i];
            if (topClass.loadPath(path)) {
                std::cout << "load " << path << " ok !!§§" << std::endl;
            }
        }
        topClass.forward();
    }

    topClass.backward();
    return 0;
}
Beispiel #6
0
void SpecificBidAi::reset(Ai const& ai)
{
  if (bid_name_ == "pass") {
    bid_ = Bid::pass;
  } else {
    Contracts const& contracts = ai.rules().contracts();
    bid_ = contracts.index_by_bid_name(bid_name_);
    if (bid_.is_pass()) {
      throw AiError("SpecificBidAi: no such bid '"+bid_name_+"'");
    }
  }
}
Beispiel #7
0
/**
 * Handles mouse up events
 * @param button - button that is pressed
 */
void WindowShop::mouseUp(SDL_MouseButtonEvent button){

	//Find out if a button was hit
	UIComponent *component = findComponent(button.x, button.y);
	int i;
	
	
	Player *player = this->gameEngine.getPlayer(this->activePlayerIndex);
	
	if (component == buttonNextPlayer) {		
		this->sounds.playSound(SOUND_CLICK);
		
		//Select next player
		activePlayerIndex++;
		
		//If this was the last player
		if ((int)activePlayerIndex >= this->gameEngine.getPlayerCount()) {
			activePlayerIndex = 0;
			this->startGame();
			return;
		}
		this->updateFields();
	}
	
	else if (component == buttonQuit) {
		this->sounds.playSound(SOUND_CLICK);
		this->close(0);
	}
	
	else if (component == this->buttonRandomWeapons) {
		this->sounds.playSound(SOUND_CLICK);
		Ai *tempAi = new Ai(*player);
		tempAi->doShopping();
		delete tempAi;
		this->updateFields();
	}
	
	else if (component == this->buttonClearAll){
		this->sounds.playSound(SOUND_CLICK);
		this->resetPlayerProperties(player);
		this->updateFields();
	}
	
	else if (component == this->buttonBuyArmor) {
		if (player->buyShieldArmor(1)) {
			this->sounds.playSound(SOUND_CLICK);
			this->updateFields();
		}
		else {
			this->sounds.playSound(SOUND_TICK);
		}
	}
	else if (component == this->buttonSellArmor) {
		if (player->buyShieldArmor(-1)) {
			this->sounds.playSound(SOUND_CASH);
			this->updateFields();
		}
		else {
			this->sounds.playSound(SOUND_TICK);
		}
	}
	
	for (i = 0; i < this->projectileCount; i++) {
		
		if (component == this->buttonsBuy[i]) {
			if ( player->buyShots(i,1) ) {
				this->sounds.playSound(SOUND_CLICK);
				this->updateFields();
			}
			else {
				this->sounds.playSound(SOUND_TICK);
			}
		}
		
		else if (component == this->buttonsSell[i]) {
			if (player->buyShots(i,-1)) {
				this->sounds.playSound(SOUND_CASH);
				this->updateFields();
			}
			else {
				this->sounds.playSound(SOUND_TICK);
			}
		}

		else if (component == this->buttonsProjectile[i]) {
			this->sounds.playSound(SOUND_CLICK);
			this->updateDescriptionField( i );
		}

	}
	
	redraw();
}
Beispiel #8
0
std::vector<char> Player::Evaluate(std::vector<Card*> p1_cards, std::vector<Card*> p2_cards)
{
    Ai ev;
    return ev.EvaluatePlay(p1_cards, p2_cards, cards_in_hand);
}
Beispiel #9
0
	void test::run(prog_options& options)
	{
		Game* game = new Game();
		Ai* ai = new Ai(options);
		ai->setThinkingTime(2);

		game->displayASCII();

		game->makeMove(4);
		game->makeMove(4);
		game->makeMove(5);

		game->displayASCII();

		auto serialized_bitboard = game->getState();
		printf("%ld\n",serialized_bitboard[2]);

		ai->setState(serialized_bitboard);
		ai->_ai->print_tree(2);
		ai->explore();
		ai->_ai->print_tree(2);

		auto dump = ai->getMovesStatistics();
		sort(dump.begin(), dump.end(), second);
		u_long move_chosen = (*(dump.begin())).first;
		std::cout << "move - win / full" << std::endl;
		for(auto t = dump.begin(); t != dump.end(); ++t)
		{
			std::cout << (*t).first << " - " << (*t).second.first << "/" << (*t).second.second << std::endl;
		}

		game->makeMove(move_chosen);
		serialized_bitboard = game->getState();
		game->displayASCII();

		ai->setState(serialized_bitboard);
		ai->explore();

		dump = ai->getMovesStatistics();
		sort(dump.begin(), dump.end(), second);
		move_chosen = (*(dump.begin())).first;
		std::cout << "move - win / full" << std::endl;
		for(auto t = dump.begin(); t != dump.end(); ++t)
		{
			std::cout << (*t).first << " - " << (*t).second.first << "/" << (*t).second.second << std::endl;
		}
		game->makeMove(move_chosen);
		serialized_bitboard = game->getState();
		game->displayASCII();

		ai->setState(serialized_bitboard);
		ai->explore();

		dump = ai->getMovesStatistics();
		sort(dump.begin(), dump.end(), second);
		move_chosen = (*(dump.begin())).first;
		std::cout << "move - win / full" << std::endl;
		for(auto t = dump.begin(); t != dump.end(); ++t)
		{
			std::cout << (*t).first << " - " << (*t).second.first << "/" << (*t).second.second << std::endl;
		}
		game->makeMove(move_chosen);
		serialized_bitboard = game->getState();
		game->displayASCII();

		ai->setState(serialized_bitboard);
		ai->explore();

		dump = ai->getMovesStatistics();
		sort(dump.begin(), dump.end(), second);
		move_chosen = (*(dump.begin())).first;
		std::cout << "move - win / full" << std::endl;
		for(auto t = dump.begin(); t != dump.end(); ++t)
		{
			std::cout << (*t).first << " - " << (*t).second.first << "/" << (*t).second.second << std::endl;
		}
		game->makeMove(move_chosen);
		serialized_bitboard = game->getState();
		game->displayASCII();

		ai->setState(serialized_bitboard);
		ai->explore();

		dump = ai->getMovesStatistics();
		sort(dump.begin(), dump.end(), second);
		move_chosen = (*(dump.begin())).first;
		std::cout << "move - win / full" << std::endl;
		for(auto t = dump.begin(); t != dump.end(); ++t)
		{
			std::cout << (*t).first << " - " << (*t).second.first << "/" << (*t).second.second << std::endl;
		}
		game->makeMove(move_chosen);
		serialized_bitboard = game->getState();
		game->displayASCII();

		ai->setState(serialized_bitboard);
		ai->explore();

		dump = ai->getMovesStatistics();
		sort(dump.begin(), dump.end(), second);
		move_chosen = (*(dump.begin())).first;
		std::cout << "move - win / full" << std::endl;
		for(auto t = dump.begin(); t != dump.end(); ++t)
		{
			std::cout << (*t).first << " - " << (*t).second.first << "/" << (*t).second.second << std::endl;
		}
		game->makeMove(move_chosen);
		game->displayASCII();



		cout << "#####################" << endl;
		delete game;

		cout << "test 1 passed" << endl;

		// game = new Game();

		// serialized_bitboard = game->getState();
		// ai->setState(serialized_bitboard);
		// ai->displayASCII();
		// ai->_ai->print_tree(2);

		// ai->makeMove(7);
		// ai->explore();

		// dump = ai->getMovesStatistics();
		// sort(dump.begin(), dump.end(), second);
		// move_chosen = (*(dump.begin())).first;

		// ai->makeMove(move_chosen);
		// serialized_bitboard = ai->getState();
		// ai->displayASCII();


		// game->setState(serialized_bitboard);
		// game->displayASCII();

		// game->makeMove(4);
		// game->makeMove(3);

		// game->makeMove(3);
		// game->makeMove(3);

		// game->makeMove(1);
		// game->makeMove(2);

		// game->makeMove(1);
		// game->makeMove(2);

		// game->makeMove(1);
		// game->makeMove(4);

		// game->makeMove(2);
		// game->makeMove(4);

		// game->makeMove(4);
		// game->makeMove(4);

		// game->makeMove(3);
		// game->makeMove(3);

		// game->makeMove(2);
		// game->makeMove(2);

		// game->makeMove(1);

		// game->displayASCII();
		// cout << game->getWinner() << endl;
		// cout << "test 2 passed" << endl;
		// auto wl = game->getWinningLine();
		// for (auto it = wl.begin(); it != wl.end(); ++it)
		// {	
		// 	cout << (*it).first << ";" << (*it).second << endl;
		//	}
	}