Building an XNA Game Studio XBox360 Indie Game.

[page 0049] ~ AI ~ Prelude:

Updates – just Windows.

And the theme this month is ???.

Pheromone Fantasia.

Now that everything, or nearly everything, is set up so that, from the programming, the concept of chess can be mnemonically conveyed from the code page to the computer screen.  From there I can begin to delineate the basic assumptions and leaps of faith a human player would use to play the game, from what a Reactionary AI and its accompanying algorithms, would need to collate, compare and correlate what can be done with what needs to be done to play, and hopefully win, a game of chess.  So far this game can be played by people who understand the concepts of chess.  That being said, it cannot be played, at all, by an Algorithmic Reactionary Artificial Intelligents.  Seeing that I haven’t built an ARAI, (spoken: “are-eye”), before and have no idea of where to start I will use a strategy from the Music Man, the “Think System”.

BackUp_00, Start this game with “X ~ Change” as its base template.

BackUp_01, the first thing to do is to clean up a few more items.  Speed is always a good thing, or at least alleviating the necessity for needless waiting, so then to have game play where it then seems to be moving along more quickly than before.  The possibility to have the game move just a little bit faster than practical would probably be good enough.  The first thing I can think of is, if I were to select a piece to move, but then change my mind to select another piece.  Currently, to select another piece I need to right click on the same piece, which the game considers not exactly a move but a trigger to rescan the chess board and thereby wastes just a little more time with each calculation because of the reselection.  What I may be able to do here is to check to see if the starting location is the same as the finishing location and if they are the same, bypass the scan, because the pieces on the board have not changed.  Nothing has changed so nothing needs to be checked for change.  But, what variables would be needed to do this and where would this check of equality take place.  Then further, how would this information be given to some position in the code so that it would not disturb the regular flow of logic that would transpire from what exists as normal game play.  Per usual, I’ll start off with some more global variables, it’s simple, they are easy to access and stay resident throughout the game.  What I’ve noticed is, is that one of the if() statements has some arithmetic computations going on inside of it, which may or may not be any big deal.  But, prior to that if() switch I may be able to consolidate that computation into one variable and give that to the if() statement and as a bonus, have that variable accessible for what I am trying to accomplish, which is adding speed within the playability.  Once again it sounds simple, in theory.  One other thing that needs to come under consideration is if or when those global variables need to be reset.  At second glance it seems that the variables I’m looking to utilize are only used as an output to the screen and are not in the if() conditional itself.  So working my way back up the function chain I find where they originate and may be able to create the variable contents there.  This would make two variables from that same point that are built from and of the same meaning but would then diverge from that point to be applied for differing usage.  For good or ill, that’s how I will work it for now.

OK, the variables have been switched out W/B SP X/Y 1/2, being four sets of coordinate pairs (WSPX1, WSPY1), (BSPX2, BSPY2) … , and still have the results appear on the screen that still look the same.  Now to find the placement where a check for either a conditional function that brings about the full chess board scan begins, or to find if it is found somewhere else in the body of logic that streams by perpetually and occurs without trigger with each draw() call of the games cycle.  So what is supposto happen?  I left click on a piece to select it.  The mode switches over to single piece view.  Time is ticking away. My strategy changes because I notice something more advantageous.  Here?  I would like to change the piece I am currently working with and must change to another piece.  Yup, here.  I right click on my same piece, and I have some time wasted by waiting while the scan goes off rereading what is already known and will not change the outcome of this turn, a non-move.  What I would like to happen is, I right click on my same piece and the game recognizes that the origin is the same as the destination and there is nothing that needs to be rescanned, and so it doesn’t.  That right click on the same piece in the same position will immediately allow me to left click on another piece and enter the game state where a single piece view mode becomes available again.  Sounds good, but where, and how.  And for some reason, I hear Jabba the Hutt laughing in the background, “Muwah hoah ah ha ha ha ha”, slowly and ominously.  The way it looks, after the right click on the same piece, I’m given the chess board tile piece coordinates almost immediately in the bottom left or right sides of the game screen, then thereafter the scan goes off.  So there might be a chance to place a, “hey you don’t need to scan”, flag, somewhere before it does start the scan somewhere around there, maybe.  Yes I will try that old Jedi mind trick, “These are not the voids you are looking for, move along”.  But first to move all of the Pawn_3.mask(Pawn_2); and similar piece stuff into the setup(); function so it is only accessed once.  Oh yeah, this will take a while to refigure out.  There is nothing obvious as to where this flag might be set.  There is a mouseButton == LEFT in an if() switch inside another that might have potential.  But no, and yes.  The check, it seems, is to be put inside of, void CurrentlyMoved(int X, int Y, int House, int Piece).  And from playing a couple of games, with the change in position of, DualScan = 0; from void mousePressed() : (mouseButton == RIGHT) to the function CurrentlyMoved, the apparent game play does move slightly faster.  Now, when a piece is selected and then clicked on itself again to be deselected, the full chess board scan is not activated and by the simple nonfunctioning of a function and not doing something in lieu of actually doing something the concept of speed is given to the players of the game.  Now that that is done, what comes next?  How about another save.

