<%@ LANGUAGE = VBScript%> <% Const tmpXWidth = 44, tmpSpacerWidth = 11, tmpBoardWidth = 154 %> <% tmpPlayers = Request("Players") %> <% tmpComputer = Request("Computer") %> <% tmpMoveNum = Request("MoveNum") %> <% tmpMoves = Request("Moves") %> <% tmpWon = "0" %> <% If tmpComputer = "X" Then tmpOpp = "O" Else tmpOpp = "X" %> <% Function GetSquare (CharOffset) If tmpMoves = "" Then tmpMoves = "000000000" Select Case (Mid (tmpMoves, CharOffset, 1)) Case "0", "5" GetSquare = "Blank" Case "1", "3", "7", "9" GetSquare = "X" Case "2", "4", "6", "8" GetSquare = "O" End Select End Function %> <%Sub CheckWin tmpWon = "0" tmpVal1 = GetSquare (1) tmpVal2 = GetSquare (2) tmpVal3 = GetSquare (3) tmpVal4 = GetSquare (4) tmpVal5 = GetSquare (5) tmpVal6 = GetSquare (6) tmpVal7 = GetSquare (7) tmpVal8 = GetSquare (8) tmpVal9 = GetSquare (9) If (tmpVal1 <> "Blank" And tmpVal1 = tmpVal2 And TmpVal1 = tmpVal3) then tmpWon = tmpVal1 If (tmpVal4 <> "Blank" And tmpVal4 = tmpVal5 And TmpVal4 = tmpVal6) then tmpWon = tmpVal4 If (tmpVal7 <> "Blank" And tmpVal7 = tmpVal8 And TmpVal7 = tmpVal9) then tmpWon = tmpVal7 If (tmpVal1 <> "Blank" And tmpVal1 = tmpVal4 And TmpVal1 = tmpVal7) then tmpWon = tmpVal1 If (tmpVal2 <> "Blank" And tmpVal2 = tmpVal5 And TmpVal2 = tmpVal8) then tmpWon = tmpVal2 If (tmpVal3 <> "Blank" And tmpVal3 = tmpVal6 And TmpVal3 = tmpVal9) then tmpWon = tmpVal3 If (tmpVal1 <> "Blank" And tmpVal1 = tmpVal5 And TmpVal1 = tmpVal9) then tmpWon = tmpVal1 If (tmpVal7 <> "Blank" And tmpVal7 = tmpVal5 And TmpVal7 = tmpVal3) then tmpWon = tmpVal7 End Sub%> <% Function RandomX Randomize tmpNum = Int(9 * Rnd + 1) If tmpNum Mod 2 = 0 Then tmpNum = tmpNum - 1 If tmpNum = 5 then tmpNum = 3 RandomX = chr (48 + tmpNum) End Function %> <% Function RandomO Randomize tmpNum = Int(7 * Rnd + 2) If tmpNum Mod 2 = 1 Then tmpNum = tmpNum + 1 RandomO = chr (48 + tmpNum) End Function %> <% Function RandomBlank Randomize tmpNum = Int((9) * Rnd + 1) If tmpNum > 5 Then tmpNum = 5 Else tmpNum = 0 RandomBlank = chr (48 + tmpNum) End Function %> <%Function CalcMovesURL (SquareClicked) If tmpMoves = "" Then tmpMoves = "000000000" End If For tmpCount = 1 to 9 If tmpCount <> SquareClicked Then Select Case GetSquare (tmpCount) Case "X" tmpUsed = tmpUsed + RandomX Case "O" tmpUsed = tmpUsed + RandomO Case "Blank" tmpUsed = tmpUsed + RandomBlank End Select Else Select Case tmpPlayers Case "1" If tmpComputer = "O" Then tmpUsed = tmpUsed + RandomX Else tmpUsed = tmpUsed + RandomO End If Case "2" If tmpMoveNum Mod 2 <> 0 Then tmpUsed = tmpUsed + RandomX Else tmpUsed = tmpUsed + RandomO End If End Select End If Next CalcMovesURL = tmpUsed End Function %> <% Function Move2 tmpVal = 0 If GetSquare (5) <> tmpOpp then Move2 = 5 Else tmpVal = Int((4) * Rnd + 1) Select Case tmpVal Case 1 Move2 = 1 Case 2 Move2 = 3 Case 3 Move2 = 7 Case 4 Move2 = 9 End Select End If If GetSquare (5) = tmpOpp Then tmpVal = Int((4) * Rnd + 1) Select Case tmpVal Case 1 Move2 = 1 Case 2 Move2 = 3 Case 3 Move2 = 7 Case 4 Move2 = 9 End Select End If End Function%> <% Function Move3 tmpVal = 0 If GetSquare (1) = tmpComputer Then If GetSquare (2) = tmpOpp Or GetSquare (3) = tmpOpp Then Move3 = 4 If GetSquare (4) = tmpOpp Or GetSquare (7) = tmpOpp Then Move3 = 2 If GetSquare (5) = tmpOpp Then Move3 = 9 If GetSquare (6) = tmpOpp Then Move3 = 7 If GetSquare (8) = tmpOpp Then Move3 = 3 If GetSquare (9) = tmpOpp Then tmpVal = Int((2) * Rnd + 1) If tmpVal = 1 then Move3 = 3 Else Move3 = 7 End If End If If GetSquare (2) = tmpComputer Then tmpVal = 5 If GetSquare (7) = tmpOpp Then tmpVal = 1 If GetSquare (9) = tmpOpp Then tmpVal = 3 If GetSquare (5) = tmpOpp Then tmpVal = Int((7) * Rnd + 3) If TmpVal = 5 Then TmpVal=1 End If Move3 = tmpVal End If If GetSquare (3) = tmpComputer Then If GetSquare (1) = tmpOpp Or GetSquare (2) = tmpOpp Then Move3 = 6 If GetSquare (6) = tmpOpp Or GetSquare (9) = tmpOpp Then Move3 = 2 If GetSquare (5) = tmpOpp Then Move3 = 7 If GetSquare (4) = tmpOpp Then Move3 = 9 If GetSquare (8) = tmpOpp Then Move3 = 1 If GetSquare (7) = tmpOpp Then tmpVal = Int((2) * Rnd + 1) If tmpVal = 1 then Move3 = 1 Else Move3 = 9 End If End If If GetSquare (4) = tmpComputer Then tmpVal = 5 If GetSquare (3) = tmpOpp Then tmpVal = 1 If GetSquare (9) = tmpOpp Then tmpVal = 7 If GetSquare (5) = tmpOpp Then tmpVal = Int((7) * Rnd + 3) If (tmpVal = 4 Or tmpVal = 5) Then tmpVal=tmpVal - 3 End If Move3 = tmpVal End If If GetSquare (5) = tmpComputer Then If (GetSquare (1) = tmpOpp Or GetSquare (9) = tmpOpp) Then tmpVal = Int((2) * Rnd + 1) If tmpVal = 1 Then Move3 = 3 If tmpVal = 2 Then Move3 = 7 End If If GetSquare (2) = tmpOpp Then tmpVal = Int((2) * Rnd + 1) If tmpVal = 1 Then Move3 = 1 Else Move3 = 3 End If If (GetSquare (3) = tmpOpp Or GetSquare (7) = tmpOpp) Then tmpVal = Int((2) * Rnd + 1) If tmpVal = 1 Then Move3 = 1 If tmpVal = 2 Then Move3 = 9 End If If GetSquare (4) = tmpOpp Then tmpVal = Int((2) * Rnd + 1) If tmpVal = 1 Then Move3 = 1 Else Move3 = 7 End If If GetSquare (6) = tmpOpp Then tmpVal = Int((2) * Rnd + 1) If tmpVal = 1 Then Move3 = 3 Else Move3 = 9 End If If GetSquare (8) = tmpOpp Then tmpVal = Int((2) * Rnd + 1) If tmpVal = 1 Then Move3 = 7 Else Move3 = 9 End If End If If GetSquare (6) = tmpComputer Then tmpVal = 5 If GetSquare (1) = tmpOpp Then tmpVal = 3 If GetSquare (7) = tmpOpp Then tmpVal = 9 If GetSquare (5) = tmpOpp Then tmpVal = Int((7) * Rnd + 3) If (tmpVal = 5 Or tmpVal = 6) Then tmpVal=tmpVal - 4 End If Move3 = tmpVal End If If GetSquare (7) = tmpComputer Then If GetSquare (1) = tmpOpp Or GetSquare (4) = tmpOpp Then Move3 = 8 If GetSquare (8) = tmpOpp Or GetSquare (9) = tmpOpp Then Move3 = 4 If GetSquare (2) = tmpOpp Then Move3 = 9 If GetSquare (5) = tmpOpp Then Move3 = 3 If GetSquare (6) = tmpOpp Then Move3 = 1 If GetSquare (3) = tmpOpp Then tmpVal = Int((2) * Rnd + 1) If tmpVal = 1 then Move3 = 1 Else Move3 = 9 End If End If If GetSquare (8) = tmpComputer Then tmpVal = 5 If GetSquare (1) = tmpOpp Then tmpVal = 7 If GetSquare (3) = tmpOpp Then tmpVal = 9 If GetSquare (5) = tmpOpp Then tmpVal = Int((7) * Rnd + 1) If tmpVal = 5 Then tmpVal=9 End If Move3 = tmpVal End If If GetSquare (9) = tmpComputer Then If GetSquare (3) = tmpOpp Or GetSquare (6) = tmpOpp Then Move3 = 8 If GetSquare (7) = tmpOpp Or GetSquare (8) = tmpOpp Then Move3 = 6 If GetSquare (2) = tmpOpp Then Move3 = 7 If GetSquare (4) = tmpOpp Then Move3 = 3 If GetSquare (5) = tmpOpp Then Move3 = 1 If GetSquare (1) = tmpOpp Then tmpVal = Int((2) * Rnd + 1) If tmpVal = 3 then Move3 = 1 Else Move3 = 7 End If End If End Function %> <% Function CanLose tmpVal = 0 If (GetSquare(1)=tmpOpp And GetSquare(2)=tmpOpp And GetSquare(3)="Blank") Then tmpVal = 3 If (GetSquare(1)=tmpOpp And GetSquare(3)=tmpOpp And GetSquare(2)="Blank") Then tmpVal = 2 If (GetSquare(2)=tmpOpp And GetSquare(3)=tmpOpp And GetSquare(1)="Blank") Then tmpVal = 1 If (GetSquare(4)=tmpOpp And GetSquare(5)=tmpOpp And GetSquare(6)="Blank") Then tmpVal = 6 If (GetSquare(4)=tmpOpp And GetSquare(6)=tmpOpp And GetSquare(5)="Blank") Then tmpVal = 5 If (GetSquare(5)=tmpOpp And GetSquare(6)=tmpOpp And GetSquare(4)="Blank") Then tmpVal = 4 If (GetSquare(7)=tmpOpp And GetSquare(8)=tmpOpp And GetSquare(9)="Blank") Then tmpVal = 9 If (GetSquare(7)=tmpOpp And GetSquare(9)=tmpOpp And GetSquare(8)="Blank") Then tmpVal = 8 If (GetSquare(8)=tmpOpp And GetSquare(9)=tmpOpp And GetSquare(7)="Blank") Then tmpVal = 7 If (GetSquare(1)=tmpOpp And GetSquare(4)=tmpOpp And GetSquare(7)="Blank") Then tmpVal = 7 If (GetSquare(1)=tmpOpp And GetSquare(7)=tmpOpp And GetSquare(4)="Blank") Then tmpVal = 4 If (GetSquare(4)=tmpOpp And GetSquare(7)=tmpOpp And GetSquare(1)="Blank") Then tmpVal = 1 If (GetSquare(2)=tmpOpp And GetSquare(5)=tmpOpp And GetSquare(8)="Blank") Then tmpVal = 8 If (GetSquare(2)=tmpOpp And GetSquare(8)=tmpOpp And GetSquare(5)="Blank") Then tmpVal = 5 If (GetSquare(5)=tmpOpp And GetSquare(8)=tmpOpp And GetSquare(2)="Blank") Then tmpVal = 2 If (GetSquare(3)=tmpOpp And GetSquare(6)=tmpOpp And GetSquare(9)="Blank") Then tmpVal = 9 If (GetSquare(3)=tmpOpp And GetSquare(9)=tmpOpp And GetSquare(6)="Blank") Then tmpVal = 6 If (GetSquare(1)=tmpOpp And GetSquare(5)=tmpOpp And GetSquare(9)="Blank") Then tmpVal = 9 If (GetSquare(1)=tmpOpp And GetSquare(9)=tmpOpp And GetSquare(5)="Blank") Then tmpVal = 5 If (GetSquare(5)=tmpOpp And GetSquare(9)=tmpOpp And GetSquare(1)="Blank") Then tmpVal = 1 If (GetSquare(3)=tmpOpp And GetSquare(5)=tmpOpp And GetSquare(7)="Blank") Then tmpVal = 7 If (GetSquare(3)=tmpOpp And GetSquare(7)=tmpOpp And GetSquare(5)="Blank") Then tmpVal = 5 If (GetSquare(5)=tmpOpp And GetSquare(7)=tmpOpp And GetSquare(3)="Blank") Then tmpVal = 3 CanLose = tmpVal End Function%> <% Function CanWin tmpVal = 0 If (GetSquare(1)=tmpComputer And GetSquare(2)=tmpComputer And GetSquare(3)="Blank") Then tmpVal = 3 If (GetSquare(1)=tmpComputer And GetSquare(3)=tmpComputer And GetSquare(2)="Blank") Then tmpVal = 2 If (GetSquare(2)=tmpComputer And GetSquare(3)=tmpComputer And GetSquare(1)="Blank") Then tmpVal = 1 If (GetSquare(4)=tmpComputer And GetSquare(5)=tmpComputer And GetSquare(6)="Blank") Then tmpVal = 6 If (GetSquare(4)=tmpComputer And GetSquare(6)=tmpComputer And GetSquare(5)="Blank") Then tmpVal = 5 If (GetSquare(5)=tmpComputer And GetSquare(6)=tmpComputer And GetSquare(4)="Blank") Then tmpVal = 4 If (GetSquare(7)=tmpComputer And GetSquare(8)=tmpComputer And GetSquare(9)="Blank") Then tmpVal = 9 If (GetSquare(7)=tmpComputer And GetSquare(9)=tmpComputer And GetSquare(8)="Blank") Then tmpVal = 8 If (GetSquare(8)=tmpComputer And GetSquare(9)=tmpComputer And GetSquare(7)="Blank") Then tmpVal = 7 If (GetSquare(1)=tmpComputer And GetSquare(4)=tmpComputer And GetSquare(7)="Blank") Then tmpVal = 7 If (GetSquare(1)=tmpComputer And GetSquare(7)=tmpComputer And GetSquare(4)="Blank") Then tmpVal = 4 If (GetSquare(4)=tmpComputer And GetSquare(7)=tmpComputer And GetSquare(1)="Blank") Then tmpVal = 1 If (GetSquare(2)=tmpComputer And GetSquare(5)=tmpComputer And GetSquare(8)="Blank") Then tmpVal = 8 If (GetSquare(2)=tmpComputer And GetSquare(8)=tmpComputer And GetSquare(5)="Blank") Then tmpVal = 5 If (GetSquare(5)=tmpComputer And GetSquare(8)=tmpComputer And GetSquare(2)="Blank") Then tmpVal = 2 If (GetSquare(3)=tmpComputer And GetSquare(6)=tmpComputer And GetSquare(9)="Blank") Then tmpVal = 9 If (GetSquare(3)=tmpComputer And GetSquare(9)=tmpComputer And GetSquare(6)="Blank") Then tmpVal = 6 If (GetSquare(1)=tmpComputer And GetSquare(5)=tmpComputer And GetSquare(9)="Blank") Then tmpVal = 9 If (GetSquare(1)=tmpComputer And GetSquare(9)=tmpComputer And GetSquare(5)="Blank") Then tmpVal = 5 If (GetSquare(5)=tmpComputer And GetSquare(9)=tmpComputer And GetSquare(1)="Blank") Then tmpVal = 1 If (GetSquare(3)=tmpComputer And GetSquare(5)=tmpComputer And GetSquare(7)="Blank") Then tmpVal = 7 If (GetSquare(3)=tmpComputer And GetSquare(7)=tmpComputer And GetSquare(5)="Blank") Then tmpVal = 5 If (GetSquare(5)=tmpComputer And GetSquare(7)=tmpComputer And GetSquare(3)="Blank") Then tmpVal = 3 CanWin = tmpVal End Function%> <% Function RandomMove Do tmpVal = Int((9) * Rnd + 1) Loop Until GetSquare (tmpVal) = "Blank" RandomMove = tmpVal End Function %> <% Function Move4to8 tmpVal = 0 tmpVal = tmpVal + CanWin If tmpVal = 0 Then tmpVal = CanLose If (tmpVal = 0 And GetSquare (5) = "Blank") Then tmpVal = 5 If (tmpVal = 0 And GetSquare (5) <> "Blank") Then tmpVal = RandomMove Move4to8 = tmpVal End Function %> <% Function Move9 For tmpCount = 1 To 9 If GetSquare (tmpCount) = "Blank" Then Move9 = tmpCount Next End Function %> <% Sub ComputerMove If tmpMoves = "" Then tmpMoves = "000000000" End If Randomize Select Case tmpMoveNum Case 1 tmpTheMove = Int((9) * Rnd + 1) Case 2 tmpTheMove = Move2 Case 3 tmpTheMove = Move3 Case 4, 5, 6, 7, 8 tmpTheMove = Move4to8 Case 9 tmpTheMove = Move9 End Select For tmpCount = 1 to 9 If tmpCount <> tmpTheMove Then Select Case GetSquare (tmpCount) Case "X" tmpUsed = tmpUsed + RandomX Case "O" tmpUsed = tmpUsed + RandomO Case "Blank" tmpUsed = tmpUsed + RandomBlank End Select Else If tmpComputer = "O" Then tmpUsed = tmpUsed + RandomO Else tmpUsed = tmpUsed + RandomX End If End If Next tmpMoves = tmpUsed tmpMoveNum = tmpMoveNum + 1 End Sub %> <% Sub ShowSquare (SquareNum) tmpSquare = GetSquare (squareNum) If (tmpSquare = "Blank" And tmpWon = "0") then %>&Computer=<%=tmpComputer%><%End If%>&MoveNum=<%=tmpMoveNum + 1 %>&Moves=<%= CalcMovesURL (SquareNum) %>" OnMouseOver="document.Image<%=squarenum%>.src=Gray<% If tmpMoveNum Mod 2 = 0 Then%>O<%Else%>X<%End If %>.src;" OnMouseOut="document.Image<%=squarenum%>.src=GrayOff.src;"><% End If %> alt="Click here to move"<% End If %> border="0"><% If (tmpSquare = "Blank" And tmpWon = "0") then %><% End If %><% End Sub %> <% Sub ShowGameBoard If tmpPlayers = 1 And tmpWon = "0" Then If (tmpMoveNum Mod 2=0 And tmpComputer="O") Or (tmpMoveNum Mod 2=1 And tmpComputer="X") Then ComputerMove End If CheckWin End If%>
<% ShowSquare (1) %> <% ShowSquare (2) %> <% ShowSquare (3) %>
<% ShowSquare (4) %> <% ShowSquare (5) %> <% ShowSquare (6) %>
<% ShowSquare (7) %> <% ShowSquare (8) %> <% ShowSquare (9) %>

