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


C++ game_state::get_all_no_tipping_moves方法代码示例

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


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

示例1:

	pair<int, int> ai_move(game_state state) {
		vector<pair<int, int> > all_moves = state.get_all_no_tipping_moves();
		if (all_moves.size() == 0) {
			// if all moves would tip, surrender
			return pair<int, int>(-1, 16);
		}
		return all_moves[rand() % all_moves.size()];
	}
开发者ID:ashwath,项目名称:heuristics2012,代码行数:8,代码来源:random_ai.cpp

示例2: time

	pair<int, int> ai_move(game_state state) {
		vector<pair<int, int> > all_moves = state.get_all_no_tipping_moves();
		if (all_moves.size() == 0) {
			// if all moves would tip, surrender
			return pair<int, int>(-1, 16);
		}
		
		// find best solution
		int alpha = -1000;
		int beta = 1000;
		int best_index = 0;

		if (state.game_turn < 15) {
			ai_depth = 3;
		}
		else {
			ai_depth = 4 + (state.game_turn-15) / 3;
		}
		
		cout << "[[TURN:" << state.game_turn << "]]\n";
		cout << "======= depth: " << ai_depth << " ==========\n";
		time_t s_time = time(NULL);
		
		for (int ii = 0; ii < all_moves.size(); ii ++) {
			int i = ii;
			if (ai_depth % 2 == 0) {
				i = (int) all_moves.size() - ii - 1;
			}
			int this_value = alpha_beta(state.move_fast(all_moves[i]), ai_depth-1, alpha, beta);
//			cout << all_moves[i].first << "," << all_moves[i].second << " : " << this_value << "\n";
			if (ai_depth % 2 == 0) {
				// minimax 2(2,3), 1(0), 3(1,4,1)->first
				if (this_value > alpha) {
					alpha = this_value;
					best_index = i;
				}
			}
			else {
				// maxmini 2,1,3->second
				if (this_value < beta) {
					beta = this_value;
					best_index = i;
				}
			}
			if (alpha >= beta) {
				break;
			}
		}
		
		time_t e_time = time(NULL);
		cout << "======used: " << e_time-s_time << " seconds=======\n";
		return all_moves[best_index];
	}
开发者ID:ashwath,项目名称:heuristics2012,代码行数:53,代码来源:alpha_beta_ai.cpp

示例3: alpha_beta

	int alpha_beta(game_state state, int depth, int alpha, int beta) {
		if (alpha == beta) {
			return alpha;
		}
		
		vector<pair<int, int> > children = state.get_all_no_tipping_moves();
		
		if (depth == 0) {
			return (int) children.size();
		}
		
		if (depth % 2 == 0) {
			// get max, only alpha
			// minimax 2(2,3), 1(0), 3(1,4,1)->first
			for (int i = 0; i < children.size(); i ++) {
				int value = alpha_beta(state.move_fast(children[i]), depth-1, alpha, beta);
				if (value > alpha) {
					alpha = value;
				}
				if (alpha >= beta) {
					return alpha;
				}
				
			}
			return alpha;
		}
		else {
			// get min, only beta
			// maxmini 2, 1, 3->second
			for (int i = 0; i < children.size(); i ++) {
				int value = alpha_beta(state.move_fast(children[i]), depth-1, alpha, beta);
				if (value < beta) {
					beta = value;
				}
				if (beta <= alpha) {
					return beta;
				}
			}
			return beta;			
		}
	}
开发者ID:ashwath,项目名称:heuristics2012,代码行数:41,代码来源:alpha_beta_ai.cpp


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