本文整理汇总了C++中game_state类的典型用法代码示例。如果您正苦于以下问题:C++ game_state类的具体用法?C++ game_state怎么用?C++ game_state使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了game_state类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: ai_info
playsingle_controller::playsingle_controller(const config& level,
game_state& state_of_game, hero_map& heros, hero_map& heros_start,
card_map& cards,
const int ticks, const int num_turns,
const config& game_config, CVideo& video, bool skip_replay) :
play_controller(level, state_of_game, heros, heros_start, cards,
ticks, num_turns, game_config, video, skip_replay, false),
cursor_setter(cursor::NORMAL),
data_backlog_(),
textbox_info_(),
replay_sender_(recorder),
end_turn_(false),
player_type_changed_(false),
turn_over_(false),
skip_next_turn_(false),
level_result_(NONE)
{
game_config::no_messagebox = false;
game_config::hide_tactic_slot = false;
// game may need to start in linger mode
if (state_of_game.classification().completion == "victory" || state_of_game.classification().completion == "defeat")
{
LOG_NG << "Setting linger mode.\n";
browse_ = linger_ = true;
}
ai::game_info ai_info(*gui_, map_, units_, heros_, teams_, tod_manager_, gamestate_);
ai::manager::set_ai_info(ai_info);
ai::manager::add_observer(this) ;
}
开发者ID:coolsee,项目名称:War-Of-Kingdom,代码行数:31,代码来源:playsingle_controller.cpp
示例2:
playsingle_controller::playsingle_controller(const config& level,
game_state& state_of_game, const int ticks, const int num_turns,
const config& game_config, CVideo& video, bool skip_replay) :
play_controller(level, state_of_game, ticks, num_turns, game_config, video, skip_replay),
cursor_setter(cursor::NORMAL),
data_backlog_(),
textbox_info_(),
replay_sender_(recorder),
end_turn_(false),
player_type_changed_(false),
replaying_(false),
turn_over_(false),
skip_next_turn_(false),
level_result_(NONE)
{
// game may need to start in linger mode
if (state_of_game.classification().completion == "victory" || state_of_game.classification().completion == "defeat")
{
LOG_NG << "Setting linger mode.\n";
browse_ = linger_ = true;
}
ai::game_info ai_info;
ai::manager::set_ai_info(ai_info);
ai::manager::add_observer(this) ;
}
开发者ID:asimonov-im,项目名称:wesnoth,代码行数:26,代码来源:playsingle_controller.cpp
示例3: ai_move
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
示例4: ai_move
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
示例5: balance_ffa
///well, more of an iterative balance. Should probably make it properly fully balance
///team data isn't reliable. Am I an idiot?
///this is not a good balance, we want to distribute players evenly between teams
void balance_ffa(game_state& state)
{
int number_of_players = state.player_list.size();
int max_players_per_team = (number_of_players / TEAM_NUMS) + 1;
//printf("Max num of players per team %i\ncurrentplayernum %i\n", max_players_per_team, number_of_players);;
std::vector<int32_t> too_big_teams;
too_big_teams.resize(TEAM_NUMS);
for(int i=0; i<TEAM_NUMS; i++)
{
if(state.number_of_team(i) > max_players_per_team)
{
too_big_teams[i] = 1;
}
}
for(auto& i : state.player_list)
{
if(i.team < 0 || i.team >= too_big_teams.size() || too_big_teams[i.team] == 1)
{
int old_team = i.team;
i.team = (i.team + 1) % TEAM_NUMS;
byte_vector vec;
vec.push_back(canary_start);
vec.push_back(message::TEAMASSIGNMENT);
vec.push_back<int32_t>(i.id);
vec.push_back<int32_t>(i.team);
vec.push_back(canary_end);
int no_player = -1;
state.broadcast(vec.ptr, no_player);
if(old_team >= 0 && old_team < too_big_teams.size())
too_big_teams[old_team] = 0;
}
}
}
开发者ID:20k,项目名称:sword_gameserver,代码行数:46,代码来源:game_state.cpp
示例6: 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
示例7: balance_first_to_x
void balance_first_to_x(game_state& state)
{
if(state.number_of_team(0) == state.number_of_team(1))
return;
///odd number of players, rest in peace
if(abs(state.number_of_team(1) - state.number_of_team(0)) == 1)
return;
int t0 = state.number_of_team(0);
int t1 = state.number_of_team(1);
int team_to_swap = t1 > t0 ? 1 : 0;
int team_to_swap_to = t1 < t0 ? 1 : 0;
int extra = abs(state.number_of_team(1) - state.number_of_team(0));
int num_to_swap = extra / 2;
int num_swapped = 0;
for(auto& i : state.player_list)
{
if(i.team == team_to_swap && num_swapped < num_to_swap)
{
i.team = team_to_swap_to;
///network
byte_vector vec;
vec.push_back(canary_start);
vec.push_back(message::TEAMASSIGNMENT);
vec.push_back<int32_t>(i.id);
vec.push_back<int32_t>(i.team);
vec.push_back(canary_end);
//udp_send_to(i.sock, vec.ptr, (const sockaddr*)&i.store);
int no_player = -1;
state.broadcast(vec.ptr, no_player);
num_swapped++;
}
}
}
开发者ID:20k,项目名称:sword_gameserver,代码行数:45,代码来源:game_state.cpp
示例8:
replay_controller::replay_controller(const config& level,
game_state& state_of_game, const int ticks, const int num_turns,
const config& game_config, CVideo& video) :
play_controller(level, state_of_game, ticks, num_turns, game_config, video, false),
teams_start_(),
gamestate_start_(state_of_game),
units_start_(),
tod_manager_start_(level, num_turns, &state_of_game),
current_turn_(1),
delay_(0),
is_playing_(false),
show_everything_(false),
show_team_(state_of_game.classification().campaign_type == "multiplayer" ? 0 : 1)
{
init();
gamestate_start_ = gamestate_;
}
开发者ID:Yossarian,项目名称:WesnothAddonServer,代码行数:17,代码来源:replay_controller.cpp
示例9: play_replay
void play_replay(display& disp, game_state& gamestate, const config& game_config,
hero_map& heros, hero_map& heros_start, card_map& cards, CVideo& video)
{
std::string type = gamestate.classification().campaign_type;
if(type.empty())
type = "scenario";
// 'starting_pos' will contain the position we start the game from.
config starting_pos;
if (gamestate.starting_pos.empty()){
// Backwards compatibility code for 1.2 and 1.2.1
const config &scenario = game_config.find_child(type,"id",gamestate.classification().scenario);
assert(scenario);
gamestate.starting_pos = scenario;
}
starting_pos = gamestate.starting_pos;
//for replays, use the variables specified in starting_pos
if (const config &vars = starting_pos.child("variables")) {
gamestate.set_variables(vars);
}
try {
// Preserve old label eg. replay
if (gamestate.classification().label.empty())
gamestate.classification().label = starting_pos["name"].str();
//if (gamestate.abbrev.empty())
// gamestate.abbrev = (*scenario)["abbrev"];
play_replay_level(game_config, &starting_pos, video, gamestate, heros, heros_start, cards);
gamestate.snapshot = config();
recorder.clear();
gamestate.replay_data.clear();
gamestate.start_scenario_ss.str("");
// gamestate.start_hero_ss.str("");
gamestate.clear_start_hero_data();
} catch(game::load_game_failed& e) {
gui2::show_error_message(disp.video(), _("The game could not be loaded: ") + e.message);
} catch(game::game_error& e) {
gui2::show_error_message(disp.video(), _("Error while playing the game: ") + e.message);
} catch(incorrect_map_format_error& e) {
gui2::show_error_message(disp.video(), std::string(_("The game map could not be loaded: ")) + e.message);
} catch(twml_exception& e) {
e.show(disp);
}
}
开发者ID:coolsee,项目名称:War-Of-Kingdom,代码行数:49,代码来源:playcampaign.cpp
示例10: next_move
direction random_ai_player::next_move(const game_state gs) {
player me = gs.player_by_id(get_player_id());
float rand = std::generate_canonical<float, 32>(gen);
if (rand < .30) {
return me.get_direction();
}
rand = std::generate_canonical<float, 32>(gen);
if (rand < .25) {
return LEFT;
} else if (rand < .50) {
return RIGHT;
} else if (rand < .75) {
return UP;
} else {
return DOWN;
}
}
开发者ID:shargoj-hw,项目名称:terminal-tron,代码行数:21,代码来源:ai_player.cpp
示例11:
replay_controller::replay_controller(const config& level,
game_state& state_of_game, const int ticks, const int num_turns,
const config& game_config, CVideo& video) :
play_controller(level, state_of_game, ticks, num_turns, game_config, video, false),
teams_start_(teams_),
gamestate_start_(gamestate_),
units_start_(units_),
tod_manager_start_(level, num_turns),
current_turn_(1),
is_playing_(false),
show_everything_(false),
show_team_(state_of_game.classification().campaign_type == game_classification::MULTIPLAYER ? 0 : 1)
{
tod_manager_start_ = tod_manager_;
// Our parent class correctly detects that we are loading a game. However,
// we are not loading mid-game, so from here on, treat this as not loading
// a game. (Allows turn_1 et al. events to fire at the correct time.)
loading_game_ = false;
init();
reset_replay();
}
开发者ID:gaconkzk,项目名称:wesnoth,代码行数:23,代码来源:replay_controller.cpp
示例12: savegame
scenariostart_savegame::scenariostart_savegame(hero_map& heros, hero_map& heros_start, game_state &gamestate)
: savegame(heros, heros_start, gamestate, dummy_snapshot)
{
memset(game_config::savegame_cache, 0, sizeof(unit_segment2));
set_filename(gamestate.classification().label);
}
开发者ID:freeors,项目名称:War-Of-Kingdom,代码行数:6,代码来源:savegame.cpp
示例13: savegame
scenariostart_savegame::scenariostart_savegame(game_state &gamestate, const bool compress_saves)
: savegame(gamestate, compress_saves)
{
set_filename(gamestate.classification().label);
}
开发者ID:blackberry,项目名称:Wesnoth,代码行数:5,代码来源:savegame.cpp
示例14: play_game
LEVEL_RESULT play_game(display& disp, game_state& gamestate, const config& game_config, hero_map& heros, hero_map& heros_start,
card_map& cards,
io_type_t io_type, bool skip_replay)
{
tent::io_type = io_type;
std::string type = gamestate.classification().campaign_type;
if (type.empty()) {
type = "scenario";
}
config const* scenario = NULL;
// 'starting_pos' will contain the position we start the game from.
config starting_pos;
// Do we have any snapshot data?
// yes => this must be a savegame
// no => we are starting a fresh scenario
if (!gamestate.snapshot["runtime"].to_bool() || !recorder.at_end()) {
gamestate.classification().completion = "running";
// Campaign or Multiplayer?
// If the gamestate already contains a starting_pos,
// then we are starting a fresh multiplayer game.
// Otherwise this is the start of a campaign scenario.
if (gamestate.starting_pos["id"].empty() == false) {
starting_pos = gamestate.starting_pos;
scenario = &starting_pos;
} else {
// reload of the scenario, as starting_pos contains carryover information only
scenario = &load_campagin_scenario(gamestate.classification().campaign, gamestate.classification().scenario, type);
VALIDATE(!scenario->empty(), std::string("play_game, cannot load scenario id = ") + gamestate.classification().scenario + " in game_config!");
gamestate.starting_pos = *scenario;
starting_pos = gamestate.starting_pos;
scenario = &starting_pos;
}
} else {
// This game was started from a savegame
starting_pos = gamestate.starting_pos;
scenario = &gamestate.snapshot;
// When starting wesnoth --multiplayer there might be
// no variables which leads to a segfault
if (const config &vars = gamestate.snapshot.child("variables")) {
gamestate.set_variables(vars);
}
gamestate.set_menu_items(gamestate.snapshot.child_range("menu_item"));
// Replace game label with that from snapshot
if (!gamestate.snapshot["label"].empty()){
gamestate.classification().label = gamestate.snapshot["label"].str();
}
}
bool fog = scenario->get("fog")->to_bool();
bool shroud = scenario->get("shroud")->to_bool();
while (scenario != NULL) {
// If we are a multiplayer client, tweak the controllers
if (io_type == IO_CLIENT) {
if (scenario != &starting_pos) {
starting_pos = *scenario;
scenario = &starting_pos;
}
}
config::const_child_itors story = scenario->child_range("story");
gamestate.classification().next_scenario = (*scenario)["next_scenario"].str();
bool save_game_after_scenario = true;
LEVEL_RESULT res = VICTORY;
end_level_data end_level;
try {
// Preserve old label eg. replay
if (gamestate.classification().label.empty()) {
t_string tstr = (*scenario)["name"];
if (gamestate.classification().abbrev.empty()) {
gamestate.classification().label = tstr;
gamestate.classification().original_label = tstr.base_str();
} else {
gamestate.classification().label = std::string(gamestate.classification().abbrev);
gamestate.classification().label.append("-");
gamestate.classification().original_label = gamestate.classification().label;
gamestate.classification().label.append(tstr);
gamestate.classification().original_label.append(tstr.base_str());
}
}
// If the entire scenario should be randomly generated
if ((*scenario)["scenario_generation"] != "") {
const cursor::setter cursor_setter(cursor::WAIT);
static config scenario2;
scenario2 = random_generate_scenario((*scenario)["scenario_generation"], scenario->child("generator"));
//level_ = scenario;
//merge carryover information into the newly generated scenario
config temp(scenario2);
gamestate.starting_pos = temp;
scenario = &scenario2;
}
std::string map_data = (*scenario)["map_data"];
//.........这里部分代码省略.........
开发者ID:coolsee,项目名称:War-Of-Kingdom,代码行数:101,代码来源:playcampaign.cpp
示例15: main
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Ping Pong");
coreState.SetWindow(&window);
coreState.SetState(new menu());
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::Black);
coreState.Update();
coreState.Render();
window.display();
if(quitGame){
window.close();
}
Sleep(5);
}
return 0;
}
开发者ID:MichaelKhalil,项目名称:Ping-Pong-Game,代码行数:32,代码来源:Pong.cpp
示例16: main
int main()
{
sf::RenderWindow window(sf::VideoMode(800, 600), "Ping");
coreState.SetWindow(&window);
coreState.SetState(new main_menu());
sf::Clock timer;
sf::Time elapsed;
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
elapsed = timer.getElapsedTime();
if (elapsed.asMicroseconds() > 162)
{
window.clear(sf::Color::Black);
coreState.Update();
coreState.Render();
window.display();
if (quitGame)
{
window.close();
}
timer.restart();
}
}
return 0;
}
开发者ID:mrLoloCoco,项目名称:Pong,代码行数:45,代码来源:main.cpp
示例17: main
int main(int argc, char ** argv)
{
GameControls::createInstance(argc, argv);
sf::RenderWindow window(sf::VideoMode(800, 800), "DameUs");
coreState.SetWindow(&window);
coreState.SetState(new main_menu());
// run the program as long as the window is open
while (window.isOpen())
{
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
window.clear(sf::Color::Black);
coreState.Update();
coreState.Render();
window.display();
if (quitGame)
{
window.close();
}
std::this_thread::sleep_for(std::chrono::milliseconds(17));
}
return 0;
}
开发者ID:Flash2307,项目名称:PlayGround,代码行数:36,代码来源:main.cpp
示例18: run
void run(void)
{
gs.gs_run();
menu_pages.push(&lv);
}
开发者ID:mastergreg,项目名称:pewpew,代码行数:5,代码来源:pewpew.cpp
示例19: new_game
void new_game(void)
{
gs.gs_run();
menu_pages.push(&lv);
lv.reset();
}
开发者ID:mastergreg,项目名称:pewpew,代码行数:6,代码来源:pewpew.cpp
示例20: gpause
void gpause(void)
{
gs.gs_pause();
menu_pages.pop();
}
开发者ID:mastergreg,项目名称:pewpew,代码行数:5,代码来源:pewpew.cpp
注:本文中的game_state类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论