<% If tmpWon <> "0" then %>

<%=tmpWon%> won the game in <%=tmpMoveNum - 1%> Moves!

Click here to Play again

<%Else If tmpMoveNum > 9 then %>

It's a Cat game!

Click here to Play again

<% End If End If %>
<% End Sub %> <% CheckWin %> <% If tmpPlayers = "" Then %> Tic-Tac-Toe - Select a game type <% End If %> <% If tmpPlayers = "1" And tmpMoveNum = "" Then %> Tic-Tac-Toe - Select who goes first <% End If %> <% If tmpMoveNum <> "" Then %> Tic-Tac-Toe <% End If %>

Tic-Tac-Toe


<% If tmpPlayers = "" Then %> <% tmpAction = Request ("Action") %> <% If tmpAction = "Rules" Then %>

The object of Tic Tac Toe is to get three in a row. You play on a three by three game board. One player is known as X's and the other is O's. Players alternate placing their X's and O's on the game board until either oppent has three in a row or all nine squares are filled. X's always go first, and in the event that no one has three in a row, the stalemate is called a cat game.

In a One Player Game you play against the computer. You may go first if you select to be X's, otherwise the computer will go first. The Computer is programmed to try to not loose, however this does not mean you can not win.

In a Vs Game you will play against a real human opponet. They may be anywhere in the world and may or may not speak you language however, they are playing you Tic-Tac-Toe. Vs Games are not functional yet, but willbe soon.

