I am designing a chess-like game but I believe this question can be extend to all games that have battle.
So my question is, how should I properly label an object as a friend
object or an enemy object in a battle game?
Take chess for example. If player W plays white pieces, then W's opponent, player B, plays black pieces.
For W, all white pieces are friend objects and black pieces are enemy objects, while player B has black friends and white enemies. So here my labeling problem can be simply solved by using colors. When you try to calculate the possible moves of a piece and decide if you can take out a piece, you can basically check if they have the distinct colors.
However, what if two players have the same view? For example, a game can color all friends as black while color all enemies as white, and the players start their games with their pieces all at the bottom. In this sense of speaking, indeed, pieces can be viewed as the attributes of the player. So the coloring of black and white is based on whether a piece has an owner id that is the same as yours.
Here comes a problem:
Although I can decide the color by comparing the ids, what if I want
to know whether a friend piece enters the enemy region?
The definition of enemy region could be the upper part of the board. Since board is not part of the player (while pieces can be), it is not possible to use the previous id solution.
So one possible solution I can think of is to make the board an attribute of the player. However, there are two players, this doubles the data storage because we have actually only one board from an objective perspective. And any moves and further changes on a piece requires operations on two boards, which is also time consuming.
In order not to double the board, I try use to another strategy, which is to use a landscape view. What I mean is that, the data doesn't take sides as players. Players view the board from bottom to top, which is like the portrait view, while data can be viewed from left to right/right to left like what a just referee observes. So the data becomes objective here. But the problem is how to present the objective data in a subjective manner to players? And it is still not easy to know if a piece enters enemy region.
So my question is, how should I properly design the data structure, so that it does not doubles or triples or copies multiple times of the data, and in the meanwhile, it is also easy to know the labels of a public area? In my question, the public area is a chess board, where all pieces should fight on this single board. I call it public because both players can move their pieces to everywhere on the board, and third parties can also see what's going on the board. But the labels of pieces are just subjective attributes, personal private thoughts.
I am not sure if I can properly explain/phrasing my question well so I didn't search for a similar question. Sorry for my laziness. If there is a duplicate question that has been asked, please guide me to it.
---Update---
I think a more clearer question is, let's say I have 3 * 3 board. If I need to move my piece from (1, 2) to (2, 3), then in the perspective of my opponent, the move is not taking place at the same location. It is the opposite. It is from (3, 2) to (2, 1). What is the best way to store this move? Do I have to take one side (subjective) to store it, or is there a neutral/objective way to do this?
The drawback of the subjective way for me is that I need to recalculate the moves for another player to fit his/her view. Using a neutral way might be a life saver.
A general answer without concrete database design - There is data an there are multiple views. There is no need to copy data but to have multiple references to some data (which of course also takes some memory). E. g. a rook is referenced by a square and by a player. Such references may be stored (collection "enemies") or may be calculated on the fly (collection "reachable") depending on runtime/storage design decisions. Also multiple players are just views. On a game move you have to update all static views while dynamic views need none.
For symmetric games there is the possibility not to store the opponents views but generate them by just transforming the whole game into the other players view with every move. Again this is your decision, stored vs. dynamically created.
If I need to move my piece from (1, 2) to (2, 3), then in the perspective of my opponent, the move is not taking place at the same location. It is the opposite. It is from (3, 2) to (2, 1). What is the best way to store this move? Do I have to take one side (subjective) to store it, or is there a neutral/objective way to do this?
Pick one orientation for the board. It doesn't matter which one you pick. This is a neutral/objective way -- neither choice offers any advantage for either player, and the choice doesn't significantly affect the code. Any imbalance you imagine, like that it's better to have (0,0) on your own side, is imaginary.
This is not a "subjective" choice, it is an "arbitrary" choice.
So I'm trying to make a game that's similar to the game GO. Essentially I've got a grid of faces, and when you click on a face they turn your respective color (red and blue). You and your opponent take turns clicking on faces to color them your respective color. When any amount of faces are surrounded by faces that are of all the same color, then all the faces that are surrounded are deleted from the board, and the number deleted is added as score to the player whose color surrounded. And if you tap a face twice with the same color (so red face is tapped by red again) then it bursts leaving residue around that face's surrounding faces making it so those residued faces can't have their color change to the other color that's not the residue color.Now my hope is that I could get a slightly working AI, it doesn't have to be amazing or anything, just good enough to make decently intelligent moves and could possibly win. After doing some research it seems that using a MiniMax algorithm would be my best bet, but I have no clue how to create such a thing in unity. I was hoping someone might have some insight on how to accomplish this, or does anyone have a better idea of an algorithm that would be better in determining moves?
Thanks for the help!
This is horribly broad question, however - one of the most succesful approaches to the board games AI (especially GO) is UCT based approach. It is a monte carlo driven heuristic approximation of the minmax algorithm. MinMax requires game's state space to be very small in order to fit in both memory and time constraints. UCT on the other hand can make reasonable moves in any given amount of time (it is fully iterative).
I'm coding a GameBoy Advance game in C and I'm trying to come up with the most efficient way of spawning enemies. The game is going to be similar to SpyHunter (http://en.wikipedia.org/wiki/Spy_Hunter).
The problem is that I don't know what would be the most efficient way to have randomly appearing enemies at the top of the screen and never have more than 3 or 4 at the same time on screen.
I thought about creating 4 structures at random places at top of the screen and as soon as one reaches the bottom initialize it again at the top and so forth using random positions but I don't know if this would be the most efficient algorithm.
How should I spawn the enemies?
The algorithm you outline does seem quite efficient.
You are only allocating memory for the actual sprites you wish to have on screen. You'll need to track their position down the screen anyhow to properly render them. Once they are off screen, you are re-using existing structures. Doesn't get much better than that.
One thought would be to randomly delay some period of time after a sprite goes off screen before re-initializing it at a random position at the top of the screen again. This would lead to some variability.
I am working on a simple soccer simulation, I am using potential fields for collision avoidance more specifically following technique,
http://www.ibm.com/developerworks/java/library/j-antigrav/
only obstacles on the field are other players and they are constantly moving. Problem is it works if I assign really big push force to the characters since characters move at speed it takes some time to change direction but this has few drawbacks with such a high gravity I can never position an npc to grab the ball cause there is always some force pushing me around.
I though I could solve this by assigning pulling force to the ball but that actually made it worse. nps would go to the ball, ball starts pulling which makes npc push the ball it goes into a loop until npc crashes to a wall.
How I've implemented this is, I have a vector that would steer me towards my target then I add to that all gravitational forces acting on the npc and steer towards that direction.
Basically I am wondering what kind of improvements I can make? my current problem is not hitting other players precisely getting behind a ball without getting affected by other players.
I'm not sure that employing potential fields is the way to go here. If all players are directly between you and the ball, how do you get to it?
I'd be tempted to plot a straight line, then iteratively adjust the route for the position of other players, adjusting for their trajectories and — if you're really clever — anticipating changes in the same.
You could put some kind of limit as to the area of effect that another player's gravity well will have. Limit it to a small radius around that player so that when you're clear of other players, there are no forces acting on your character. You could also diminish the collision avoidance force when you're near the ball, reasoning that players care less about not hitting each other when it's time to kick the ball.
I have read about using CompositionTarget.Rendering Timer for the primary gaming loop in silverlight. To be used for hit testing and general game logic as would be done in any language.
This said I was wondering is it best to move objects around inside this x pixels at a time (as a game in any other language) or can I utilise silverlight animations better and use such features as easing?
The objects I refer to would be in games such as tetris and pong rather than a platform game where the user is moving a character around.
The other area is sprite animation. For example is a walking animation done best with the gaming loop changing frames or keyframe silvrelight animations?
here's a really good source for information about game loops in silverlight
http://blogs.msdn.com/nikola/archive/2009/08/19/exposed-5-methods-to-create-game-loop-which-is-the-best.aspx
To address the core of your question ... I think it all comes down to the content pipeline. What I mean by that is that you should ask yourself. Which method makes it easier for the content creator (which may or may not be you) to create animations? For the most part, you want to optimize for that process, which for many games takes longer than the actual programming, and is done by less technical folks.