BackUp_02, done.

BackUp_03, now that this chess game is a little bit faster and continues to work with no new noticeable errors from this upgrade, I’ll need to start thinking about a data backbone as some type of grid and/or array matrix that will store which pieces are moved each turn.  Right now I can’t think of any type of AI that would have any way to “see” the game beyond some random movement schema.  For all practical purposes any AI for this game would be quite blind and conceptless in concern to what is to be achieved or expected of it.  But before anything like this will begin to happen I’ll need to build something where, I either can’t have a King move into check, which may prove to be a somewhat difficult thing to do.  Or I could build something that will let me undo a move out of check that has put me into check from a piece moved out of the way and which may have taken another piece off the board and thereby put my King into check, another invalid move.  In either of any case, I’ll need to address this issue and a couple of more issues before I get into an AI pipeline production model.  But, this King/Check issue would more than likely come from some variable array that will store the piece movements for at least one turn prior to what needs to be restored.  So, to get the chess board back to how it was before the erroneous move was made sounds like something that would be useful in the short term and possibly in the long term for that AI stuff later on.

Ok, what do I want to do today?  What is the game plan.  Where to start.  Well, the game is initialized and asks which team will begin with the first move.  At the starting point, without giving any thought about what variable arrays will be holding any of this supposed AI information, I’ll just think of what and how the forthcoming scenario will commence turn by turn.  And the first thing that comes to mind is another little tweaker tool that would be helpful up top within the time line area.  Having a < or > sign in either black or white on either side of the count down time to Victory timer, might help the players keep track of which direction that timer is moving for whichever player is currently active.  The way that timer is set up is, when the time has moved into whites side of the timeline the timer/counter is drawn in white even though black is the active player and visa versa.  And, that time would then be greater than 3 minutes and 30 seconds, which is the center mark for the timeline.  As it is, the timer always counts down from any time that is less than 6 minutes and 59 seconds.  When that timer reaches zero on either end of the timeline the other team wins.  OK, that’s done, so now there are two arrow heads, one black that appears when it’s blacks turn and one white that appears when it’s whites turn.  The black arrow head is, instead, positioned to the left of the light gray full game time timer, which is the centered top most timer, while the white arrow head is also positioned to the right of that same timer.  It does provide a little more clarity as to who is going that turn and which way that timer is running when the Minimal HUD is the only utility that is being used and seen on the game screen.  This is good enough for BackUp_03.

BackUp_04, having gone through this timeline directional addition, and having been left and right clicking on the same piece over and over while watching the results, I’ve noticed that the semitransparent green “Next Move” signal is not quite right.  A more appropriate term would be “Next Turn”.  But after a little research the term “Move” does seem to be sufficient because, for most rules of play, a move does signal the end of that players turn, and therefore is the action that relinquishes that turn back to the opposing player.  Move stays, Turn, not, done.  But there still is a problem here because at each start of a players turn the “Next Move” signal and button is not viewable, but once a piece is moved to another tile the “Next Move” signal appears, which is good and how it should be.  Then, for some odd reason or other, probably because I haven’t worked on that part yet, if that piece is selected again and then unselected, just because or just to see what happens or what would happen, while not moving, the “Next Move” signal and button disappears and does not reappear.  The game then, in so not doing, makes the current player unable to leave the board open for the next player to select any piece.  The table becomes locked with the current player and leaves that same teams timeline active to tick against that player moving towards the opponents Victory.  Hmm, what to do.

I think I’m finally getting to the point where only a few more puzzles are missing, sure.  And shortly after that point I’ll be able to begin to start working backwards into the information given and collected, where the games AI will begin to take shape.  But until then I think I’ll need a couple of other checks and flags to wheedle this puzzle into submission.

