AI for enemy in SpriteKit - ios

I have been making a game in sprite kit for some time now. I have added enemies and am wondering how I can control them around the map using AI(just like in any other game).
What I want is for the enemy to wonder around the TMX map, turning corner depending on random number. I have tried to do this but have run into many problems. Does anyone know of any articles that would help me with this? I have done some research. "PathFinding" and "A*" come up, but with know explanation or sample code on how to do it. Any help would be greatly appreciated.

Welcome to SO. Let me start by saying that I too am currently searching for exactly the same thing. Unfortunately the pickings have been kinda weak, at least what I found so far.
I did find a couple of very interesting reads:
An article on the ghosts behavior of PacMan. Simple but very effective.
Amit’s Game Programming Information. A more general discussion about making games.
Gamasutra. An excellent resources for all things game design.
Designing AI Algorithms For Turn-Based Strategy Games. A Gamasutra article which is extremely useful in explaining turn based AI in plain english.
All these are very useful in their own ways and make you think. However, nothing I have come across provides a plain worded explination on a bad guy's logic (the PacMan article came close). Searching Amazon for Game AI books yields a bunch of books which are extremely expensive and read more like advanced quantum theory.
I ended up deciding on a simple approach for my game. I have my bad guy decide between 2 possible states. Patrol Mode and Attack Mode.
In Patrol Mode he sits idle for a few seconds, walks left or right until he hits a wall or other object, runs (same rules as walking), climbs up and down ladders, and does the occasional jump. I use arc4random() to decide what he does next when his current action is completed. This provides a truly random behavior and makes the bad guy completely unpredictable.
Attack Mode happens when the player is within X distance of the bad guy. The bad guy now has a different set of actions to choose from. Run towards player, swing sword at player, jump up, and so on. Again I use the random function to make the bad guy unpredictable. The results so far have been really excellent. My bad guy behaves like one of those hard to beat 12 year kids playing Halo.
The bad guy will continue to do battle until he dies, the player dies or the player runs away and is no longer within the X distance required for Attack Mode. You can of course fine tune bad guy's behavior by limiting jumping, time between attacks and so on.
Hope this helps and got your creative juices flowing.

The Wikipedia page for the A* Search Algorithm here contains a psuedocode example. All you really need is an understanding of how the algorithm works then you should be able to implement it. Googling for iOS and A* brings up several tutorials.
You have a tile map so it should be relatively easy to do what you want without A* like this bit of psuedocode.
// An Update function for your Enemy
function Update
paths = GetAllPathways()
if paths.length == 0
TurnAround()
else
randomPath = paths.Random()
TurnTowards(randomPath)
endif
MoveForward()
end function
function GetAllPathways()
paths = new Array()
if CanGoForward()
paths.push(forward)
end if
if CanGoLeft()
paths.push(left)
end
if CanGoRight()
paths.push(right)
end
return paths
end function
An algorithm like A* is really for more complex things (not random decision making) where you
can have a complex or dynamic map and want your enemies to target something or the player dynamically which is where A* comes into play, determining a way through the world to find the path to it's target.

Related

Lua (Filter Forge) - Trouble implementing roll on a sphere with working yaw and pitch

I am trying to expand on something I had working using just yaw and pitch (rotation and tilt) controls for a mapped sphere. I added a roll component which works for just moving the sphere, but not for keeping the gradients used (via hsl conversion) coordinated with the movements.
Looking for answers online goes straight into math (still struggling with trig) I can't follow well enough to apply to this case. Code gets hashed when inserted. Here is the link to a trimmed down version of the script:
3d sphere v.0.0.1
I honestly do not submit questions with the intent to answer them myself. I just keep hammering at a problem until a solution presents itself. Often answers come via the Filter Forge forums, sometimes through online searches (and often other stack overflow questions I did not find before submitting my own), and more often recently through simple trial and error.
So, yes, I came up with a solution. I was right that the order of operations was the key. There are probably other, better solutions out there, so please share if you have one. It could help whoever finds their way here.
You can see my answer here.

