FOUR 4 V1.8 by John Augustine This is a description about the procedures the computer uses during it's turn to move. Note: When referring to procedures, I'll use my source code labels. This program has intensive defensive analytical procedures ("PHSE1,2,3,4,5,6"). In addition, it also has some offensive procedures. The offensive procedures are not as complex as the defensive. Since these procedures are similar to my thought processes, while playing (many times) "FOUR" with a friend of mine over the radio ("ham" radio), I decided to use the term "artificial intelligence". Further more, the learning procedures enhance the program's performance (in time). This in effect, makes the program "smarter", similar to our own learning processes, where we can learn a new technique, adding to our experience. The accumulated "knowledge" is saved to a file, "FOUR.DTA", if a new winning pattern is learned, when you exit "FOUR". The sequence of procedures during the computer's turn to move are: "RECALL" is the first procedure called. RECALL examines the accumulated "knowledge" ("FOUR.DTA"). "It" looks for a sequence of moves that match the current sequence. The sequence must favor the computer, even if the particular sequence of moves originally was "learned" from a game that man won. As an example, if the computer moves first in the present game, "it" will ignore all learned game sequences in which the winner of those past games (man or computer) moved second. Those sequences are of no benefit to the computer during the present game in this example. Also, if there is a matching sequence of moves found, the computer will continue RECALL until the most recent matching sequences of moves are found. This way the computer, in effect, uses the most advanced techniques. For comparison, haven't we learned something in life, and later, learned a better way to do it? We remember how we use to do it, but now we do it differently. Dare I say, "artificial intelligence" is certainly a suitable term for "FOUR". NOTE: This "RECALL" procedure is the same as a person playing a game, who remembers all the past game sequences that led to a win, and retraced those same steps, as long as the current game sequence matches one of those past games. However, if the current game sequence deviates, due to a move made by man, from all of the past games "learned", then there is a new game to learn after it is over, as long as the game ends with a winner. Note: It is possible to have a "No Win Game". Finally, the computer stores only the sequences that are unique, no duplicates are "learned". If RECALL "fails", the next procedures are executed: "PHSE1" procedure checks to see if "it" can make a "4" (four consecutive pieces in a "line"). If yes, uses that slot number to make it's move. If this "fails", move on to "PHSE2". "PHSE2" procedure checks to see if man can make "4" on his turn (next). If so, takes that "winning" slot number to block man from making a "4". If that situation is not present at this time, moves to "PHSE3". "PHSE3" puts slot numbers into "OFF_LIMIT" which include full slots, and those slots, if computer placed a piece, would allow man to win on his turn. As an example: Man has three across (slot 3,4 and 5), second row from the bottom. Slot 6 is empty. If the computer placed a piece in slot 6 (bottom row), man can put his/her piece into slot 6 afterwards and win, therefore slot 6 will become an "OFF_LIMIT" slot. "PHSE4" evaluates if man is two pieces from "connect 4", and puts those two slot numbers into "TWO". The procedure re-cycles until all slots are evaluated, unless the man's two pieces can be placed, one on either side of two of his pieces that are already on the board, a most dangerous "TWO" situation. In that event, the procedure "flags" this dangerous "TWO" by setting the hi bit in the relative slot numbers entered into "TWO". At this point, the procedure ends (moves on to "PHSE5") without going further. It is possible that more than one 2 piece to "4" exist for man, the later one will cover up the earlier one relative to the direction of slot evaluation movement. A low threat two piece situation exist if one was on top of the other in the same slot. These "TWO" numbers are replaced by more threatening "TWO" pieces, if any exist. "PHSE5" is a variation of "PHSE4" except it checks to see if man has an opportunity to win after he/she places a piece into one of the slots. Only across and diagonal directions are considered in this procedure. That opportune slot number is entered into the "OFF_LIMIT" slot numbers, but with a lower threat flag set than other "OFF_LIMIT" numbers. "PHSE6" determines what action to take based on the above "PHSEs, except "PHSE1" and "PHSE2". The "TWO" numbers are first checked for the "dangerous" "TWO". If a "dangerous" "TWO" exist, the computer places it's own piece to disable that threatening situation. If the "TWO" is not "dangerous" or no "TWO" exist, the computer places a piece in slot number 4, if it is not in the "OFF_LIMIT" (full slot or advantage to man) table. NOTE: Slot number 4 is strategically the best slot. If slot number 4 is "OFF_LIMIT", the computer calls "OFFENSE" procedures and uses the number returned, unless "flagged" otherwise. The slot number returned by the "OFFENSE" procedures is used to work toward a "4" sequence of pieces. I'll explain the "OFFENSE" procedures when I am through with "PHSE6". If no suitable position is found by the "OFFENSE" procedures, the computer calls a random number generator procedure for a number from 1 to 7, and checks the number against those in the "OFF_LIMIT" table. NOTE: I would like to take a step backward and say something regarding the "OFF_LIMIT_CHECK" procedure which handles the checking of a slot number against those in the "OFF_LIMIT" table. If all 7 slots are "OFF_LIMIT", "OFF_LIMIT_CHECK calls another procedure to find a slot, any slot that is not full and "flags" the computer to use that slot number. "OFFENSE" is called by "PHSE6" only after slot 4 is full or "OFF_LIMIT" for some other reason. The purpose of "OFFENSE" is to search for opportunities to make a "4". It examines the "board" for an opening to place it's piece, in order to increase the number of pieces in a sequence (in a line). A row (across) sequence opportunity is sought first. "Failing" this, it looks for a sequence in a line diagonally both left and right. If this "fails", it will seek a column opportunity. Note: the column opportunity has the lowest priority since it is the most obvious to man. In general, even if another piece can be placed to increase, say two consecutive pieces to three, additional positions are checked in that "line" to see if a "4" can be made. If not, there is no practical reason to use that slot, when in that line, a "4" can't be made anyway. SUMMARY: There are many other support procedures involved with the above mentioned procedures, but what I explained is the "heart" of the computer's "thinking" before making a move. Some of it's shortcomings are filled, in time, with "learned" "knowledge" (experience).