F. Discussion

The overall steps of creating the game included creating an initial and final flowchart for the coding process, maintaining consistent documentation of the entire process, creating a pitch video for potential users to watch, and coding and debugging the game. The entire code for the game involves one main script file and ten function files in order to maintain simplicity and to avoid repetition in the code or hardcoding.

Although the overall amount of code is fairly large, the progression of the code and its creation can be explained in simple terms. The code begins by initiating the ‘scene’ or board of the game, and variables are made to include graphics such as ship and water sprites. The story of the game, rules, and prompts for user inputs follow. This is where the user will have an option to choose between three different difficulty levels. The code will run through a series of if-elseif-else statements based on the difficulty level to allow the user to place their ships, and a coin toss is initiated afterwards to determine whether the user or AI will start the game. The board is continuously displayed throughout the program to ‘update’ the board after each turn is taken. Once the main portion of the game starts, the program will ask the user for a mouse input to select where to hit on the AI’s portion of the board. The AI, which is controlled by the many functions such as ‘advanced_AI.m’ or ‘advanced_AI_4Qua.m’ will guess on the user’s portion of the board, and the players will take turns until someone wins the game. If a hit is made, the player gets unlimited turns until they miss a ship. After each location is chosen to hit, the program will run through the portion of code that will determine if that location is a water sprite or a ship sprite, and based on the result, the code will update the ‘hitmiss_display’ board layer that will display the hit and miss sprites (white and red dots). The count functions that were created, such as ‘cntWaterSpike’ were made to count the number of hit sprites on each side of the board (user versus Smart AI) in order to determine if the game has ended or not. Because there are fourteen ship sprites per player, once the number of hit sprites of one side of a board has reached fourteen—which the counting functions will do when the program runs this portion of the code—the game will end and display which player has won.

During the testing of the game, the tester or player inputted initial information such as their name, difficulty level, and location of their ships. The game would then commence and the player took turns with the Smart AI to guess where they think the enemy ships are located. The results of the final testing was that the levels were still fairly hard despite having three levels of difficulty (easy, medium, and hard). Otherwise, the code worked with no bugs present and the visuals and storyline worked well with the game and Smart AI.

The main problems that occurred while creating the code involved infinite loops, overlapping of the Smart AI’s ships, and the AI guessing outside of the board (out-of-bound guesses). The overall process of game creation was to base the code off the flowchart that was made and to approach each issue that would arise individually until the game worked. Refinements needed to be made in order to debug the game, but the team was confident that the overall setup of the game was a fair approach. The infinite loop was present when the AI was guessing because it was designed to guess the four adjacent ‘cells’ to a location that was marked with a hit sprite. Initially, the AI guessing function had an infinite loop where it kept guessing the four adjacent ‘cells’ to a hit sprite location, and it would never become the user’s turn. This was fixed by changing the formatting of the code so that there would be conditions that needed to be met. Doing this allowed the program to move on if there was a hit or miss sprite, and the AI would either get another turn or it would become the user’s turn. The issue with the overlapping ships for the Smart AI was fixed by limiting the ships to four quadrants, but still allowing the ships to be randomly placed. The 5-long ship was placed in the bottom-right quadrant, the 4-long ship was placed in the top-right quadrant, the 3-long ship was placed in the top-left quadrant, and the 2-long ship was placed in the bottom-left quadrant. The AI’s ships could no longer overlap one another, but the randomizer function that was created still made it more difficult to win against the Smart AI. The final issue that the team had was the issue in which the Smart AI would guess out-of-bounds. When this occurred, the program would result in an error and could not continue running. This was changed by making if-else statements with necessary conditions. In simple terms, if the AI guessed out-of-bounds (not in rows 1-10 or columns 1-10), then the AI would have to guess again until it reaches a guess that is in-bounds.