Game Design: Is a plug-in the best solution for this Problem? (Cocoa, Objective-C) - objective-c

I've started helping with an open source game (based on Cocoa, Obejctive-C, Xcode). The existing game engine is already setup to allow the character to run around the world, encounter an enemy, and when combat is begun, a characterObject is called with the enemy unit object that is to be attacked. This characterObject has a default method of attacking the enemy.
I wanted to improve on this design by extending the program to allow others to develop a combatUnit plugin that would handle the combat actions in their own programmed way. This could open up the community to develop different styles of combat and come up with their own unique play style.
As I began to look into Plug-Ins and examples on how to build, most of the examples kept the plug-in relatively isolated from the internals of the rest of the program. And any data the plugin required would be passed into the routine(s) themselves.
However, in this case, a combat unit developer might want to have access to numerous external objects in the existing game: a developer might want to also know of any nearby enemy units to avoid any potential adds in a fight and would have to access several of the existing environment objects to get that data, the character might be in a group and the developer might want access to the group info and each players data to determine if they should heal, etc... Not knowing what a developer has in mind, it would be unfeasible for me to attempt to predict and pass in all potential info for them to use.
So, my question is:
Is this a good application for a Plug-In? If so, when developing the plug-in how do I open up the other objects for the plug-in developer to code against?
Is there another approach to solve this problem? Something else than a "Plug-in" that would be more appropriate for the code to have access to the game's objects?
Thanks for you help!

That’s a good case for making plug-ins. As an alternative you could compile the new objects directly into the game or use a scripting language interpreter. But with those you’d have to solve the same problems of how to give access to the internals of the game to the new combat unit.
The cleanest way to do this would be to define an interface to the game (either as a protocol or a base class) and pass that to the plug-in. Using this object the plug-in can then query anything it needs.

Related

Interfacing Netlogo with external agents

