Fluxkompensator Posted December 27, 2014 Report Share Posted December 27, 2014 Hello,I wrote a new component in c++ and now I want to access to this methods in _petrabot.js:Engine.QueryInterface(SYSTEM_ENTITY, IID_MyComponent).In binaries\data\mods\public\simulation\helpers\InitGame.js it works fine.In _petrabot.js you can access to this method:Engine.IncludeModule("common-api")but not to this one:Engine.QueryInterface(SYSTEM_ENTITY, IID_MyComponent):" QueryInterface is not a function"(btw.: SYSTEM_ENTITY and IID_MyComponent are also not defined in _petrabot.js, I have replaced these with the corresponding integer value)It seems to be Engine is defined, but not QueryInterface-function, SYSTEM_ENTITY and IID_MyComponent!?What I am doing wrong?Is there a document where I can see, which functions of "Engine" are accessible in which javascript-files or a general documentation of "Engine"?Maybe I just need a Link.Thank you for your time and attention Quote Link to comment Share on other sites More sharing options...
Teiresias Posted December 27, 2014 Report Share Posted December 27, 2014 I stumbled on the same question before. In short, not each part of the JS scripts can access each C++ method, they have to be reflected into the JS runtime beforehand.In detail: See /source/simulation2/components/CCmpAIManager.cpp - the CAIWorker is the C++ "driver" of a single bot afaik. At construction time, it initiates the m_ScriptInterface:m_ScriptInterface(new ScriptInterface("Engine", "AI", g_ScriptRuntime))that's the "Engine" object you see in JS. Following in the constructor you see the functions being registered:m_ScriptInterface->RegisterFunction<void, int, CScriptValRooted, CAIWorker::PostCommand>("PostCommand");m_ScriptInterface->RegisterFunction<void, std::wstring, CAIWorker::IncludeModule>("IncludeModule");m_ScriptInterface->RegisterFunction<void, CAIWorker::DumpHeap>("DumpHeap");m_ScriptInterface->RegisterFunction<void, CAIWorker::ForceGC>("ForceGC"); m_ScriptInterface->RegisterFunction<void, std::wstring, std::vector<u32>, u32, u32, u32, CAIWorker::DumpImage>("DumpImage");So these are the functions of the Engine you can invoke from the AI. Note this list includes "IncludeModule" but not "QueryInterface" so a script cannot break out its sandbox directly. As a side notice, PostCommand is used heavily in the common-api scripts.Additionally, in /binaries/data/mods/public/simulation/components/ you'll find files named AIInterface.js and AIProxy.js; these are for passing the simulation game/state to the AI. Quote Link to comment Share on other sites More sharing options...
agentx Posted December 27, 2014 Report Share Posted December 27, 2014 One can run Object.keys(Engine).forEach(k => print(k + "\n")) within a bot and get the list of available commands:ProfileStartProfileStopPostCommandIncludeModuleDumpHeapForceGCDumpImageMore is available via global, Object.keys(global).forEach(k => print(k + "\n")) :API3clonedeepcopyDoesModificationApplyEngineerrorg_pluralTranslationsg_pluralTranslationsWithContextg_translationsg_translationsWithContextGetIdentityClassesGetTechModifiedPropertyGetVisibleIdentityClassesglobalHANNIBALHANNIBAL_DEBUGisNonEmptyStringlogmarkForTranslationmarkForTranslationWithContextMatchesClassListPlayerIDprintsprintftranslatetranslateMessageObjecttranslateObjectKeystranslatePluraltranslatePluralWithContexttranslateWithContextVector2DVector2DprototypeVector3DVector3DprototypevsprintfwarnSame thing (Engine) in the GUI compartment looks different:AddPlaylistItemAssignNetworkPlayerAtlasIsAvailableBuildDirEntListCameraFollowCameraFollowFPSCameraGetXCameraGetZCameraMoveToClearAllPlayerReadyClearPlaylistConfigDB_CreateValueConfigDB_GetValueConfigDB_ReloadConfigDB_SetFileConfigDB_WriteFileConnectXmppClientConsole_GetVisibleEnabledConsole_SetVisibleEnabledCrashDebugWarnDeleteSavedGameDisconnectNetworkGameDisconnectXmppClientDisplayErrorDialogDumpSimStateDumpTerrainMipmapEnableTimeWarpRecordingEncryptPasswordEndGameExitFileExistsForceGCFormatDecimalNumberIntoStringFormatMillisecondsIntoDateStringGameView_GetConstrainCameraEnabledGameView_GetCullingEnabledGameView_GetLockCullCameraEnabledGameView_SetConstrainCameraEnabledGameView_SetCullingEnabledGameView_SetLockCullCameraEnabledGetAIsGetAllLocalesGetAvailableModsGetBoardListGetBuildTimestampGetCurrentLocaleGetDictionariesForLocaleGetDictionaryLocaleGetEngineInfoGetFPSGetFallbackToAvailableDictLocaleGetFileMTimeGetFileSizeGetFollowedEntityGetGUIObjectByNameGetGameListGetLocaleBaseNameGetLocaleCountryGetLocaleLanguageGetLocaleScriptGetMapSettingsGetMatchIDGetPlayerIDGetPlayerListGetProfileGetProfilerStateGetSavedGamesGetSimRateGetSupportedLocaleBaseNamesGetSupportedLocaleDisplayNamesGetTerrainAtScreenPointGetUserReportStatusGuiInterfaceCallHasXmppClientHotkeyIsPressedIsAtlasRunningIsPausedIsRankedGameIsUserReportEnabledLoadMapSettingsLobbyBanLobbyGetNickLobbyGetPlayerPresenceLobbyGetPlayerRoleLobbyGetRoomSubjectLobbyGuiPollMessageLobbyKickLobbySendMessageLobbySetNickLobbySetPlayerPresenceMusicPlayingOpenURLPickEntitiesAtPointPickFriendlyEntitiesInRectPickFriendlyEntitiesOnScreenPickSimilarFriendlyEntitiesPlayAmbientSoundPlayMusicPlayUISoundPollNetworkClientPopGuiPagePopGuiPageCBPostNetworkCommandProfileStartProfileStopPushGuiPageQuickLoadQuickSaveReadFileReadFileLinesReevaluateCurrentLocaleAndReloadRenderer_GetDisplayFrustumEnabledRenderer_GetGenTangentsEnabledRenderer_GetParticlesEnabledRenderer_GetPostprocEnabledRenderer_GetPreferGLSLEnabledRenderer_GetRenderPathRenderer_GetShadowPCFEnabledRenderer_GetShadowsEnabledRenderer_GetShowSkyEnabledRenderer_GetSilhouettesEnabledRenderer_GetSmoothLOSEnabledRenderer_GetWaterFancyEffectsEnabledRenderer_GetWaterRealDepthEnabledRenderer_GetWaterReflectionEnabledRenderer_GetWaterRefractionEnabledRenderer_GetWaterShadowsEnabledRenderer_GetWaterUglyEnabledRenderer_SetDisplayFrustumEnabledRenderer_SetGenTangentsEnabledRenderer_SetParticlesEnabledRenderer_SetPostprocEnabledRenderer_SetPreferGLSLEnabledRenderer_SetRenderPathRenderer_SetShadowPCFEnabledRenderer_SetShadowsEnabledRenderer_SetShowSkyEnabledRenderer_SetSilhouettesEnabledRenderer_SetSmoothLOSEnabledRenderer_SetWaterFancyEffectsEnabledRenderer_SetWaterRealDepthEnabledRenderer_SetWaterReflectionEnabledRenderer_SetWaterRefractionEnabledRenderer_SetWaterShadowsEnabledRenderer_SetWaterUglyEnabledRestartEngineRestartInAtlasRewindTimeWarpSaveGameSaveGamePrefixSaveLocaleSendChangeStateGameSendGameReportSendGetBoardListSendGetGameListSendGetProfileSendGetRatingListSendNetworkChatSendNetworkReadySendRegisterGameSendUnregisterGameSetActionGainSetAmbientGainSetBoundingBoxDebugOverlay(true)SetCameraDataSetCameraTargetSetCursorSetMasterGainSetModsSetMusicGainSetNetworkGameAttributesSetNetworkPlayerStatusSetPausedSetPlayerIDSetRankedGameSetSimRateSetTurnLengthSetUIGainSetUserReportEnabledStartGameStartMusicStartNetworkGameStartNetworkHostStartNetworkJoinStartPlaylistStartRegisterXmppClientStartSavedGameStartXTimerStartXmppClientStopMusicStopXTimerStopXmppClientSubmitUserReportSwitchGuiPageTranslateTranslateArrayTranslateLinesTranslatePluralTranslatePluralWithContextTranslateWithContextUseLongStringsValidateLocaleWhat I miss the most is interactively firing methods a bot has during run time, like you do with the GUI console(F9). Once a bot runs, nothing can interfere. Access to the camera would also help with testing. Another trick would be to chat commands to the bot, but that doesn't work either. Quote Link to comment Share on other sites More sharing options...
Fluxkompensator Posted December 28, 2014 Author Report Share Posted December 28, 2014 Thanks a lot for the quick reply!My intention was to advance the AI with several selflearning features.One of these features should be to remember past skirmish statistics. Even after shutdown the system.To do that, I need to write files to the HDD/SSD.As far as i know there is no option to write/edit files for the AI right now. (in general for JS)So I wrote a C++-Component, which can do it. -> But AI can't use the component via "QueryInterface".Do you know an option for the AI to store informations or writing/editing files?Is there any function or something else I can use? (Maybe the vfs.?)Or maybe there is another way to do this? 1 Quote Link to comment Share on other sites More sharing options...
agentx Posted December 28, 2014 Report Share Posted December 28, 2014 (edited) > Do you know an option for the AI to store informations or writing/editing files?There is none. Except another debugging tool reads and writes from stdout.> to remember past skirmish statistics. Even after shutdown the system.0AD is deterministic. Every game is replicable on every computer. That means bots in a multi player game need *same* code, data and thus behavior. If one bots learned something, he needs to share it with all other, too. Otherwise you'll get out of sync errors very quickly.> Or maybe there is another way to do this?Sure, spend the bots a XMLHttpRequest object like browsers do to sync over the net. Some projects link to curl to embed it. Then the bots can make sure having same knowledge.Or, very advanced, let players train their private ally bots, then the game has to sync the full bot code across all connected players.In both cases I'm ready to work on the server part, syncing data or code. Just the c++ part is way over my head, especially to make it work async with callbacks. Edited December 28, 2014 by agentx Quote Link to comment Share on other sites More sharing options...
Stan` Posted December 28, 2014 Report Share Posted December 28, 2014 > Do you know an option for the AI to store informations or writing/editing files?There is none. Except another debugging tool reads and writes from stdout.> to remember past skirmish statistics. Even after shutdown the system.0AD is deterministic. Every game is replicable on every computer. That means bots in a multi player game need *same* code, data and thus behavior. If one bots learned something, he needs to share it with all other, too. Otherwise you'll get out of sync errors very quickly.> Or maybe there is another way to do this?Sure, spend the bots a XMLHttpRequest object like browsers do to sync over the net. Some projects link to curl to embed it. Then the bots can make sure having same knowledge.Or, very advanced, let players train their private ally bots, then the game has to sync the full bot code across all connected players.In both cases I'm ready to work on the server part, syncing data or code. Just the c++ part is way over my head, especially to make it work async with callbacks.Do you plan to do such a thing ? *.*Maybe you could use the anonymous feedback to send ai data =) Quote Link to comment Share on other sites More sharing options...
agentx Posted December 29, 2014 Report Share Posted December 29, 2014 > Do you plan to do such a thing ?It makes a difference whether a bot learns by running on one machine or hundreds. Quote Link to comment Share on other sites More sharing options...
Stan` Posted December 29, 2014 Report Share Posted December 29, 2014 Therefore ? Quote Link to comment Share on other sites More sharing options...
agentx Posted December 29, 2014 Report Share Posted December 29, 2014 XMLHttpRequest makes bots more clever, because it connects them to the hive mind. Quote Link to comment Share on other sites More sharing options...
Stan` Posted December 29, 2014 Report Share Posted December 29, 2014 Do you have the possibility to set it up ? Quote Link to comment Share on other sites More sharing options...
agentx Posted December 29, 2014 Report Share Posted December 29, 2014 What exactly you mean? Quote Link to comment Share on other sites More sharing options...
Stan` Posted December 29, 2014 Report Share Posted December 29, 2014 I mean, use that system on Hannibal, and allow every SVN player here to contribute to your AI ? Quote Link to comment Share on other sites More sharing options...
agentx Posted December 29, 2014 Report Share Posted December 29, 2014 That'll not work on SVN. Quote Link to comment Share on other sites More sharing options...
Fluxkompensator Posted December 30, 2014 Author Report Share Posted December 30, 2014 (edited) I'm not sure if I have understood correctly:The AI I want to write, should be for single player games only.(I'm afraid hive mind, multi player sync and thinks like that, are a way over my head.)Just Player VS. "Learning_AI". No multi player, just local skirmish. (later maybe one player and many AI's)The data/file where the bot should write his experience is local.With "The feature to remember past skirmish statistics" I mean the experience of the local bot. (no hive mind)That also means if you use the "Learning_AI" the first time, they will not have any experiences.Do you think there is still a problem with synchronization?@ stanislas69:> Do you plan to do such a thing ? *.*My idea is to write an AI, which has the ability to learn and acts more dynamic.But my programmer skill's (C, C++ and Java) are basic and in JS I'm just at the beginning.The goal is a prototype of the AI. (Not finished and far away from "ready to releasing".) Edited December 31, 2014 by Fluxkompensator 1 Quote Link to comment Share on other sites More sharing options...
mimo Posted December 30, 2014 Report Share Posted December 30, 2014 Can you be more specific on what you want the AI to learn ? Quote Link to comment Share on other sites More sharing options...
Fluxkompensator Posted December 30, 2014 Author Report Share Posted December 30, 2014 The idea is that the AI remember the games they played.(The decisions they make and the result of these.)In the next game(s), the AI will make decisions based on their previous experiences.I hope this will creates a kind of "evolvement".To give the AI the ability to remember, I want to write the experiences/decisions into a file.Then the AI can load/read them when a new game (skirmish) starts and save/write them in the end of a game.For example:The AI remeber the last game:The AI only build towers and no army and losed the game.In this game they will try another way (less towers, more army or less towers more workers....) Quote Link to comment Share on other sites More sharing options...
agentx Posted December 30, 2014 Report Share Posted December 30, 2014 I like this idea. I'd really love to make bots share their "their previous experiences". Quote Link to comment Share on other sites More sharing options...
fabio Posted December 31, 2014 Report Share Posted December 31, 2014 It was alreday discussed in the past, at least in these threads, where you may find some useule ideas:http://www.wildfiregames.com/forum/index.php?showtopic=17142http://www.wildfiregames.com/forum/index.php?showtopic=17759 Quote Link to comment Share on other sites More sharing options...
Fluxkompensator Posted December 31, 2014 Author Report Share Posted December 31, 2014 (edited) Thats very uncomfortable:Today I readed my posts again and see that I make a translation mistake:In my description I often using "they" instead of "the AI".(Thats why you asking about how to sharing the knowledge of the AI's. -> Btw. thats a nice idea^^. )Im very sorry about this Actually I want to speak about only one AI(singual) and not about many AI's(plural).I will give this AI the ability to remember previous games.In this way the AI can make decisions based on his experience.The bot will learn in every game, and changing his strategy if necessary.(The AI will also including some random decisions too)The experience of the AI, I want to write into a simple file on the computer of the user.Because of this I'm looking for a way to let the AI writing files.The Current state is, that I have found a dirty way to do this. (I added funcitons in "/source/simulation2/components/CCmpAIManager.cpp")I'm not happy with this solution, so if anybody have an another idea for me, pls let me know. (My problem: AI can not access "Engine.QueryInterface()")@ fabio: Thanks for the links.I hope all of you have a nice evening and night today. Edited December 31, 2014 by Fluxkompensator 1 Quote Link to comment Share on other sites More sharing options...
agentx Posted December 31, 2014 Report Share Posted December 31, 2014 > Actually I want to speak about only one AI(singual) and not about many AI's(plural).Actually my error, I should have made clear that an AI might share knowledge only with its own type. Anyway, if you put sync issues aside, what's left it dealing with with either file system or a web service.Happy New Year° Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.