Artificial Intelligence Program (AIP)
Version 0.2
1. Start the program.
2. Click on File, New Game Type.
3. Click on 3 x 3 (Note, this is already checked by default but must be
clicked to initiate a game).
4. At the popup window, enter the game name "Tic Tac Toe" and click OK.
5. Several buttons and text fields on the left side of the program window are enabled.
From here it is possible to change the symbols of the teacher and program. Symbols
represent game pieces. Each symbol has an associated numerical value. Additionally,
the teacher (user) can select who plays first. The programs statistics are also displayed
(wins, losses and ties).
6. By default, the program goes first. Click on the Start Game button.
Several things happen. The buttons and text fields above the solid black horizontal
line are disabled. The buttons below the Start Game button are enabled. The
program places an 'X' on the game board or grid.
7. As a teacher, your purpose is to play Tic Tac Toe as you understand it. Click
on a legal space within the game board. A 'O' will be placed on the grid.
If you have made a mistake, simply click on the mistake and it will disappear.
Try again.
8. After each play click on the Teacher Move Complete button. This
signals the program to play.
NOTE: The program does not know what constitutes a win. Therefore it is important that the teacher pay careful attention to the game play. As soon as the teacher or program has won the game, the teacher must click on the Win option button and then carefully click on each symbol or cell that defines the win. Do not drag the mouse. Click on each cell. The cell will turn to a green color.
9. Immediately upon highlighting the winning pattern in green, click the Send Feedback button. This informs the program that the game is over and signals the program to store the winning pattern within its knowledge base.
NOTE: In the event that no one wins, the teacher must click on the Tie option button and click Send Feedback. This terminates the game.
10. Play can be repeated by clicking on the Start Game button. Generally, it is
necessary to play against the program several times. Each time, the teacher should attempt
to use another pattern or variation of a pattern.
11. Periodically, the game should be saved by clicking on File, Save Game.
NOTE: It is a point of interest to click on the AI Knowledge tab and observe the results as the game is played. More detail can be found on the AIP Theory page.
1. Click on File, Open Existing Game.
2. Select the appropriate game file and click OK.
3. Opening an existing game file loads all game parameters into the computer
program. The AI program will continue to build upon this knowledge base as the program
continues game play.
Try designing a game that uses a larger grid such as 5 x 5. Invent your own winning patterns such as an "L" shape using four cells or spaces. After winning, try playing an "L" shape that is inverted, upside down or flipped. It is possible to represent this shape in eight orientations. You can change the symbols to any alphanumeric character(s).

For the non-VB programmer who is not studying the open source code for AIP, this Tab has very little value. The purpose is to display all program Global Variables so the program can be more effectively studied and debugged. Following is a list of global variables displayed in this program.
Note the prefix(es) used are as follows: (g)=global, (b)=boolean, (n)=integer, (l)=long integer, (s)=string and (u)=user-defined type.
gbFilenameExists: False
gbWin: False
gbProgramTurn: True
gbGameOver: False
gbLoss: False
gbTie: False
gbTeacherDone: False
gnGoFirst: 1
gnRows: 3
gnCols: 3
gnProgramValue: 1
gnTeacherValue: 2
gnProgramWins: 0
gnProgramLosses: 0
gnProgramTies: 0
gnTotalCells: 9
gnGameType: 1
gnMoveCount: 0
gnGameCount: 0
gnPlayCount: 0
glCellColor: 16777215
glCellSelectedColor: 65280
gsRules:
gsVersion: v0.2a
gsProgramSymbol: X
gsTeacherSymbol: O
gsFilename:
gsGameName:
gnABSTotal: 0
glTeacher: 0
glProgram: 0
glAllCells: 0
glFreeCells: 0
gbWinNotSaved: False
uABS( 0) Pattern : 0
uABS( 0) Wins : 0

All games created by the teacher are saved as ASCII text files using an .AIP extension. All saved games can be opened for play. The major divisions of the game file are as follows.
Comment Header - provides filename and date file last saved
System Variables - these are variables necessary for the correct functioning of the AIP
program game.
Win-Loss History - records the AI Program wins, losses and ties with the teacher.
Winning Patterns - all patterns that resulted in a win are recorded with ABS which means
absolute position within the grid. Row and column coordinates follow in pairs inside
parentheses. The '=1' means that this particular pattern has resulted in at least
one win for either the program or the teacher. The particular upper case keywords
below comprise the AIP Scripting language.
'**********************************
'game1.aip
'Date:7/10/2002
'**********************************
'system variables
GAME.NAME=TicTacToe
GAME.TYPE=1
GAME.ROWS=3
GAME.COLS=3
GAME.TEACHER.SYMBOL=O
GAME.TEACHER.VALUE=2
GAME.PROGRAM.SYMBOL=X
GAME.PROGRAM.VALUE=1
GAME.GOFIRST=1
GAME.CELL.COLOR=16777215
GAME.CELL.SELECTEDCOLOR=65280
'win-loss history
GAME.PROGRAM.WIN=0
GAME.PROGRAM.LOSS=3
GAME.PROGRAM.TIE=2
'winning patterns
ABS(1,1);(2,2);(3,3)=1
ABS(1,3);(2,2);(3,1)=1
ABS(1,1);(1,2);(1,3)=1
ABS(2,1);(2,2);(2,3)=0
ABS(3,1);(3,2);(3,3)=0

