Building an XNA Game Studio XBox360 Indie Game.

[page 0045] ~ For the Espionage:

Grace Period: 48 hours.


But first, off to sleep, off to dream.  I awake happy, but in something of a quandary.  I found my Dad last night or maybe he found me.  He said something unintelligible, I replied “What?”  Again something was said but this time I could kind of hear words not just vocal noise.  Then he said something where he would let someone know and mentioned what I thought was a name and we grasped hands in a Greco-Roman Knuckle Lock, a hand clasp.  He laughed and said he understood.  My Father had passed away a few years back, so to see him again, well, made me glad.  When I awoke I felt rested in the knowledge of remembering such a fine gentleman albeit again in a dream.  Only God knows how that all comes to be.  More hmm, so be it.  Now back to the game.


Pursuing the Transcendence.


I have this chess game up and running and there are a couple things that need to be addressed.  Like, what happens when a pawn reaches the other side of the board where it is transformed into another piece.  Then there is en passant, where a pawn can take another piece on its first move of the game unlike any of its further moves beyond that of its first move.  But that and other puzzles will find their spotlight in due time.  And with that duely noted, the theme, philosophy, which is to be incorporated into this game, has finally been built to the point where it is close enough to be ready to and start expressing the philosophy of espionage.  In its simplest terms, espionage is the act of spying.  But in this game the espionage will be overt.  The pieces move about the board within their own capacity.  Each has an algorithm that it follows and that is where, within that movement plot, the overt traces of espionage will be seen.  I had gone through this in part previously while testing the graphics that will be shown on the chess board.  When a piece is selected it makes a call to the draw method where the prospective moves are given and are drawn to the screen as the result of that call.  There are six different pieces, but for as simple as it may seem to have its movement shown, there are many external factors that may inhibit its movement, possibly to the point of that piece not being able to move at all, check mate.


Climbing Through the Ranks.


I have built the void stub functions for the six piece types.  So seeing that the pawn is one of the first pieces to move, I’ll try to work through the pawn and the drawing of its overt movement plot.  I left click on a pawn and it becomes highlighted.  If it is its first move, en passant will also be one of its actions.  A boolean flag set in an array is the best way that I can think of to have this denotation become apparent.  Back to the code page.  Two arrays, one for either house, black or white, may make the searches needed easier to work with. And the name of the array?  EnPassantWhite and Black should suffice.  The variable array is declared in the header and then given their assignment to false in a for/loop for each of the eight pawns in the setup function.  For all practical purposes the pawns are initialized so they are now known to have not moved since the beginning of the game.  Something that has come to mind is, what if a player moves the piece but then decides that that was not the move they wanted for that turn.  I will be leaving that up to the players, but from what I can recall the rules are, “What is laid is played.”  And with that I won’t be adding any undo for a piece that will reset the boolean flag if that situation were to be a result.  I can’t build an all inclusive application, not now, not here.  But to get on with it, where does this flag get set and where will it be used.  I’ll need to put the training wheels back on in my program to find which variable I can use to set which pawn is being moved.  These are just draws to the screen to print out the values of different variables in the different states of game play.  I’ve got’m, so I might as well use’m.  Ok, once again it is somewhat complex but still doable.  The code is dropped into MouseIsDownRight and set so if a SetPiece is 1, that being a pawn, the boolean in that array coinciding with that piece is set to true, it has moved this game.  Now off to the pawns draw function.  Using those flags makes those square highlights easy to draw.  One thing I can now see is the coverage that the pawns can give all the way up to mid field at the start of the game, very staunch, stalwart.  But there is one last thing that I’ll need to do.  When a pawn is on the boarder of the chess field either to the far left or right, there are no tiles there and therefore no need for the highlight.  another thing is that when a pawn is taken, the highlight remains and is shown, if it is selected in the out-of-play sideline.  Also at the far side, when the pawn has reached the line where the Crown pieces are initially set on the opposing side of the field, the pawn can no longer move forward and there the highlight is again no longer needed.  So I have these three variations that need to be taken into account.  One more thing is that a pawn can move out of position, being a side step to either side of its starting point.  This can bring it closer to either of the side boarders of the chess board and again will give it no need for those nonexistent tiles to be highlighted.  With all that said . . .  back to the draw function of the pawn.  Hmm, AND how to keep a piece from landing on a piece of the same team.  But this question will be relevant later on when drawing out the prospective movement plots for the other pieces and so will some portion of these many other puzzles, ok, I’m good, let’s go.  I’ll take on the same team situation next.  Two variables AllyX and AllyY are two good names.  And what values do they need to be useful.  Another exhaustive search to flip a flag called SameTeam.  That adds more code to MouseIsDownRight but an allied piece can no longer move onto a tile from the same team.  Another problem that needed clearing up is that when a piece is selected and then the mouse pointer is positioned outside of the chess board and clicked, that piece moves to a spot that is most closely matched to the values of the board in concern to the tile grid values.  This has been fixed so that when any point outside of the chess board is clicked it no longer registers as a valid position and does nothing.  When a pawn gets to the other end of the chess board so (PawnPromotion == true) the player may pick one of the taken pieces to replace it.  Time for a save #10.  That was time intensive.  All the draw stubs have the general draw algorithm needed to show how that piece will move on the chess board.  The Pawns have their first move to include en passant, the Rook moves horizontally and vertically, the Knight has eight possible tiles to move to each turn the Bishops move diagonally, the Queen moves both horizontally and vertically and also diagonally, and the King can move in any of the adjacent tiles.  All that and the draw got an upgrade so it can be seen more clearly on the light and dark checkered tile layout.  And so with all that done, save #11.  Wow, it looks like the rules for en passant are different than the rules elsewhere, oh well.