In a Two player game you play against another person who is using the same computer as you. This means they must be sitting right next to you. Usually this is doen if you are having a party and are bored, or if you have smaller children you wish to teach how to play Tic Tac Toe.

<% End If %> <%If tmpAction = "Score" Then %> <% End If %> <%If tmpAction = "" Then %>

Please select a game type.

One Player Two Players

One Player Vs.
The Computer

One Player Vs.
Internet Opponent

Two Players Using
This Computer

<% End If %> <% End If %> <% If tmpPlayers = "1" And tmpMoveNum = "" Then %>

Please select who goes first.


You play as X's

You play as O's

<% End If %> <% If tmpPlayers <> "" And tmpMoveNum <> "" Then ShowGameBoard End If%> <% If tmpWon = "0" And tmpMoveNum <> "10" And tmpMoveNum <> "11" Then %> <% If (tmpPlayers=2 And tmpMoveNum Mod 2=1) Or (tmpPlayers=1 And tmpComputer="O") Then %>

X, Click on an empty square

<% End If %> <% If (tmpPlayers=2 And tmpMoveNum Mod 2=0) Or (tmpPlayers=1 And tmpComputer="X") Then %>

O, Click on an empty square

<% End If %> <% End If %>

[ Main Menu | One Player Vs O's | One Player Vs X's | Two Players | Rules | Scores ]