当前位置: 首页>>代码示例>>C++>>正文


C++ BinaryHeap::interact_with_Soldier方法代码示例

本文整理汇总了C++中BinaryHeap::interact_with_Soldier方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryHeap::interact_with_Soldier方法的具体用法?C++ BinaryHeap::interact_with_Soldier怎么用?C++ BinaryHeap::interact_with_Soldier使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryHeap的用法示例。


在下文中一共展示了BinaryHeap::interact_with_Soldier方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: processTurn

//Will pick a soldier from our remaining soldiers alive.
//
void processTurn(BinaryHeap<soldier>& heap, vector<int>& soldiers, int& remaining_Soldiers)
{
	int position_of_Soldier;
	if(remaining_Soldiers == 1) position_of_Soldier = 0;//A condition to ensure kill a soldier is not called when only one soldier is left
	else position_of_Soldier = rand() % remaining_Soldiers;

	bool target_Condition;
	
	soldier nextUp = heap.findMin(); //Return the smallest value; our next up.

	target_Condition = heap.interact_with_Soldier(nextUp.return_Faction(), soldiers[position_of_Soldier]);//False if alive, true if killed
	if(target_Condition && nextUp.return_Faction() ) kill_a_Soldier(soldiers, remaining_Soldiers, position_of_Soldier);//Will removed the soldier if dead.
	else if(target_Condition && !(nextUp.return_Faction()) ) {//Will invigorate if a soldier is killed, AND the soldier target was a Persian

		kill_a_Soldier(soldiers, remaining_Soldiers, position_of_Soldier);//Remove the soldier as per usual
		invigorate(heap, soldiers, remaining_Soldiers);//function invigorate will go through the entire array to invigorate soldiers.
	}

}
开发者ID:jseuribe,项目名称:335_project3,代码行数:21,代码来源:sim300.cpp


注:本文中的BinaryHeap::interact_with_Soldier方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。