Can someone guide me as googling does not send me to the right places.
I want to adapt netlogo to include players real or simulated with other technologies. I need to interface the netlogo core (running an established game) and have the moves and choices determined by the external entities, which may be human or automania.
In searching for the API to allow this, I can find is the controlling API which is seems to be for running NetLogo muitiple runs of a model and not what I want.
And please before you close this again suggest how I can make this more focused as the problem is finding the starting point....
Can anyone assist.
Regards
Robert
There are two main ways to interface between NetLogo and the "outside world":
The extensions API.
The controlling API.
Which one to use depends on what you're trying to achieve.
You say that you:
need to interface the netlogo core (running an established game) and have the moves and choices determined by the external entities, which may be human or automania.
That, to me, sounds very much like a job for the extensions API, which is what has been suggested to you on the netlogo-devel group. Extensions allow to add new "primitives" to NetLogo, and those primitives can be written in any language that runs on the JVM (Java, Scala, Clojure, etc.)
So if you have a game written in NetLogo and a bot written in some other language that the JVM can interface with (possibly by using the JNI), you could write a new NetLogo extension command that calls out to the bot (e.g., something like bot:play game-state). A game written in NetLogo could then use that command to let the bot play its turn.
If that is indeed what you want to do, then Jeremy has already given you a good starting point in his netlogo-devel answer, and there is not much we can add to this until you have more specific questions.
You also said, however, that you looked at using the controlling API, so maybe what you had in mind is to have a game written in some other language, and use a NetLogo model to generate the behaviour of a particular player in that game. The controlling API allows you to do that. (It's not just for running a model multiple times!) If you look at the examples in the controlling guide, you'll see that you can use the API to send commands to a NetLogo model and to report the results back to your external program. The only constraint is that this external program needs to be able to talk to the JVM.
If you don't think this answers you question, please try to give us a concrete example of a precise thing that you want to do but do not think can be achieve in one of these two ways. We might be able to help you better than.

I need help choosing a game engine for a very specific task

I need a 3D engine for a very specific task in Artificial Intelligence, and I'd like some input.
The first part is the trivial one - basically, all I need is a FPS engine (3rd person would be good, too), such that it allows me to navigate a room and interact with objects (if you have Java and Windows, I'm looking for something similar to the Give Challenge, but a little more up-to-date). Physics would be nice, but is not a must.
Now, the non-trivial part would be: I need to impose a virtual grid over this room, such that at any moment I can say "the player is located at B5 - now he moved to B6", and so on. I need to redirect this information to another system (namely, one which will give the player instructions about what to do) and, at the same time, send messages to the player, so I must be able to have a single point through which the game logic passes through; also, I'd love not having to write my own collision detection and such.
So far, I've tried:
the Source SDK: it seems a little overkill (since I'm not really planning to shoot anyone, at least half the code base is useless to the task), and since I'm not really a Windows developer, I'm spending too much time with the "easy" stuff (such as getting VS up and running). Plus, cross-platform would be really nice.
Blender game engine: while this worked decently, the interaction model seems a little weird, and some easy stuff (such as making sure the camera stays inside the scene or showing the mouse on screen) gets too weird too soon.
Crystalspace 3D: I've tried their demos, but it looks a little old-fashioned, and since that was one of the problems of previous engines (it's easier to get volunteers when your game looks nice) I'd like to try something else.
Now, maybe I'm asking a little too much for a single software, but I'd love some input. Can anyone suggest me an alternative? Or should I give one of the previous ones a second chance?
Try the UDK. All of the things you request are present, and it's free for personal/noncommercial projects. Here are some highlights:
Modern looking. The UDK features an intuitive-ish visual material design system, post-processing effects, Scaleform Gfx UIs from Autodesk, and more.
A visual scripting interface called Kismet that can control gameplay elements, the camera, and more.
UnrealScript, a scripting language similar in syntax to C, C++, Java, that gives you the ability to extend existing functionality or create your own.
Comprehensive documentation available on UDN.
Lots of community support outside of Epic, in places such as Polycount, Eat3d, 3dbuzz, and more.
Basically, "and more".
If what you're looking for is a professional, free (as in beer) engine that will allow you to focus primarily or solely on your differentiating gameplay features, Epic has set the bar high.

How do I hook into a game and write a script to manipulate it?

I know this is a pretty open question but I was wondering how people go about writing scripts that will "play" a game, or manipulate it in some way. I had been thinking that I'd try to get a working AI to play a game for fun, but don't even really know where to start. Are there any good resources to learn this? What are good languages to use? Once I have the language, how do I get my script hooked into the game? I was thinking of just trying simple flash games, if that helps.
Thanks a bunch!
Are you looking to "play" an existing game, or write some sort of a game that can then be scripted?
If the former, you find that game's API and start writing code in the appropriate language. E.g. Unreal-powered games use UnrealScript and ship with the tools so you can embed new functionality. You're pretty much dependent on the game creators leaving an "in" such as this...
...unless you want to get totally nutty and hack the executable itself to execute your own code somehow. For information on how to do this, search for information on game "trainers". I'm not sure what a great set of search terms would be, but I know a lot of games do have trainers released, so type in "trainer <my_favorite_game>" and see what you get?
You can do this quite simply in Java 6.
expose your objects/functions in your Java app into the scripting environment
For example you can expose your character or the game world into the scripting environment and allow the script to control it.
invoke script functions/methods from Java environment
Allow the script to customize behaviours, add new actions, etc. Another use of this is to override the default build in game rules and load your own house rules. Another use is as a macro facility. Typically this would be part of the main game loop
use the script as a data/level file
For example, in a game likes SpaceHulk where it is mission based, you can use a script to define a game specific DSL, and us this DSL to define new missions. When the game starts up, it evaluates the data file and create a model of the game.
To integrate a scripting engine into Java, simply do this
ScriptEngineManager mgr = new ScriptEngineManager();
ScriptEngine jsEngine = mgr.getEngineByExtension("js");
jsEngine.eval("print('Hello world!');
To expose an object into the script environment
jsEngine.put("avatar", avatarObject);
//An avatar object is now available in myscript.js
jsEngine.eval(new FileReader("myscript.js");
To invoke a function in the script
jsEngine.eval("function hello(name) ... ");
Invocable inv = (Invocable)jsEngine;
inv.invokeFunction("hello", "Fred");
One of the problem with scripting is that, the script has access to your entire application. You can restrict what the script can 'see' by setting a classloader when you create the ScriptEngineManager instance.
Java 6 comes with a bundled JavaScript engine. However I prefer Groovy and loading Groovy basically mean changing 'js' in getEngineByExtension() to 'groovy'.
I know that a lot of people say that Java is not fast for games, but if you are writing turn based games or social games like Farmville then I think it is more than adequate.
For C/C++ based games, I think the preferred script engine is Lua. I've not used it so I cannot comment on it.
The best way to do that is to use the API provided by the game, if there is one. The Civilization games, for example, come with a very complete modding engine that allows you to script whatever you want. The same can be said for Age of Empires and a variety of other games.
Simple flash games, though? That'll be tough. Those don't generally provide any supported way to script, so you'll be left with simulating input. It'll be tough.
The easy way is to control mouse and keyboard functions with autoit. You can also read out information from your screen, but it is a bit limited It is good to just check if things changed or check whats on a certain area of the screen if you know there are a limited amount of possibilities. Not so easy to read and interpret text. Autoit is excelent to automate games like farmvile. I have also made blackjack bots for online casinos. And use it for small but mundane and repeating (manufacturing) tasks in RPGs. Dont expect to build an AI for an RTS or FPS though.
Autoit is easy to find with google. A fast and small download. Excelent documentation and you can learn it in days.
The hard way is what people wrote about above here i guess. Interacting with the game data. Searching information on that is what brought me here. I see its with C++ or Java. While the languages are all similar and you can use them all after learning 1, these come with complicated software environments that take lots of time to learn. The possibilities and chances to make something really reliable are much much greater though.

Language-Portable Example Programs

At the moment I am learning Objective-C 2. I'm aware that it's used heavily by Mac developers, but I'm more interested in learning the language at this point in time than the frameworks for developing on Mac OS X/iPhone (except for Foundation). In order to do this I want to write a few intermediate* console applications, but I'm stuck for ideas.
Most examples are something along the lines of "Write a Fraction class that has getters/setters and a print function", which isn't very challenging coming from a C++ background. I'd like some generic examples of programs, but I don't want them to include any Objective-C implementation details. I want to figure out the program structure/write my own interfaces and learn the language from there.
In summary: I am curious as to what example programs Objective-C programmers would recommend for exploring the language.
An example of an "intermediate" application would be something along the lines of "Write a program that takes a URL from the command line and returns the number of occurrences of a certain word in data returned:
example -url www.google.com -word search
"Project Euler" is a standard response for this kind of thing, but I get the feeling that you're less interested in being told to implement algorithmic stuff (since that knowledge is easier to port between languages) and more interested in miniprojects that will familiarize you with core libraries. Is this fair?
If so, IMO, you ought to know the basics of how to do the following with the standard libraries of language you hope to use for serious work:
Standard IO
Network IO
Disk IO and navigating the filesystem
Regexp utilities
Structured data (XML libraries and CSV libraries if they exist)
Programming problems I would recommend for those:
It sounds like you've already done this.
A very simple proxy - something like what you described in your post, but that listens on a port for a message containing a URL rather than taking it on the command line, and likewise returns the results to whatever contacted it over the network rather than outputting to stdio. [Obviously you need to have the machine behind an appropriate firewall for this!]
Something which takes a directory path and recursively tallies the number of lines its children contain. (So, get the directory's listing, open each child file and count the number of line breaks. Then open each of its child directories, get their listings, ...) Record any errors encountered (e.g., no read privileges) in a reasonable way. Write out the final results to file in the directory supplied.
Usually if I tool around in a language enough, I'll run across some problem which I just naturally find myself using regexps for. I'll assume the same is true for you and punt this element for now.
Fetch StackOverflow.com, and [by putting it into a DOM model and navigating that] determine whether this question is still on the front page.
I got the most out of Objective-C by exploring it with a testing framework. I have written a short blog post about it. You should also wrap your head around the memory management conventions employed by Objective-C, reference counting takes a little time to get used to but works very well if responsibilities are clearly segregated (I have written about that on my blog too).
By getting my hands dirty on a testing framework (GHUnit for that matter), I was able to learn far more about the language than I could have in a "traditional" way. Of course you'll need a little pet project, otherwise this approach doesn't make sense.
I don't think your example is a very good idea as it requires you to mess with http connections, resources etc. which is a little framework specific after all. Parsing a text file would be a little easier in this regard. Using a unit testing framework has the following advantages for you:
learn about platform specific build systems and deployment details
forced to develop components in a loosely coupled fashion from the ground up
thereby exploring unique mechanisms of the language, that might require new or make known patterns redundant (e.g. categories make dependency injection obsolete etc.)
fast compile-test cycle, less time spent in front of the debugger
combined with source control: painless experiments
You should also look into the testing framework implementation, as testing frameworks always require to work with metadata to some extend. Testing frameworks are often used together with isolation frameworks. They basically create objects at runtime that comply to certain interfaces and act as stand-ins for concrete objects. Looking at their implementation will teach you about the runtime manipulations that can be done in Objective-C (keyword: Method-Swizzling)

How do you write your QTP Tests?

I am experimenting with using QTP for some webapp ui automation testing and I was wondering how people usually write their QTP tests. Do you use the object map, descriptive programming, a combination or some other way all together? Any little code example would be appreciated, Thank you
Here's my suggestion.
1) Build your test automation requirements matrix.
You can use samples from my blog
http://automation-beyond.com/2009/06/06/qa-test-automation-requirements-usability/
http://automation-beyond.com/2009/06/07/qa-test-automation-requirements-usability-2/
http://automation-beyond.com/2009/06/10/qa-test-automation-requirements-5-maintainability/
http://automation-beyond.com/2009/06/08/qa-test-automation-requirements-robustness/
http://automation-beyond.com/2009/06/09/qa-test-automation-requirements-scalability/
2) Choose your automation approach
3) Write your testing scripts according to the approach you chose
Note. QTP Repository way or Descriptive Programming belong to GUI recognition part of front-end functional test automation. They matter in terms of robustness and maintenance.
Technically, it's nearly the same. In both cases you should understand GUI recognition concept well, or you will have problems no matter the approach.
You can store GUI object recognition properties in XML-like data structure and map the record to an English-like name. Whenever the original object's properties change, you update your record in repository, while a code still refers to a mapped name.
Or you can address GUI objects by directly putting same recognition properties into a function call. Whenever the original object's properties change, you have to do code change. But you don't have to maintain extra files along with your scripts.
A good framework should support both GUI-mapped and descriptive programming notations by operating at object reference level. I.e. you should keep object recognition and object interaction tasks separate.
Note that depending on context Descriptive Programming notation may slowdown performance of your scripts and it always demands extra maintenance effort while in other cases using Object Repositories only may lead to unwanted duplication of objects' descriptions or it may limit recognition of dynamically changing GUI.
I illustrate some points made above in the following article:
A little QTP performance test: Object Repository vs. Descriptive Programming
Straight code examples (for a practical automation I recommend GUI Function Wrapping).
Descriptive programming - addressing objects by physical description properties.
Dim sProfile
sProfile = "Guest"
Set objWebParent = Browser("title:=Select Profile").Page("title:=Select Profile")
Set objWebObject = objWebParent.Link("text:="&sProfile)
boolRC = objWebObject.Exist(0)
If Not boolRC Then
'error-handling
End If
objWebObject.Click
Addressing objects by mapped GUI names
Browser("Select Profile").Page("Select Profile").Link("Guest").Click
Thank you,
Albert Gareev
http://automation-beyond.com/
I know I am late here, and you must already have what you are looking for, but I wanted to provide my inputs as well for anyone visiting this topic.
I generally never use OR, unless I encounter an environment where Descriptive Programming is a no-go. Just recently, I worked with a Mainframe Front-End GUI application that has absolutely no naming convention for objects. If you choose to use Descriptive Programming with such an application, the only way to work with its objects would be through Index or Location Ordinal Identifiers, which is not the best course of action considering 100's of objects in each pane.
So, the answer to your question really depending upon the environment and your experience with OR and DP. Most people I have worked with at my job, and on online communities prefer to work with Descriptive Programming whenever its feasible. However, I have also seen people work wonders with OR.
I have a few code samples, but, unfortunately, they are deal with Descriptive Programming. For instance, the following article talks about creating modular VBScript classes to divide application's functionality into small manageable components:
http://relevantcodes.com/qtp-using-classes-as-test-modules-i/
Similarly, this article shows how Descriptive Programming can be used to verify multiple properties of target objects through a single block of code:
http://relevantcodes.com/qtp-verify-multiple-object-properties-an-elegant-approach/
Also, a demo framework is also available for you to view here:
http://relevantcodes.com/relevantcodes1one-qtp-automation-framework/
The framework is built completely on the principles of Descriptive Programming, but in the next release, some functionality will be added that will enable users to work with ORs as well.
Thank you,
Anshoo Arora
(Thanks for linking to the original articles, Motti)