So, I left click on a piece to move it.  The screen changes to the view single piece statistic mode.  The path that that piece is able to take is shown.  The name of the piece is shown in either of the upper corners of the game screen.  In the lower corner is the Start position with a picture of the piece that is selected.  The Finish position is empty, (  ,  ).  The selected piece has the cyan selected wide square highlight around it in the tile and a thin Start move highlight directly inside the cyan highlight.  The next thing to do is to move that piece somewhere along the available paths seen on the chessboard.  The mouse is positioned over another tile and the right mouse button is clicked.  The automation process begins and the piece moves from the Start position to the Finish position.  The Finish position, in either of the bottom corners of the screen is now filled out with the actual coordinate pair, (x, y).  The Selected Piece highlight is turned off, because the piece is no longer selected.  The automation has deselected it.  The Start position highlight tile still has the highlight on, although the tile is now empty, and another highlight, the Finish position highlight, surrounds the piece that has just moved to the new tile position.  At that point the “Next Move” signal and button becomes viewable.  That’s a lot of stuff happening just to move a piece on the board, and also to get me to this point so I can begin to correct the affor mentioned idiosyncrasies that are posing these newly observable problems, whew!

But of course there is more to do, such as, figuring out what needs to be done with what and where that what, might take place.  Then there is the creation of some variables, and to give them their names to reflect the facilitation for just which what needs to be done where.  Once again I’m thinking I’m done with the administrative, yadda, yadda and will be getting back to the fun stuff, management and supervision, so I can tell myself what to do, with what where, and hopefully how, shortly.

Kinda getting back to the build, the “Next Move” signal and button can become nonviewable.  This is a major flaw that a human player may run across and one that needs to be rectified.  But how.  What needs to happen so only one move of one piece will become a valid registered move.  Thus far the game itself is built to be manipulatable.  Many permutations and combinations are currently possible, although not valid.  Any piece of one team can be moved to almost any tile on the board.  A path for any given piece of that particular type is shown on the game board, when selected, but there are no rules that state that those paths are the only place that that piece may move.  Validity of piece placement are still conceptual in nature.  An ARAI will need rules that are to be followed so there will be consistency when an ARAI moves a piece on the chess board.  The ideals of the upcoming ARAI are beginning to show themselves, and those rules will be many and varied.

For simplicity sake, lets start out with two ARAI’s playing a game of chess.  The ARAI’s will not be the ones to start the game, but once the game begins they will “see” the game as a set of rules that run to their logical conclusion.  The three major conclusions for this game of chess will be: 1.) Victory, because time has run out for one team leaving the other team victorious, 2.) Stale Mate, because it is not possible to put the opposing teams King into Check within a given number of moves, or 3.) Check Mate, because the opposing teams King has found itself in a position where it will be taken from the chess board because of the inability of that player, ARAI, to remove that impending danger from all of the possible valid moves remaining of that team for that turn.  Yup, simple.  But where to start.  The more rules based this game becomes to facilitate the ARAI the more ridged in format the structure will also become, not to mention the increasing derivation testing that evolves from the processes involved as a result of those restrictive reactionary rules.  Yeah, that’s what I say, WHAT?

The plan, in theory.  An ARAI will need to adhere to a basic set of rules.  So I would guess the best question to ask is what rules are currently present, at least in concept, that pertain to a chess pieces movement.  Apart from all that left-click right-click stuff, the ARAI will need its own automation system to facilitate an action that can come about from what is seen as the current mouse movement model.  That’s one part, but it’s not exactly what I’m looking to get at right now.  I need something more simple than that.  Such as, what happens before the first move of the game.  What is the objective that the ARAI will seek.  How will it utilize the movement plot, that is, the hexes seen as Green: a clear path, Red: a potential opponent kill and Cyan: a current ally protectorate.  From these three movement potentials there must be some directive that will assume an objective.  And the plot thickens.

Again, at the beginning of the game, in chess terms the “opening“, the ARAI will be able to “look” at the statistics, somehow, and formulate an initial reactive strategy.  It would seem, from all prior observable instances, that there would be no pieces to take of the opponent on the first move, so that part of the equation would become null, not zero, but null.  That would leave only two parts of this formulated stratagem needed, which would provide some material to advance this first piece off to somewhere as the starting move for the first ARAI.  The first move would consist of, “Can I move at all”, while the second is, “Do I want to move out of protection, or not.”  So far this does sound rather simple, but what would be the impetus to promote this first move.  And thereafter, would that be perpetuated or relinquished.  Ah, the impetuous human player, always looking into obscurity.  Which brings about the idea of foresight, which in turn brings about the reality of CPU cycles, logic flow and apparent game speed.  Yup, from AI concept, hammer-thrown all the way to the provisions of playability in one flail swoop.  Thoughts do tend to move quite quickly when concept and theory collide.