The cells within the 3x3, 4x4 and 5x5 square grids adhere to a particular number convention. The top left cell in the grid is always number one. The numbering increases from left to right, top to bottom. Therefore, given a 3x3 grid, the top row from left to right is numbered 1 through 3, the middle row from left to right is numbered 4 through 6 and the bottom row is numbered 7 through 9. The highest numbered cell is always the product of the rows and the columns. For example, a 3x3 grid has 9 cells, a 4x4 grid has 16 cells and a 5x5 grid has 25 cells.
Additionally, each cell is assigned a bit position in a binary number. For example, a 3x3 grid has 9 cells and therefore can be represented by a binary number that has 9 "1" bits. Converted to decimal this is 511. The AIPSL (AIP Scripting Language) representation of the win is expressed with the ABS keyword. IN the example below, this winning pattern which is a diagonal from the top left to the bottom right is represented by a binary number equivalent to 273 decimal.
AIP Scripting Representation of Knowledge
******************************************************
273 = ABS(1,1);(2,2);(3,3)=1
84 = ABS(1,3);(2,2);(3,1)=1
7 = ABS(1,1);(1,2);(1,3)=1
56 = ABS(2,1);(2,2);(2,3)=0
448 = ABS(3,1);(3,2);(3,3)=0
Following is a binary representation of all winning patterns that the program still has the capability of winning. The digits 9 through 1 represent the actual cells within the grid. For Tic Tac Toe, notice that there are only three bits set which define a winning row, column or diagonal. Following the nine digit number, is the equal sign followed by two numbers. The first of the numbers is a count of all bits to the immediate left. The number inside the parentheses is the number of times that this particular pattern has been won by the program or teacher.
***************************
Program cells to win...
***************************
9 8 7 6 5 4 3 2 1
***************************
1 0 0 0 1 0 0 0 1 = 3 (1)
0 0 1 0 1 0 1 0 0 = 3 (1)
0 0 0 0 0 0 1 1 1 = 3 (1)
0 0 0 1 1 1 0 0 0 = 3 (0)
1 0 1 0 0 0 0 0 0 = 2 (0)
***************************
2 0 2 1 3 1 2 1 2
The numbered row below the binary values represents the sum of all bits added vertically.
***************************
Teacher cells to win...
***************************
9 8 7 6 5 4 3 2 1
***************************
1 0 0 0 1 0 0 0 1 = 3 (1)
0 0 1 0 1 0 1 0 0 = 3 (1)
0 0 0 0 0 0 1 1 1 = 3 (1)
0 0 0 1 1 1 0 0 0 = 3 (0)
***************************
1 0 1 1 3 1 2 1 2
The status of the board in terms of which cells are used, which cells are still free or empty, which cells have been played by the computer and which cells have been played by the program is indicated below.
All Used: 0 1 0 0 0 0 0 0 0
Free: 1 0 1 1 1 1 1 1 1
Prog: 0 1 0 0 0 0 0 0 0
Teach: 0 0 0 0 0 0 0 0 0
The above information is explained better on the AIP Theory page.
Viewing the Error Log is accomplished by clicking on Help, Error Log. This starts Windows Notepad.exe and displays the contents of the ASCII file EVENTLOG.TXT. As a general rule, most errors occuring during the program process is handled by a error handling routine that data logs the error to the file EVENTLOG.TXT. Additionally, all global variable names and values are dumped to this file.
It is recommended that the AIP user send this file as an attachment when reporting bugs or errors that occur during the operation of the program.
********************************************************
E R R O R ! ! !
No.: 0
Description:
Form: AIEngineMod
Procedure: GetFactBasedMove
Location in Code:
Info:
DATE: 7/7/2002 TIME: 1:16:00 AM
********************************************************
G L O B A L V A R I A B L E S
********************************************************
gbFilenameExists: True
gbWin: False
gbProgramTurn: True
gbGameOver: False
gbLoss: False
gbTie: False
gbTeacherDone: False
gnGoFirst: 1
gnRows: 5
gnCols: 5
gnProgramValue: 1
gnTeacherValue: 2
gnProgramWins: 0
gnProgramLosses: 0
gnProgramTies: 0
gnTotalCells: 25
gnGameType: 1
gnMoveCount: 0
gnGameCount: 0
gnPlayCount: 0
glCellColor: 16777215
glCellSelectedColor: 65280
gsRules:
gsVersion: v0.1g
gsProgramSymbol: X
gsTeacherSymbol: O
gsFilename:
gsGameName: Big Game
gnABSTotal: 0
glTeacher: 0
glProgram: 0
glAllCells: 0
glAllCellsInverted: 33554431
gbWinNotSaved: False
uABS( 0) Pattern : 0
uABS( 0) Wins : 0