Any existing in-game MonogGame/XNA performance stats / diagnostics info?

I'm in the process of creating a game using MonoGame and a fork-of-a-fork of Farseer Physics (https://github.com/alundgren04/Aether.Physics2D) and trying to push the physics to be able to process a very large world. In doing so, the on-screen statistics are invaluable: https://github.com/alundgren04/Aether.Physics2D
Many of these came with the physics engine, and others I had to add. I'm wondering if there's something similar for MonoGame. Something which would show each frame how many polygons were rendered, how many sprites, etc., and how long each took. This would be analogous to the physics info where it lists both the number of "Bodies," "Fixtures," "Joints," etc., and the time it took to up date each of them.
See screen grab here: https://i.imgur.com/5RdOlay.png
I see the total physics update time is around 3-5ms yet the game only appears to be rendering perhaps once a second or so (1 fps). This points to the rendering being the bottleneck in performance, and I would like to have thorough diagnostics before beginning the optimization effort. I could build it myself, and may end up doing so, but I'm hoping there's a built-in solution I can at least use as a foundation.
Thanks!
GraphicsDevice.Metrics returns rendering information when you draw. It's reset whenever Present is called. While it doesn't mention how long everything took, it still contains information that should help with debugging your issue.

Xcode Mass Multiplayer (Not What You're Probably Thinking)

Okay so I would like to make a game, I'm trying not to divulge what it is but it requires anyone of a certain level in the game who is currently playing to be able to see each other in a sort of MMO style but not really.
For example:
Suppose I have players Bob, Mary, and Rob. Suppose that Bob is level 4, Mary is level 6 and Rob is also level 4. These would be shown in leaderboards by the way. What I would like is for Bob and Rob and anyone else who is level 4 AND CURRENTLY PLAYING to see each other in a sprite kit seen. I would like Mary to be off with other level 6's.
I have little idea of where to start with this. So my questions are:
Should I even use Xcode or would I be better off using Unity?
Does GameCenter have the capabilities for this or would I need to use Parse or something like that
And also, could you please point me in the right direction as far as the concepts of how this would work?
If you can answer any of this that would be AWESOME!!!!! If not that's cool too! Thanks in advance!
Xcode is an IDE and Unity is a Game-Engime.
If you need to create your own game since the beginning, you should use an IDE. But this is really LONG and sometime difficult. With a Game-Engime, a big part of the game is already programmed (physic, 3D animations...) so you can focus your time for program your game.
Game Center is for share a game or a score. Not played online.
For play online, you should create your own server.
Do you know how to program? Are you good in 2D/3D?
For create an MMO game, you must be logic.
First, you should create a client.
The client is the game
He contain the sounds, the graphics, the scripts...
Second, you should create a server.
The server is connected to all clients.
He contains the databases (Accounts, characters, HP, gold...)
So where started?
When a character move (from the client A), he send his new position to the server. The server send this position to all the client. So the client B know where is the character of the client A and can draw a tileset (in your example, you can draw the tileset only if the boolean sameLevel is true).
Take a look at the sockets:
http://www.linuxhowtos.org/C_C++/socket.htm
http://www.nullterminator.net/winsock.html
https://stackoverflow.com/questions/tagged/sockets%20c%2b%2b
https://stackoverflow.com/questions/tagged/sockets+c
Hint - I have already answer at some similar questions. Even if the programming language are sometime different, I give you the link, the logic is always the same so it can maybe help you:
Creating a Multiplayer game in python
Multiplayer game in Java. Connect client (player) to game that was created by other client
How would an MMO deal with calculating and sending packets for thousands of players every tick for a live action game?

XNA - Starting a platformer

I have followed the MSDN Platformer tutorial and made a variant with it.
However, I want to make a Platformer like the Super Mario games. Although I prefer to make a game with a basic level, instead of a side scrolling level.
I've read certain documents about using Tile grid to create my levels. Are there also beginner/full tutorials available to create a start?
Basically need help with the first steps of setting up a level.
Greets
I have not used XNA for about 6-7 months, but back when I was 'playing' with it, I was working on Windows Phone 7 games and learned a lot from this blog over here. His tile engine worked pretty good for me.
Although it looks like it is for RPG-like games, take a closer look at the examples, there is a 2D platformer example there too.
You must read this, otherwise nothing will make sense :)