Back to ye olde solace within.  My ARAI wants to move a piece on the chess board.  “Wee!  Oh-boy, which piece shall I move?”, says the first ARIA.  I guess that could come from a plain old crapshoot.  Some random act that again takes into account the two remaining, hmm, what should I call them, accrual arguments?  The two of the three path plots of a piece consisting of, what, Green, Red and Cyan, as colors.  But what exactly are those.  For one, they are the three parts of a teams piece movement potential that are now named the accrual arguments.  As a side note: the remainder of the full accrual argument formula comes also from the manipulation of time that is used per player turn, which culminates in a representation as the bar graph chart.  So anyway, each hex away from the piece is an open step and/or a terminus.  Each step, because of the type of piece it originates from, will move according to its given schema, and the distance it can go from its origin which is determined by its proximity to the chess board border or another piece.  Well that’s nice to know.  But what does it get me.  Another day older and deeper in debt, and ya’ put ’em in the water and they don’t get wet.  Sure, yeah right, nighty night, I go now.

I’m back.  Wow, I was digging pretty deep there last night with that one, all the way back to a song mom and dad had us kids singing on our road trips back in the day.

The Ditty:

Boom boom,

aint it great to be,


Boom boom,

aint it great to be nuts like us.

Silly and foolish all day long.

Boom boom,

aint it great t’ be,


Sittin’ on a corner sellin’ socks.

A dollar a pair a nickle a box.

The longer ya’ wear ’em the shorter they get.

An’ ya put ’em in the water an’ they don’t get wet.

Chorus: … et. al.

This ARAI stuff, hmm, well I don’t seem to be charging head long into the coding aspects of this pipeline.  No I don’t, no I’m not.  I think I’ll get back to the “Next Move” problem that has come to surface.  But first I’ll address the concept of the ARAI, that being the Algorithmic Reactionary Artificial Intelligents, just to clear up within my own minds eye what it is composed of, the purpose and its composite ideals.  The way it looks, the power that will drive the positioning of the pieces will come from objectives derived of the components of the statistics.  Like most strategy games, there are some predefined default settings that an AI can follow, usually offensive, defensive or neutral.  So what I will need are some choices that allow for selection of how the team will react to the current statistics.  Will I keep my pieces protected?  And if so, to what degree?  What about peril?  Should my piece move out of peril only if not protected?  Should my piece ever move into peril?  Then to get even more basic than that, how should the AI look for a path of that selected piece where the capacity of any of the above mentioned actions will move it into an uncompromised destination.  What direction should that piece move and also how far along that path should it move before it should stop?  These questions and many more will need to be algorithmically answered so the AI will react with some degree of consistency as the game progresses.  This degree might be achieved by constructing combinations and turning them into ratio sets.  These ratio sets could be built and tested empirically, then thereafter, allow the AI to be ‘tweaked’ out with other tested parameters.  Chess, has three phases being the opening, middle game and end game.  Ratio sets may be made up of objectives such as “Move towards the enemy”, “Move along your path until a piece is in peril”, or combinations of ratio sets such as 1.) “Move towards the enemy” but 2.) “Do not move out of protection.”  I think I said something before about the metrics matrix, but maybe not exactly, but now I have, so I guess I’ll continue.

What I’ll need to do is play a couple games of chess and write down some of these simple actions to see if they can be fit, as combinations, into that which will become these fabled ratio sets.  So after getting an Excel SpreadSheet set up for this, it’s back to “Next Move”.  There is an if() conditional that triggers, or keeps from triggering, the gate that prints “Next Move” to the screen and allows for other things to happen.  This whole game is being built piecemeal, so all of this will more than likely end up as a very strange and convoluted longhand logic, nothing tidy, but fully unoptimized and technically inefficient, code thing, but so what.  With that, there must be a way to build a signal flag that is switched on and off if a piece is moved thus ending that players turn.  I’ll get to Castling and Pawn Evolution as two exceptions later on.  For now, what makes a move a move.  The only piece that can move is the one that is selected.  That selected piece is Start (x, y) where x and y are known when the piece is selected.  What happens is when deselected x1 equates to x2 as does y1 and y2.  This is what keeps the “Next Move” signal and button nonviewable, which was a good idea at the time.  But the situation has changed, through the testing process, and now I’m concerned beyond getting the initial move to work properly and am off to allowing for reselection that doesn’t break the game play experience.  Man oh man, derived leaps of faith and truth in linearity inside convoluted code constructs is a rather tumultuous state, but like in the game of Monopoly, Just Visiting.  Then moving in silently down wind and out of sight you need to strike when the moment is right, without thinking … Then after a while …  What I seem to be working on is, if I put the piece that I had just moved back to its starting position, then the “Next Move” will vanish once again because a piece has not been moved yet this turn.  But like many things inside this code page, much is too easily overwritten.  But I gotta say, this game can be decked out like a little happy confetti patch, for as dry a game that chess is.

So, Merry Christmas to all.  And to all a good night.



December 26, 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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s