Grace Period: 24 hours.


Eat and do dishes, eat and do dishes, eat and do dishes sleep, that and a whole lot of coding.  Save #12.  Now that the moves of the piece can draw to the screen they will need to be refined.  At this time the highlights that radiate from the piece that is set to move can spill over the edges of the chess board.  Getting these to stay within these boarders are what comes next.  I started out with the King.  This is somewhat labor intensive because of the calculations involved.  Each move that is possible, while keeping the next move on the chess board, needs a succinct bounds check.  The King can move horizontally, vertically and diagonally but can only move one tile per turn.  That makes eight tiles, and in the PlotKing() function means eight bounds checks.  But there are two kings in the game, one white and one black.  And as what may have been guessed, yes that means when the other piece is to be selected to move, that piece also need to be bounds checked as will be for all of the pieces, of either side.  The code page is starting to expand because of the code that drives this bounds checking.  The next piece will be the Queen.  But first a save #13.


Time for Introspection.


The queen has a similar movement plot as the king except for the fact that the queen can move in a strait line across the board as far as possible.  This might be the time to use a while/loop seeing that I really don’t know what all of the formats are that will come into play as the queen moves across the board.  Seemingly, starting with the king was a good idea because the queen was relatively easy to implement, only a change to the for loop with no need to use a the while/loop.  The Rook and the Bishop were equally as easy to place into the plot functions of those pieces because those are a subset of movements of the queen.  Now back to the Knight and the Pawn.  These two pieces move differently than the other four pieces mentioned above.  I’ll start with the pawn because it resembles the movement of the king but in a limited capacity.  En Passant, is not the move that I had believed it to be.  So I’ll be reformulating the structure of the function call that had previously represented it.  I kinda like my version of it and I’ll keep it in mind and see what others think, just for fun.  But again another save #14.  I’ve simplified the pawn movement and it is aligned with the currently upgraded pieces.  The Knight is next  Using the existing algorithm and applying the constraint has made the testing process easy to do, there are none.  Save #15.


Things In Things.


Clicking on any of the pieces will show the full potential of the piece while keeping their movement plot on the chess board.  What does become apparent is that that potential is not necessarily what can be obtained because the selected piece may be blocked.  It is currently blocked by the boarders of chess board itself, but the constraints in concern to the other pieces that remain on the board have no bearing while that plot is draw to the screen.  And so, things in things, the constraints in constraints.  I have done something to this effect when I kept a selected piece from moving on top of a piece of the same team.  I’ll check out this portion of the code and see if it is reusable in some fashion or capacity.  I found the Self and Ally check structure and the best place to start would be where I had started before, with the King.  With another function void PlotAllyExclusion() I might have some success.  I’ve also built a function stub called void PlotFoeInclusion() where a further set of constraints will be found.  Well then, it seems to work for one of the tiles occupied by the same teams piece, now to see if the same addition to the next call yields the same results.  Ok, let’s press a little further into that calling function.  Yes!  Now that is starting to look pretty cool, programmatically drawn movement plots, oh yeah.  But parenthesis are in high demand.  And with that, time for another save #16.  Now to test all the possible positions of the King on the chess board.  It works as intended so off to the other King.  Hmm, nothing.  Got it.  Now for the Queen.  Oh that silly queen.  The algorithm works, but, the line of movement for the queen, because of being blocked at some point along the way by an allied piece, does not stop.  The line continues again past that allied piece that is blocking the way.  Back to the drawing board, so to speak.  The question is how to preclude the advancement of that directed line of movement when it gets to the point where it is blocked?  I’m kinda getting it to work with another flag and a third argument in the function but now if an allied piece is in the way it blocks the entire line of movement.  It looks like I’ll need another array to hold the point in the for/loop where the cut off occurred so when that point is reached during the next draw call there will be a flag that denies access to the draw call.  So if instead of having a boolean flag I changed that to an array of integers and have that then set from the next for/loop run through it will be larger than the value set previously and therefore the call will be disabled.  Let’s give it a go.  But only if I add yet another argument to the function so it looks like this, void PlotAllyExclusion(int X, int Y, int Z, int valJ).  Yikes!  But it seems to work, and now for the other parts in the queens function.  That’s looks good.  I also dimmed the chess board when a piece is selected to move.  I did this because there was too much screen clutter and the intended espionage was clouded under the “fog of war”.  Save #17.  Things seem to be going well enough so I’ll add all those trappings to the other pieces functions.  Done, 2564 lines of code to get this game up and running.  Save #18.




Grace is good, and so is this chess game.  Thick with code and philosophy of espionage.  Each move gives the other player just what they need to know what they will get in return.


Until then,


September 4, 2013 - Posted by | 2013 [0019] to [00??], The Process

No comments yet.

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s