iOS / C: Algorithm to detect phonemes

I am searching for an algorithm to determine whether realtime audio input matches one of 144 given (and comfortably distinct) phoneme-pairs.
Preferably the lowest level that does the job.
I'm developing radical / experimental musical training software for iPhone / iPad.
My musical system comprises 12 consonant phonemes and 12 vowel phonemes, demonstrated here. That makes 144 possible phoneme pairs. The student has to sing the correct phoneme pair 'laa duu bee' etc in response to visual stimulus.
I have done a lot of research into this, it looks like my best bet may be to use one of the iOS Sphinx wrappers ( iPhone App › Add voice recognition? is the best source of information I have found ). However, I can't see how I would adapt such a package, can anyone with experience using one of these technologies give a basic rundown of the steps that would be required?
Would training be necessary by the user? I would have thought not, as it is such an elementary task, compared with full language models of thousands of words and far greater and more subtle phoneme base. However, it would be acceptable (not ideal) to have the user train 12 phoneme pairs: { consonant1+vowel1, consonant2+vowel2, ..., consonant12+vowel12 }. The full 144 would be too burdensome.
Is there a simpler approach? I feel like using a fully featured continuous speech recogniser is using a sledgehammer to crack a nut. It would be far more elegant to use the minimum technology that would solve the problem.
So really I'm hunting for any open source software that recognises phonemes.
PS I need a solution which runs pretty much real-time. so even as they are singing the note, firstly it blinks on to illustrate that it picked up the phoneme pair that was sung, and then it glows to illustrate whether they are singing the correct note pitch
If you are looking for a phone-level open source recogniser, then I would recommend HTK. Very good documentation is available with this tool in the form of the HTK Book. It also contains an entire chapter dedicated to building a phone level real-time speech recogniser. From your problem statement above, it seems to me like you might be able to re-work that example into your own solution. Possible pitfalls:
Since you want to do a phone level recogniser, the data needed to train the phone models would be very high. Also, your training database should be balanced in terms of distribution of the phones.
Building a speaker-independent system would require data from more than one speaker. And lots of that too.
Since this is open-source, you should also check into the licensing info for any additional details about shipping the code. A good alternative would be to use the on-phone recorder and then have the recorded waveform sent over a data channel to a server for the recognition, pretty much something like what google does.
I have a little bit of experience with this type of signal processing, and I would say that this is probably not the type of finite question that can be answered definitively.
One thing worth noting is that although you may restrict the phonemes you are interested in, the possibility space remains the same (i.e. infinite-ish). User training might help the algorithms along a bit, but useful training takes quite a bit of time and it seems you are averse to too much of that.
Using Sphinx is probably a great start on this problem. I haven't gotten very far in the library myself, but my guess is that you'll be working with its source code yourself to get exactly what you want. (Hooray for open source!)
...using a sledgehammer to crack a nut.
I wouldn't label your problem a nut, I'd say it's more like a beast. It may be a different beast than natural language speech recognition, but it is still a beast.
All the best with your problem solving.
Not sure if this would help: check out OpenEars' LanguageModelGenerator. OpenEars uses Sphinx and other libraries.
http://www.hfink.eu/matchbox
This page links to both YouTube video demo and github source.
I'm guessing it would still be a lot of work to mould it into the shape I'm after, but is also definitely does do a lot of the work.

Resources