コード例 #1
0
ファイル: AIInterface.cpp プロジェクト: rianneogi/DuelMasters
int AIInterface::Search(Duel* pos, int depth, int player)
{
	//Duel* lastpos
	if (depth == 0)
	{
		return Evaluate(pos, player);
	}
	int value = 0;
	vector<Message> moves = getValidMoves(pos);
	for (int i = 0; i < min(10, int(moves.size())); i++)
	{
		//Duel* d = new Duel(*pos);
		Duel* d = new Duel;
		ActiveDuel = d;
		d->isSimulation = true;
		d->RandomGen.SetRandomSeed(pos->RandomGen.GetRandomSeed());
		d->setDecks(pos->decknames[0], pos->decknames[1]);
		d->startDuel();
		d->dispatchAllMessages();
		cout << "AI: move size: " << pos->MoveHistory.size() << endl;
		for (vector<Message>::iterator i = pos->MoveHistory.begin(); i != pos->MoveHistory.end(); i++)
		{
			//cout << "AI sim move: " << (*i).getType() << endl;
			d->handleInterfaceInput(*i);
			d->dispatchAllMessages();
		}
		if (d->hands[0].cards.size() != pos->hands[0].cards.size())
		{
			cout << "AI: ERROR check not valid NON-ROOT " << d->hands[0].cards.size() << " " << pos->hands[0].cards.size() << endl;
			cout << d->MoveHistory.size() << " " << pos->MoveHistory.size() << endl;
		}
	
		for (int i = 0; i < depth; i++)
		{
			vector<Message> m = getValidMoves(d);
			if (m.size() == 0)
			{
				cout << "AI: out of moves" << endl;
				break;
			}
			Message mov = m.at(rand() % m.size());
			d->handleInterfaceInput(mov);
			d->dispatchAllMessages();
			cout << "AI: move made: " << mov.getType() << endl;
		}
		value += Evaluate(d, player);
		
		if (d!=NULL)
			delete d;
	}

	return value;
}