Blackjack Discussion
Most of the difficulties came about when drawing a random card for the user. The player had to input whether or not they wanted to stay but on the first iteration of the program, it would keep drawing cards no matter what the user input. This was eventually fixed by rewriting the else if statement to only accept “hit” or “stay”.
After the problem with accepting user input was fixed, the only other problems came from the actual blackjack rules. In the initial program, the computer was only drawing to 14 and the program was displaying too many of the computer’s cards. These problems were fixed by changing the variable responsible for keeping the loop running and by changing the array that displayed the computers cards to only display the first value.
Connect 4 Discussion
The program for Connect 4 used a seed file that included a pre-established board and chips that the code interacted with. The player was required to input a number to choose a column to drop their chip in, and the computer randomly selected a column to place its chip in. The programming of the player choice and randomization of computer choice was the first thing to be programmed, but many problems arose after the initial interface was programmed.
Most of the difficulties came about with how wins were declared. Vertical wins were the first ones to be programmed, then horizontal wins. Diagonal wins were the last to be programmed and proved to be the most problematic. The program had to tell the computer how to recognize patterns and what patterns to acknowledge.
The first pattern-recognition strategy tried was a variety of different counter systems. Each iteration of this strand of pattern-recognition had its own problems. Vertical wins would work, but not horizontal, and diagonal wins did not work until the very end. In addition to this, there was no way to check if the computer won at first, so the game could theoretically be played until the board was filled even if the player or computer won.
Many of the problems in the program were fixed through trial and error, as well as working out the logic outside of the code. It was this method that caused the original counter systems to be done away with completely. The final code utilized a matrix to figure out where the player and computer placed their chips, and whether or not either one had four in a row. It was easier to program pattern-recognition in this way than trying to count spaces, as was tried before.