本文整理汇总了C++中DoomGame::getGameVariable方法的典型用法代码示例。如果您正苦于以下问题:C++ DoomGame::getGameVariable方法的具体用法?C++ DoomGame::getGameVariable怎么用?C++ DoomGame::getGameVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DoomGame
的用法示例。
在下文中一共展示了DoomGame::getGameVariable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
std::cout << "\n\nCIG HOST EXAMPLE\n\n";
DoomGame* game = new DoomGame();
// Use CIG example config or Your own.
game->loadConfig("../../scenarios/cig.cfg");
// Select game and map You want to use.
game->setDoomGamePath("../../scenarios/freedoom2.wad");
//game->setDoomGamePath("../../scenarios/doom2.wad"); // Not provided with environment due to licences.
game->setDoomMap("map01"); // Limited deathmatch.
//game->setDoomMap("map02"); // Full deathmatch.
// Host game with options that will be used in the competition.
game->addGameArgs("-host 8 " // This machine will function as a host for a multiplayer game with this many players (including this machine). It will wait for other machines to connect using the -join parameter and then start the game when everyone is connected.
"-deathmatch " // Deathmatch rules are used for the game.
"+timelimit 10.0 " // The game (episode) will end after this many minutes have elapsed.
"+sv_forcerespawn 1 " // Players will respawn automatically after they die.
"+sv_noautoaim 1 " // Autoaim is disabled for all players.
"+sv_respawnprotect 1 " // Players will be invulnerable for two second after spawning.
"+sv_spawnfarthest 1 " // Players will be spawned as far as possible from any other players.
"+viz_nocheat 1"); // Disables depth buffer and the ability to use commands that could interfere with multiplayer game.
// Name your agent and select color
// colors: 0 - green, 1 - gray, 2 - brown, 3 - red, 4 - light gray, 5 - light brown, 6 - light red, 7 - light blue
game->addGameArgs("+name AI +colorset 0");
game->setMode(ASYNC_PLAYER);
game->init();
while(!game->isEpisodeFinished()){ // Play until the game (episode) is over.
if(game->isPlayerDead()){
game->respawnPlayer(); // Use this to respawn immediately after death, new state will be available.
// Or observe the game until automatic respawn.
//game->advanceAction();
//continue;
}
GameStatePtr state = game->getState();
// Analyze the state.
std::vector<int> action(game->getAvailableButtonsSize());
// Set your action.
game->makeAction(action);
std::cout << game->getEpisodeTime() << " Frags: " << game->getGameVariable(FRAGCOUNT) << std::endl;
}
game->close();
}
示例2: GetObject
/*
* Class: DoomGame
* Method: getGameVariable
* Signature: (Lvizdoom/GameVariable;)I
*/
JNIEXPORT jint JNICALL Java_vizdoom_DoomGame_getGameVariable
(JNIEnv *env, jobject obj, jobject enumVal){
DoomGame* game = GetObject(env,obj);
jclass jclassEnum = env->FindClass("vizdoom/GameVariable");
if(jclassEnum != 0){
jmethodID ordinal_ID = env->GetMethodID(jclassEnum, "ordinal", "()I");
if (ordinal_ID == 0){
return -1;
}
jint value = env->CallIntMethod(enumVal, ordinal_ID);
GameVariable ret=static_cast<GameVariable>(value);
int retint=game->getGameVariable(ret);
// Delete local references created
env->DeleteLocalRef(jclassEnum);
return retint;
}
}
示例3: main
int main(){
std::cout << "\n\nSHAPING EXAMPLE\n\n";
DoomGame *game = new DoomGame();
// Health gathering scenario has scripted shaping reward.
game->loadConfig("../../examples/config/health_gathering.cfg");
game->setScreenResolution(RES_640X480);
game->init();
// Define some actions.
std::vector<int> actions[3];
actions[0] = {1, 0, 0};
actions[1] = {0, 1, 0};
actions[2] = {0, 0, 1};
std::srand(time(0));
int episodes = 10;
unsigned int sleepTime = 28;
// Use this to remember last shaping reward value.
double lastTotalShapingReward = 0;
for (int i = 0; i < episodes; ++i) {
std::cout << "Episode #" << i + 1 << "\n";
// Seed can be changed anytime. It will affect next episodes.
// game->setSeed(seed);
game->newEpisode();
lastTotalShapingReward = 0;
while (!game->isEpisodeFinished()) {
// Get the state
GameStatePtr state = game->getState();
// Make random action and get reward
double reward = game->makeAction(actions[std::rand() % 3]);
// Retrieve the shaping reward
int fixedShapingReward = game->getGameVariable(USER1); // Get value of scripted variable
double shapingReward = doomFixedToDouble(shapingReward); // If value is in DoomFixed format project it to double
shapingReward = shapingReward - lastTotalShapingReward;
lastTotalShapingReward += shapingReward;
std::cout << "State #" << state->number << "\n";
std::cout << "Health: " << state->gameVariables[0] << "\n";
std::cout << "Action reward: " << reward << "\n";
std::cout << "Action shaping reward: " << shapingReward << "\n";
std::cout << "=====================\n";
if(sleepTime) sleep(sleepTime);
}
std::cout << "Episode finished.\n";
std::cout << "Total reward: " << game->getTotalReward() << "\n";
std::cout << "************************\n";
}
// It will be done automatically in destructor but after close You can init it again with different settings.
game->close();
delete game;
}