Its been a hard week of developing until 4am in the morning sometimes, just dying to finish what im working on and see it working so I can rest easy when I lay down to sleep at the end of each development iteration. Hmm where to begin…
So first I made the cube, tube and cylinder(play piece), colored & textured them before finally linking the 3 together, next duplicated this set holding shift key and dragging it, until I created a single row for the game. I then duplicated that row upwards 6 times to form the game board & made the cube to sit at the bottom before creating hemisphere shaped LED glowing lights to place along the bottom cube. Lastly was creating the side pillars using a cylinder with taper and twist plus cube with twist then another cylinder with taper on top and textured the pillar, and linked everything together making the game object!
So once visual game existed I began to code scripts that will do the work required for the game to function and work the way I desire, there is a total of 3, Master script, column selecting script and scanner script to welcome nearby Residents as seen in the above image. Also seen is a few of the other messages the game says into nearby chat… such as informing a player if there is no available spaces for that column meaning its full and to choose another, or declaring who the winner was! The floating text centered above the game shows who is playing and what color as, but there is no active game is the above picture hence the GREEN Led light is glowing indicating that the game is awaiting players!
Meeting a requirement through dialog menu’s I have made it show this menu when any part of the game is touched (other than the top rows 4 game piece spaces), here the Resident can decide to play as RED or YELLOW, Play an AI level, Reset the game, get a Note Card about how to Play or Visit this blog!
When a Resident becomes RED, the option will no longer show in the menu until game reset, same for YELLOW but once YELLOW is assigned to a Resident or AI, all the YELLOW related menu options wont show anymore until game reset.
In the image above you can now see looking at the floating text above the game that RED is myself while YELLOW is Consecutive 4 (The AI I have scripted). Because both positions are taken the game has now started and the LED light glowing is now the Red one, indicating that it is RED’s turn and Red always goes first in this game! Now how to select a column for my play piece to fall into an complete my turn? At first I added a touch script to detect touching, for all the 42 spaces possible using that to play the game. But after showing the game to Isa my tutor and getting informed about how heavy the game is running due to having so many scripts on the object I changed this now to instead of 42 scripts on each space, there is now only 7 touch scripts along the very top row of spaces only! In order to select a column for your play piece to fall down in, a resident now only needs to click a space from the top row identifying the column they desire.
So as you see from the above image when its YELLOW’s turn the LED glowing light becomes the Yellow one! And also in accordance with preference from Isa my Tutor I have made all game pieces glow so they pop and stand out more easier to see during game play!
Also during Game Play if any part of the Game is clicked by a player of other resident they will only see these 3 option in the Game Menu! But it would be rude to reset a game while others are playing!! And just to clarify, Players cannot place another piece or accidentally choose where the opponents piece will go, etc.. because I have scripted processing checks preventing such things which could disrupt or error the game.
This image above is a bit embarrassing, I was planning to screenshot how the game looks when a resident wins being myself, but the Hard AI defeated me winning the game as i rushed so I just captured who that looks anyway!
Notice even though the game ended, the Glowing LED light remains Glowing to represent the winner until such time the game gets reset! You can also see that once there is a Winner all the play pieces stop glowing, other than the winning set of pieces… this makes it clear which 4 in row got the win!
For this game to work as I have previously mentioned there is 3 scripts, two are found directly in the root prim and visible without going to edit linked mode, I could have just included the scanner scripts code in the master script but decided to leave it separate. As you can see Land Impact of 139, so there is 139 Primitives forming the game object.
Then if we go into edit linked mode and select any of the spaces(play pieces) from the top row, we find the column select script which is very simply just detecting if touched and messaging the master script as to which column was touched. From this information the master script will identify the next available space for that column to fall down into and then move the play piece into position ready to fall, setup the color and glow and alpha effects accordingly before animating the fall of a play piece into position and checking if it created a win for that colored player!
This image shows the details of the NOTE CARD that a resident will get if they choose the How To Play option from the Game Menu, it outlines the goal and rules of the game along with instructions about exactly how to play. So the game was pretty much finished once I developed all this and got it working , playing as both RED and YELLOW myself while getting the scripts to work, showing LINK numbers visually with floating text to debug and write out all the winning set combinations through identifying the 4 prim links involved for any winning set because I noticed the link number seen in build tools when editing link can be very inaccurate.
CREATING THE ADDITION OF AI???
So this was not apart of my plan originally, but I decided to give it a go after getting tired of playing against myself. Let me explain how I have designed this AI!
So the first thing AI needs to do, is check if there is any combination of 3 YELLOW(AI’s Color) where by adding a 4th piece is actually possible right now to create a Win and Win! If not.. the AI then checks the same for RED(AI’s opponents color) and if identified will take the 4th in a row space blocking RED from winning!
Next I scripted AI to failing the above, Check for any 2 in a row combinations from RED’s pieces and start blocking those from becoming 3 in a row, if no suitable move for this can be found to exist the AI will then check the same for itself to try form 3 in a row!
So if the AI still has not identified the best move to do… the AI will then look at the last move RED made and follow RED placing a piece on the top, or either side of the last played piece by RED, at random. By this stage it should be able to have made a move!
In the rear case (usually only when board is almost full) the AI might resort to using the fail safe move routine which simply scans the whole game board for any possible space to play its move into using the first it finds!
The Easy AI does not do all those checks above, making it weaker and more likely to do a bad move!
The Average AI does all of the above, making it a decent opponent but still prone to setting up a win for its opponent without knowing it!
The Hard AI has an additional check added which enables it to once a move has been identified, imagine playing that move, then check if by playing that move, it will be setting up its opponent to win that next move or not…. if not it makes the move but if that move will setup a win for the opponent then the AI will skip that move as an option and continue on looking for another good move to make instead, I call this the Bad Move Check!!
And that concludes the development and implementation process for Consecutive 4!