ASP,version,TicTacToe,beat,computer,getting
Quick Search for:  in language:    
ASP,version,TicTacToe,beat,computer,getting
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
ASP/ VbScript Stats

 Code: 144,429 lines
 Jobs: 168 postings

 
Sponsored by:

 

You are in:

 
Login


 

 


Latest Code Ticker for ASP/ VbScript.
Click here to see a screenshot of this code!Ping in ASP
By Michele_Garneri on 10/28

(Screen Shot)

Embed Real Player Object
By Ziae Mousavi m. on 10/27


Set Country --> Combobox
By Hohl David on 10/27


Client Side Sorting of records
By Ravi Rajan on 10/26


Recordset paging with images
By Ravi Rajan on 10/26


Click here to see a screenshot of this code!Online photo catalogue VBScript 2.1
By Ivan Loire on 10/26

(Screen Shot)

GPS 1.4 WYSIWYG
By Guo Xu on 10/25


Click here to see a screenshot of this code!A Network Monitor tool from ActivXperts Software Inc.
By Freddy Hofstadt on 10/25

(Screen Shot)

Socket samples based on Winsock, TCP/IP and client/server communication
By Ronny Bright on 10/25


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!





Affiliate Sites



 
 
   

ASP TicTacToe

Print
Email
 
VB icon
Submitted on: 11/1/2000 5:52:08 AM
By: Owen Cutajar  
Level: Intermediate
User Rating: By 2 Users
Compatibility:ASP (Active Server Pages)

Users have accessed this code 7426 times.
 
(About the author)
 
     ASP version of TicTacToe. Try to beat the computer at getting 3 Xs in a row.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

    '**************************************
    ' Name: ASP TicTacToe
    ' Description:ASP version of TicTacToe. 
    '     Try to beat the computer at getting 3 Xs
    '     in a row.
    ' By: Owen Cutajar
    '
    ' Inputs:N/A
    '
    ' Returns:N/A
    '
    ' Assumes:Code is fully self-sufficient,
    '     incorporating both the display and game 
    '     logic. It's interesting to note that the
    '     game was converted to ASP from Javascrip
    '     t.
    '
    ' Side Effects:N/A
    '
    'This code is copyrighted and has    ' limited warranties.Please see http://w
    '     ww.Planet-Source-Code.com/xq/ASP/txtCode
    '     Id.6364/lngWId.4/qx/vb/scripts/ShowCode.
    '     htm    'for details.    '**************************************
    
    <%
    '---------------------------------------
    '     -----------------------
    ' ASP TicTacToe v1.0
    ' (x) Ugh!! 2000 - 18/10/2000
    '
    ' based on Javascript TicTacToe by
    ' Maximilian Stocker (maxstocker@reallyu
    '     sefulcomputing.com)
    '
    ' Written for http://www.only-network.co
    '     m/games Any comments, 
    ' flames, requests, postcards etc to owe
    '     n@cutajar.net
    '---------------------------------------
    '     -----------------------
    Option Explicit
    ' -- Set up images to use ---
    Const IMGx = "x.jpg"
    Const IMGo = "o.jpg"
    Const IMGblank = "blank.jpg"
    ' -- Set up game States ---
    Const END_Not_Yet = 0
    Const END_You_Win = 1
    Const END_Computer_Win = 2
    Const END_Tie = 3
    ' Read in board or Initialise
    Dim Gameboard
    Dim wl1,wl2,wl3,wl4,wl5,wl6,wl7,wl8
    if Session("GameBoard") & "" = "" OR Request("PlayAgain") = "Yes" Then 
    	PlayAgain
    End if
    GameBoard = Split(Session("GameBoard"),"_")
    function GameState() 
    	wl1 = GameBoard(0) & GameBoard(1) & GameBoard(2)
    	wl2 = GameBoard(0) & GameBoard(3) & GameBoard(6)
    	wl3 = GameBoard(0) & GameBoard(4) & GameBoard(8)
    	wl4 = GameBoard(1) & GameBoard(4) & GameBoard(7)
    	wl5 = GameBoard(3) & GameBoard(4) & GameBoard(5)
    	wl6 = GameBoard(6) & GameBoard(7) & GameBoard(8)
    	wl7 = GameBoard(2) & GameBoard(5) & GameBoard(8)
    	wl8 = GameBoard(6) & GameBoard(4) & GameBoard(2)
    	if wl1="XXX" or wl2="XXX" or wl3="XXX" or wl4="XXX" or wl5="XXX" or wl6="XXX" or wl7="XXX" or wl8="XXX" Then
    		GameState = END_You_Win
    	ElseIf wl1="OOO" or wl2="OOO" or wl3="OOO" or wl4="OOO" or wl5="OOO" or wl6="OOO" or wl7="OOO" or wl8="OOO" Then
    		GameState = END_Computer_Win
    	ElseIf Instr ( wl1 & wl5 & wl6 ,"B" ) = 0 Then
    		GameState = END_Tie
    	Else
    		GameState = END_Not_Yet
    	End if
    End function
    function Suggest() 
    	if wl1 = "XXB" or wl1 = "OOB" Then
    		Suggest = 2
    	ElseIf wl1 = "XBX" or wl1 = "OBO" Then
    		Suggest = 1
    	ElseIf wl1 = "BXX" or wl1 = "BOO" Then
    		Suggest = 0
    	ElseIf wl2 = "XXB" or wl2 = "OOB" Then
    		Suggest = 6
    	ElseIf wl2 = "XBX" or wl2 = "OBO" Then
    		Suggest = 3
    	ElseIf wl2 = "BXX" or wl2 = "BOO" Then
    		Suggest = 0
    	ElseIf wl3 = "XXB" or wl3 = "OOB" Then
    		Suggest = 8
    	ElseIf wl3 = "XBX" or wl3 = "OBO" Then
    		Suggest = 4
    	ElseIf wl3 = "BXX" or wl3 = "BOO" Then
    		Suggest = 0
    	ElseIf wl4 = "XXB" or wl4 = "OOB" Then
    		Suggest = 7
    	ElseIf wl4 = "XBX" or wl4 = "OBO" Then
    		Suggest = 4
    	ElseIf wl4 = "BXX" or wl4 = "BOO" Then
    		Suggest = 1
    	ElseIf wl5 = "XXB" or wl5 = "OOB" Then
    		Suggest = 5
    	ElseIf wl5 = "XBX" or wl5 = "OBO" Then
    		Suggest = 4
    	ElseIf wl5 = "BXX" or wl5 = "BOO" Then
    		Suggest = 3
    	ElseIf wl6 = "XXB" or wl6 = "OOB" Then
    		Suggest = 8
    	ElseIf wl6 = "XBX" or wl6 = "OBO" Then
    		Suggest = 7
    	ElseIf wl6 = "BXX" or wl6 = "BOO" Then
    		Suggest = 6
    	ElseIf wl7 = "XXB" or wl7 = "OOB" Then
    		Suggest = 8
    	ElseIf wl7 = "XBX" or wl7 = "OBO" Then
    		Suggest = 5
    	ElseIf wl7 = "BXX" or wl7 = "BOO" Then
    		Suggest = 2
    	ElseIf wl8 = "XXB" or wl8 = "OOB" Then
    		Suggest = 2
    	ElseIf wl8 = "XBX" or wl8 = "OBO" Then
    		Suggest = 4
    	ElseIf wl8 = "BXX" or wl8 = "BOO" Then
    		Suggest = 6
    	Else
    		Suggest = -1
    	End if
    End function
    Sub yourChoice(Position) 
    	if Session("State") = "Dead" Then 
    		ReportEnded
    	Else
    		if GameBoard(Position) <> "B" Then
    			ReportTaken
    		Else
    			GameBoard(Position) = "X"
    		End if
    	End if
    End Sub
    Sub ReportTaken() 
    	Response.Write "<H2>That square is already occupied. Please Select another square.</H2>"
    End Sub
    Sub ReportEnded()
    	Response.Write "<H2>The game has already ended. To play a new game click the Play Again button.</H2>"
    End Sub
    Sub myChoice() 
    	Dim NewMove
    	NewMove = Suggest()
    	While NewMove = -1
    		Randomize
    		NewMove=int(rnd*9) 
    		if GameBoard(NewMove) <> "B" Then
    			NewMove = -1
    		End if
    	Wend
    	GameBoard(NewMove) = "O"
    End Sub
    Sub ProcessBoard() 
    	if Session("State") = "Alive" Then
    		Select Case GameState()
    			Case END_You_Win 
    				Response.Write "<H2>You won, congratulations!<H2>"
    				Session("you") = Session("you") + 1
    				Session("State") = "Dead"
    			Case END_Computer_Win
    				Response.Write "<H2>Gotcha! I win!</H2>"
    				Session("computer") = Session("computer") + 1
    				Session("State") = "Dead"
    			Case END_Tie
    				Response.Write "<H2>We tied.</H2>"
    				Session("ties") = Session("ties") + 1
    				Session("State") = "Dead"
    		End Select
    	End if
    End Sub
    Sub playAgain() 
    	Session("GameBoard") = "B_B_B_B_B_B_B_B_B"
    	Session("State") = "Alive"
    End Sub
    Sub Display(CellNum)
    	if GameBoard(CellNum) = "B" Then
    		Response.Write "<FORM action=tictactoe.asp method=post>"
    		Response.Write "<INPUT type=hidden name=pressed value=" & CellNum & ">"
    		Response.Write "<INPUT type=image src=" & IMGblank & " border=0 height=100 width=100>"
    		Response.Write "</FORM>"
    	ElseIf GameBoard(CellNum) = "O" Then
    		Response.Write "<Img src=" & IMGo & " border=0 height=100 width=100>"
    	ElseIf GameBoard(CellNum) = "X" Then
    		Response.Write "<Img src=" & IMGx & " border=0 height=100 width=100>"
    	End if
    End Sub
    ' Main Code
    if Request("Pressed") & "" <> "" Then
    	YourChoice(Request("Pressed"))
    	ProcessBoard
    	if GameState() = END_Not_Yet Then
    		myChoice
    	End if
    	ProcessBoard
    	' Save Game State
    	Session("GameBoard") = Join(GameBoard,"_")
    End if
    %>
    <HTML>
    <HEAD>
    </HEAD>
    <BODY>
    <CENTER>
    Welcome To Tic-Tac-Toe! You play as the X's and the computer is the O's. Select the square you want to put your X into by clicking them. You cannot occupy a square that is already occupied. The first player to Get three squares in a row wins. Good Luck!!
    <FORM name=game action=tictactoe.asp>
    <TABLE border=0>
    <TR>
    <TD>
    <TABLE border=1>
    <TR height=120>
    <TD><% Display(0) %></TD>
    <TD><% Display(1) %></TD>
    <TD><% Display(2) %></TD>
    </TR>
    <TR height=120>
    <TD><% Display(3) %></TD>
    <TD><% Display(4) %></TD>
    <TD><% Display(5) %></TD>
    </TR>
    <TR height=120>
    <TD><% Display(6) %></TD>
    <TD><% Display(7) %></TD>
    <TD><% Display(8) %></TD>
    </TR>
    </TABLE>
    </TD>
    <TD>
    <TABLE>
    <TR><TD><INPUT type=text size=5 name=you value=<%=Session("you")%>></TD><TD>You</TD></TR>
    <TR><TD><INPUT type=text size=5 name=computer value=<%=Session("computer")%>></TD><TD>Computer</TD></TR>
    <TR><TD><INPUT type=text size=5 name=ties value=<%=Session("ties")%>></TD><TD>Ties</TD></TR>
    </TABLE>
    </TD></TR>
    </TABLE>
    <FORM action=tictactoe.asp>
    <INPUT type=hidden name=PlayAgain value=Yes>
    <INPUT type=submit value="Play Again">
    </FORM>
    </CENTER>
    </BODY>
    </HTML>


Other 1 submission(s) by this author

 

 
Report Bad Submission
Use this form to notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
Your Vote!

What do you think of this code(in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor See Voting Log
 
Other User Comments
9/24/2002 4:21:31 AM:
didn't show anything
Keep the Planet clean! If this comment was disrespectful, please report it:
Reason:

 
Add Your Feedback!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | ASP/ VbScript Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.