找回密碼 或 安全提問
 註冊
|註冊|登錄

伊莉討論區

搜索
尊貴會員無限觀看附件圖片伊莉需要你的贊助和支持儲值後自動升級用戶組
mg霹靂julia出包王女overlord3d無碼 ge
性癖討論天使なの波涛汹涌早乙女ル重磅mj河北幸福家庭

休閒聊天興趣交流學術文化旅遊交流飲食交流家庭事務PC GAMETV GAME
熱門線上其他線上感情感性寵物交流家族門派動漫交流貼圖分享BL/GL
音樂世界影視娛樂女性頻道潮流資訊BT下載區GB下載區下載分享短片
電腦資訊數碼產品手機交流交易廣場網站事務長篇小說體育運動時事經濟
上班一族博彩娛樂

[繁/無修正]夢想成為

中國老頭在香港淺水灣

[繁]藥師少女的獨語24

[繁]因為不是真正的夥

[繁/無修正]夢想成為

[繁]迷宮飯09-
C & C++ 語言C# 語言Visual Basic 語言PHP 語言JAVA 語言
查看: 10870|回復: 11

[原創] 井字遊戲AI[複製鏈接]

Rank: 1

帖子
1699
積分
174 點
潛水值
45030 米
發表於 2016-12-1 03:11 PM|顯示全部樓層
本帖最後由 zxc693491 於 2016-12-1 03:42 PM 編輯

自己做的井字遊戲AI  請大家幫我測試看看,希望能找到錯誤,原則上不可能贏他就是了。
另外這是雙人版(做得很難看消磨時間用:
以下提供參考,我用按鈕物件寫的"VB2010"
  1. [/backcolor]Public Class 井字遊戲
  2.     Dim time As Integer
  3.     Dim att As Integer           '狀況標記
  4.     Dim cheak As Boolean = False '是否已判斷勝負
  5.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  6.         MsgBox("歡迎遊玩井字遊戲,退出請按鍵盤Alt+F4鍵", vbOKOnly, "")
  7.         N()
  8.         S()
  9.         Me.Focus()
  10.         FormBorderStyle = Windows.Forms.FormBorderStyle.None
  11.     End Sub
  12.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  13.         Button1.Text = "○"
  14.         Button1.Enabled = False
  15.         time = time + 1
  16.         If att = 22 Then
  17.             time = 3
  18.         End If
  19.         AI()
  20.     End Sub '按鈕群
  21.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  22.         Button2.Text = "○"
  23.         Button2.Enabled = False
  24.         time = time + 1
  25.         If att = 22 Then
  26.             time = 3
  27.         End If
  28.         AI()
  29.     End Sub '按鈕群
  30.     Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  31.         Button3.Text = "○"
  32.         Button3.Enabled = False
  33.         time = time + 1
  34.         If att = 22 Then
  35.             time = 3
  36.         End If
  37.         AI()
  38.     End Sub '按鈕群
  39.     Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  40.         Button4.Text = "○"
  41.         Button4.Enabled = False
  42.         time = time + 1
  43.         If att = 22 Then
  44.             time = 3
  45.         End If
  46.         AI()
  47.     End Sub '按鈕群
  48.     Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
  49.         Button5.Text = "○"
  50.         Button5.Enabled = False
  51.         time = time + 1
  52.         If att = 22 Then
  53.             time = 3
  54.         End If
  55.         AI()
  56.     End Sub '按鈕群
  57.     Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
  58.         Button6.Text = "○"
  59.         Button6.Enabled = False
  60.         time = time + 1
  61.         If att = 22 Then
  62.             time = 3
  63.         End If
  64.         AI()
  65.     End Sub '按鈕群
  66.     Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
  67.         Button7.Text = "○"
  68.         Button7.Enabled = False
  69.         time = time + 1
  70.         If att = 22 Then
  71.             time = 3
  72.         End If
  73.         AI()
  74.     End Sub '按鈕群
  75.     Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
  76.         Button8.Text = "○"
  77.         Button8.Enabled = False
  78.         time = time + 1
  79.         If att = 22 Then
  80.             time = 3
  81.         End If
  82.         AI()
  83.     End Sub '按鈕群
  84.     Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
  85.         Button9.Text = "○"
  86.         Button9.Enabled = False
  87.         time = time + 1
  88.         If att = 22 Then
  89.             time = 3
  90.         End If
  91.         AI()
  92.     End Sub '按鈕群
  93.     '======================================================================================================================
  94.     Sub S()
  95.         If MsgBox("是否先下?", MsgBoxStyle.YesNo, "順序") = MsgBoxResult.No Then
  96.             AIstep1()
  97.         Else
  98.             N()
  99.         End If
  100.         cheak = False
  101.     End Sub        '開始
  102.     Sub N() '復原
  103.         Button1.Enabled = True
  104.         Button2.Enabled = True
  105.         Button3.Enabled = True
  106.         Button4.Enabled = True
  107.         Button5.Enabled = True
  108.         Button6.Enabled = True
  109.         Button7.Enabled = True
  110.         Button8.Enabled = True
  111.         Button9.Enabled = True
  112.         Button1.Text = ""
  113.         Button2.Text = ""
  114.         Button3.Text = ""
  115.         Button4.Text = ""
  116.         Button5.Text = ""
  117.         Button6.Text = ""
  118.         Button7.Text = ""
  119.         Button8.Text = ""
  120.         Button9.Text = ""
  121.         att = 1
  122.         time = 1
  123.     End Sub        '初始化
  124.     Sub AI()
  125.         WinCheak()
  126.         If cheak = True Then
  127.             cheak = False
  128.             Exit Sub
  129.         End If
  130.         If time = 2 Then
  131.             AIstep2()
  132.             Exit Sub
  133.         End If
  134.         If time = 3 Then
  135.             AIstep3()
  136.             Exit Sub
  137.         End If
  138.         If time = 4 Then
  139.             AIstep4()
  140.             Exit Sub
  141.         End If
  142.         If time = 5 Then
  143.             AIstep5()
  144.             Exit Sub
  145.         End If
  146.         If time = 6 Then
  147.             AIstep6()
  148.             Exit Sub
  149.         End If
  150.         If time = 7 Then
  151.             AIstep7()
  152.             Exit Sub
  153.         End If
  154.         If time = 8 Then
  155.             AIstep8()
  156.             Exit Sub
  157.         End If
  158.         If time = 9 Then
  159.             AIstep9()
  160.             Exit Sub
  161.         End If
  162.     End Sub       '步數判斷
  163.     Sub AIstep1() '先攻搶角
  164.         Button3.Text = "X"
  165.         Button3.Enabled = False
  166.         time = 2
  167.         att = 22
  168.     End Sub
  169.     Sub AIstep2()
  170.         If Button1.Text = "○" Then
  171.             Button5.Text = "X"
  172.             Button5.Enabled = False
  173.             att = 1
  174.         ElseIf Button2.Text = "○" Then
  175.             Button5.Text = "X"
  176.             Button5.Enabled = False
  177.             att = 0
  178.         ElseIf Button3.Text = "○" Then
  179.             Button5.Text = "X"
  180.             Button5.Enabled = False
  181.             att = 1
  182.         ElseIf Button4.Text = "○" Then
  183.             Button5.Text = "X"
  184.             Button5.Enabled = False
  185.             att = 0
  186.         ElseIf Button5.Text = "○" Then
  187.             Button3.Text = "X"
  188.             Button3.Enabled = False
  189.             att = 0
  190.         ElseIf Button6.Text = "○" Then
  191.             Button5.Text = "X"
  192.             Button5.Enabled = False
  193.             att = 43
  194.         ElseIf Button7.Text = "○" Then
  195.             Button5.Text = "X"
  196.             Button5.Enabled = False
  197.             att = 1
  198.         ElseIf Button8.Text = "○" Then
  199.             Button5.Text = "X"
  200.             Button5.Enabled = False
  201.             att = 43
  202.         ElseIf Button9.Text = "○" Then
  203.             Button5.Text = "X"
  204.             Button5.Enabled = False
  205.             att = 1
  206.         End If
  207.         time = 3
  208.     End Sub
  209.     Sub AIstep3() '開二路
  210.         If Button1.Text = "○" Then
  211.             Button9.Text = "X"
  212.             Button9.Enabled = False
  213.             att = 1
  214.         End If
  215.         If Button2.Text = "○" Then
  216.             Button9.Text = "X"
  217.             Button9.Enabled = False
  218.             att = 2
  219.         End If
  220.         If Button4.Text = "○" Then
  221.             Button5.Text = "X"
  222.             Button5.Enabled = False
  223.             att = 4
  224.         End If
  225.         If Button5.Text = "○" Then
  226.             Button7.Text = "X"
  227.             Button7.Enabled = False
  228.             att = 5
  229.         End If
  230.         If Button6.Text = "○" Then
  231.             Button1.Text = "X"
  232.             Button1.Enabled = False
  233.             att = 6
  234.         End If
  235.         If Button7.Text = "○" Then
  236.             Button9.Text = "X"
  237.             Button9.Enabled = False
  238.             att = 7
  239.         End If
  240.         If Button8.Text = "○" Then
  241.             Button5.Text = "X"
  242.             Button5.Enabled = False
  243.             att = 8
  244.         End If
  245.         If Button9.Text = "○" Then
  246.             Button1.Text = "X"
  247.             Button1.Enabled = False
  248.             att = 9
  249.         End If
  250.         time = 4
  251.     End Sub
  252.     Sub AIstep4()
  253.         If att = 0 Then
  254.             If (Button2.Enabled = False And Button8.Enabled = False) Or (Button4.Enabled = False And Button6.Enabled = False) Then
  255.                 Button1.Text = "X"
  256.                 Button1.Enabled = False
  257.                 time = 5
  258.                 Exit Sub
  259.             End If
  260.             AI2()
  261.         ElseIf att = 1 Then
  262.             If (Button1.Enabled = False And Button9.Enabled = False) Or (Button3.Enabled = False And Button7.Enabled = False) Then
  263.                 Button2.Text = "X"
  264.                 Button2.Enabled = False
  265.                 time = 5
  266.                 Exit Sub
  267.             Else
  268.                 AI2()
  269.             End If
  270.         ElseIf att = 43 Then
  271.             If Button4.Text = "○" And Button8.Text = "○" Then
  272.                 Button7.Text = "X"
  273.                 Button7.Enabled = False
  274.             Else
  275.                 Button3.Text = "X"
  276.                 Button3.Enabled = False
  277.             End If
  278.         End If
  279.         time = 5
  280.     End Sub
  281.     Sub AIstep5()
  282.         If att = 1 Then
  283.             If Button6.Text = "○" Then
  284.                 Button7.Text = "X"
  285.                 Button7.Enabled = False
  286.             Else
  287.                 Button6.Text = "X"
  288.                 Button6.Enabled = False
  289.             End If
  290.         ElseIf att = 2 Then
  291.             If Button6.Text = "○" Then
  292.                 Button7.Text = "X"
  293.                 Button7.Enabled = False
  294.             Else
  295.                 Button6.Text = "X"
  296.                 Button6.Enabled = False
  297.             End If
  298.         ElseIf att = 4 Then
  299.             If Button7.Text = "○" Then
  300.                 Button1.Text = "X"
  301.                 Button1.Enabled = False
  302.             Else
  303.                 Button7.Text = "X"
  304.                 Button7.Enabled = False
  305.             End If
  306.         ElseIf att = 5 Then
  307.             If Button1.Text = "○" Then
  308.                 Button9.Text = "X"
  309.                 Button9.Enabled = False
  310.             ElseIf Button9.Text = "○" Then
  311.                 Button1.Text = "X"
  312.                 Button1.Enabled = False
  313.             Else
  314.                 If Button2.Text = "○" Then
  315.                     Button8.Text = "X"
  316.                     Button8.Enabled = False
  317.                     att = 9
  318.                 ElseIf Button4.Text = "○" Then
  319.                     Button6.Text = "X"
  320.                     Button6.Enabled = False
  321.                     att = 9
  322.                 ElseIf Button6.Text = "○" Then
  323.                     Button4.Text = "X"
  324.                     Button4.Enabled = False
  325.                     att = 1
  326.                 ElseIf Button8.Text = "○" Then
  327.                     Button2.Text = "X"
  328.                     Button2.Enabled = False
  329.                     att = 1
  330.                 End If
  331.             End If
  332.         ElseIf att = 6 Then
  333.             If Button2.Enabled = False Then
  334.                 Button7.Text = "X"
  335.                 Button7.Enabled = False
  336.             Else
  337.                 Button2.Text = "X"
  338.                 Button2.Enabled = False
  339.             End If
  340.         ElseIf att = 7 Then
  341.             If Button6.Enabled = False Then
  342.                 Button1.Text = "X"
  343.                 Button1.Enabled = False
  344.             Else
  345.                 Button6.Text = "X"
  346.                 Button6.Enabled = False
  347.             End If
  348.         ElseIf att = 8 Then
  349.             If Button7.Enabled = False Then
  350.                 Button9.Text = "X"
  351.                 Button9.Enabled = False
  352.             Else
  353.                 Button7.Text = "X"
  354.                 Button7.Enabled = False
  355.             End If
  356.         ElseIf att = 9 Then
  357.             If Button2.Enabled = False Then
  358.                 Button7.Text = "X"
  359.                 Button7.Enabled = False
  360.             Else
  361.                 Button2.Text = "X"
  362.                 Button2.Enabled = False
  363.             End If
  364.         End If
  365.         time = 6
  366.         WinCheak()
  367.         If cheak = True Then
  368.             N()
  369.             S()
  370.         End If
  371.     End Sub
  372.     Sub AIstep6()
  373.         AI3()
  374.         If cheak = True Then
  375.             N()
  376.             S()
  377.             Exit Sub
  378.         End If
  379.         AI5()
  380.         time = 7
  381.         If att = 99 Then
  382.             Exit Sub
  383.         End If
  384.         AI2()
  385.     End Sub
  386.     Sub AIstep7()
  387.         AI3()
  388.         If cheak = True Then
  389.             N()
  390.             S()
  391.             Exit Sub
  392.         End If
  393.         AI2()
  394.         time = 8
  395.         WinCheak()
  396.         If cheak = True Then
  397.             N()
  398.             S()
  399.         End If
  400.     End Sub
  401.     Sub AIstep8()
  402.         att = 1
  403.         AI3()
  404.         If cheak = True Then
  405.             N()
  406.             S()
  407.             Exit Sub
  408.         End If
  409.         AI2()
  410.         If att = 96 Then
  411.             time = 9
  412.             WinCheak()
  413.             If cheak = True Then
  414.                 N()
  415.                 S()
  416.             End If
  417.             Exit Sub
  418.         End If
  419.         If Button2.Enabled = True Then
  420.             Button2.Text = "X"
  421.             Button2.Enabled = False
  422.             att = 97
  423.         ElseIf Button4.Enabled = True Then
  424.             Button4.Text = "X"
  425.             Button4.Enabled = False
  426.             att = 97
  427.         ElseIf Button6.Enabled = True Then
  428.             Button6.Text = "X"
  429.             Button6.Enabled = False
  430.             att = 97
  431.         ElseIf Button8.Enabled = True Then
  432.             Button8.Text = "X"
  433.             Button8.Enabled = False
  434.             att = 97
  435.         End If
  436.         If att = 97 Then
  437.             time = 9
  438.             WinCheak()
  439.             If cheak = True Then
  440.                 N()
  441.                 S()
  442.             End If
  443.             Exit Sub
  444.         End If
  445.         WinCheak()
  446.         If cheak = True Then
  447.             N()
  448.             S()
  449.         Else
  450.             time = 9
  451.         End If
  452.     End Sub
  453.     Sub AIstep9()
  454.         AI3()
  455.         If cheak = True Then
  456.             N()
  457.             S()
  458.             Exit Sub
  459.         End If
  460.         AI2()
  461.         If att = 96 Then
  462.             time = 10
  463.             WinCheak()
  464.             If cheak = True Then
  465.                 N()
  466.                 S()
  467.             End If
  468.             Exit Sub
  469.         End If
  470.         If (Button2.Text = "X" Or Button4.Text = "X") And Button1.Enabled = True Then
  471.             Button1.Text = "X"
  472.             Button1.Enabled = False
  473.         ElseIf (Button2.Text = "X" Or Button4.Text = "X") And Button9.Enabled = True Then
  474.             Button9.Text = "X"
  475.             Button9.Enabled = False
  476.         ElseIf Button1.Enabled = False And Button9.Enabled = False Then
  477.             If Button2.Enabled = True Then
  478.                 Button2.Text = "X"
  479.                 Button2.Enabled = False
  480.             ElseIf Button4.Enabled = True Then
  481.                 Button4.Text = "X"
  482.                 Button4.Enabled = False
  483.             ElseIf Button6.Enabled = True Then
  484.                 Button6.Text = "X"
  485.                 Button6.Enabled = False
  486.             ElseIf Button8.Enabled = True Then
  487.                 Button8.Text = "X"
  488.                 Button8.Enabled = False
  489.             ElseIf Button7.Enabled = True Then
  490.                 Button7.Text = "X"
  491.                 Button7.Enabled = False
  492.             End If
  493.         Else
  494.             If Button1.Enabled = True Then
  495.                 Button1.Text = "X"
  496.                 Button1.Enabled = False
  497.             Else
  498.                 Button9.Text = "X"
  499.                 Button9.Enabled = True
  500.             End If
  501.         End If
  502.         WinCheak()
  503.         If cheak = True Then
  504.             N()
  505.             S()
  506.         Else
  507.             MsgBox("平手囉", MsgBoxStyle.OkOnly, "勝負判斷")
  508.             N()
  509.             S()
  510.         End If
  511.     End Sub
  512.     Sub WinCheak()
  513.         If Button1.Text = Button2.Text And Button1.Text = Button3.Text And Button1.Text <> "" Then
  514.             MsgBox("你輸了", MsgBoxStyle.OkOnly, "勝負判斷")
  515.             cheak = True
  516.         ElseIf Button4.Text = Button5.Text And Button4.Text = Button6.Text And Button4.Text <> "" Then
  517.             MsgBox("你輸了", MsgBoxStyle.OkOnly, "勝負判斷")
  518.             cheak = True
  519.         ElseIf Button7.Text = Button8.Text And Button7.Text = Button9.Text And Button7.Text <> "" Then
  520.             MsgBox("你輸了", MsgBoxStyle.OkOnly, "勝負判斷")
  521.             cheak = True
  522.         ElseIf Button1.Text = Button4.Text And Button1.Text = Button7.Text And Button1.Text <> "" Then
  523.             MsgBox("你輸了", MsgBoxStyle.OkOnly, "勝負判斷")
  524.             cheak = True
  525.         ElseIf Button2.Text = Button5.Text And Button2.Text = Button8.Text And Button2.Text <> "" Then
  526.             MsgBox("你輸了", MsgBoxStyle.OkOnly, "勝負判斷")
  527.             cheak = True
  528.         ElseIf Button3.Text = Button6.Text And Button3.Text = Button9.Text And Button3.Text <> "" Then
  529.             MsgBox("你輸了", MsgBoxStyle.OkOnly, "勝負判斷")
  530.             cheak = True
  531.         ElseIf Button1.Text = Button5.Text And Button1.Text = Button9.Text And Button1.Text <> "" Then
  532.             MsgBox("你輸了", MsgBoxStyle.OkOnly, "勝負判斷")
  533.             cheak = True
  534.         ElseIf Button3.Text = Button5.Text And Button3.Text = Button7.Text And Button3.Text <> "" Then
  535.             MsgBox("你輸了", MsgBoxStyle.OkOnly, "勝負判斷")
  536.             cheak = True
  537.         ElseIf time = 10 Then
  538.             MsgBox("平手囉", MsgBoxStyle.OkOnly, "勝負判斷")
  539.             cheak = True
  540.             N()
  541.             S()
  542.         End If
  543.     End Sub '勝負判斷
  544.     '準則:能贏先下,其次阻止連線,以上沒有問題時尋找最有利位置下。
  545.     Sub AI2()
  546.         If Button1.Text = "○" And Button2.Text = "○" And Button3.Text = "" Then
  547.             Button3.Text = "X"
  548.             Button3.Enabled = False
  549.         ElseIf Button1.Text = "○" And Button3.Text = "○" And Button2.Text = "" Then
  550.             Button2.Text = "X"
  551.             Button2.Enabled = False
  552.         ElseIf Button2.Text = "○" And Button3.Text = "○" And Button1.Text = "" Then
  553.             Button1.Text = "X"
  554.             Button1.Enabled = False
  555.         ElseIf Button4.Text = "○" And Button5.Text = "○" And Button6.Text = "" Then
  556.             Button6.Text = "X"
  557.             Button6.Enabled = False
  558.         ElseIf Button4.Text = "○" And Button6.Text = "○" And Button5.Text = "" Then
  559.             Button5.Text = "X"
  560.             Button5.Enabled = False
  561.         ElseIf Button5.Text = "○" And Button6.Text = "○" And Button4.Text = "" Then
  562.             Button4.Text = "X"
  563.             Button4.Enabled = False
  564.         ElseIf Button7.Text = "○" And Button8.Text = "○" And Button9.Text = "" Then
  565.             Button9.Text = "X"
  566.             Button9.Enabled = False
  567.         ElseIf Button7.Text = "○" And Button9.Text = "○" And Button8.Text = "" Then
  568.             Button8.Text = "X"
  569.             Button8.Enabled = False
  570.         ElseIf Button8.Text = "○" And Button9.Text = "○" And Button7.Text = "" Then
  571.             Button7.Text = "X"
  572.             Button7.Enabled = False
  573.         ElseIf Button1.Text = "○" And Button4.Text = "○" And Button7.Text = "" Then
  574.             Button7.Text = "X"
  575.             Button7.Enabled = False
  576.         ElseIf Button1.Text = "○" And Button7.Text = "○" And Button4.Text = "" Then
  577.             Button4.Text = "X"
  578.             Button4.Enabled = False
  579.         ElseIf Button4.Text = "○" And Button7.Text = "○" And Button1.Text = "" Then
  580.             Button1.Text = "X"
  581.             Button1.Enabled = False
  582.         ElseIf Button2.Text = "○" And Button5.Text = "○" And Button8.Text = "" Then
  583.             Button8.Text = "X"
  584.             Button8.Enabled = False
  585.         ElseIf Button2.Text = "○" And Button8.Text = "○" And Button5.Text = "" Then
  586.             Button5.Text = "X"
  587.             Button5.Enabled = False
  588.         ElseIf Button5.Text = "○" And Button8.Text = "○" And Button2.Text = "" Then
  589.             Button2.Text = "X"
  590.             Button2.Enabled = False
  591.         ElseIf Button3.Text = "○" And Button6.Text = "○" And Button9.Text = "" Then
  592.             Button9.Text = "X"
  593.             Button9.Enabled = False
  594.         ElseIf Button3.Text = "○" And Button9.Text = "○" And Button6.Text = "" Then
  595.             Button6.Text = "X"
  596.             Button6.Enabled = False
  597.         ElseIf Button6.Text = "○" And Button9.Text = "○" And Button3.Text = "" Then
  598.             Button3.Text = "X"
  599.             Button3.Enabled = False
  600.         ElseIf Button1.Text = "○" And Button5.Text = "○" And Button9.Text = "" Then
  601.             Button9.Text = "X"
  602.             Button9.Enabled = False
  603.         ElseIf Button1.Text = "○" And Button9.Text = "○" And Button5.Text = "" Then
  604.             Button5.Text = "X"
  605.             Button5.Enabled = False
  606.         ElseIf Button5.Text = "○" And Button9.Text = "○" And Button1.Text = "" Then
  607.             Button1.Text = "X"
  608.             Button1.Enabled = False
  609.         ElseIf Button3.Text = "○" And Button5.Text = "○" And Button7.Text = "" Then
  610.             Button1.Text = "X"
  611.             Button1.Enabled = False
  612.         ElseIf Button3.Text = "○" And Button7.Text = "○" And Button5.Text = "" Then
  613.             Button5.Text = "X"
  614.             Button5.Enabled = False
  615.         ElseIf Button5.Text = "○" And Button7.Text = "○" And Button3.Text = "" Then
  616.             Button3.Text = "X"
  617.             Button3.Enabled = False
  618.         Else
  619.             AI4() '找不到防禦目標
  620.         End If
  621.         att = 96 'step8.9特殊狀況
  622.     End Sub      '防禦
  623.     Sub AI3()
  624.         If Button1.Text = "X" And Button2.Text = "X" And Button3.Text = "" Then
  625.             Button3.Text = "X"
  626.             Button3.Enabled = False
  627.         ElseIf Button1.Text = "X" And Button3.Text = "X" And Button2.Text = "" Then
  628.             Button2.Text = "X"
  629.             Button2.Enabled = False
  630.         ElseIf Button2.Text = "X" And Button3.Text = "X" And Button1.Text = "" Then
  631.             Button1.Text = "X"
  632.             Button1.Enabled = False
  633.         ElseIf Button4.Text = "X" And Button5.Text = "X" And Button6.Text = "" Then
  634.             Button6.Text = "X"
  635.             Button6.Enabled = False
  636.         ElseIf Button4.Text = "X" And Button6.Text = "X" And Button5.Text = "" Then
  637.             Button5.Text = "X"
  638.             Button5.Enabled = False
  639.         ElseIf Button5.Text = "X" And Button6.Text = "X" And Button4.Text = "" Then
  640.             Button4.Text = "X"
  641.             Button4.Enabled = False
  642.         ElseIf Button7.Text = "X" And Button8.Text = "X" And Button9.Text = "" Then
  643.             Button9.Text = "X"
  644.             Button9.Enabled = False
  645.         ElseIf Button7.Text = "X" And Button9.Text = "X" And Button8.Text = "" Then
  646.             Button8.Text = "X"
  647.             Button8.Enabled = False
  648.         ElseIf Button8.Text = "X" And Button9.Text = "X" And Button7.Text = "" Then
  649.             Button7.Text = "X"
  650.             Button7.Enabled = False
  651.         ElseIf Button1.Text = "X" And Button4.Text = "X" And Button7.Text = "" Then
  652.             Button7.Text = "X"
  653.             Button7.Enabled = False
  654.         ElseIf Button1.Text = "X" And Button7.Text = "X" And Button4.Text = "" Then
  655.             Button4.Text = "X"
  656.             Button4.Enabled = False
  657.         ElseIf Button4.Text = "X" And Button7.Text = "X" And Button1.Text = "" Then
  658.             Button1.Text = "X"
  659.             Button1.Enabled = False
  660.         ElseIf Button2.Text = "X" And Button5.Text = "X" And Button8.Text = "" Then
  661.             Button8.Text = "X"
  662.             Button8.Enabled = False
  663.         ElseIf Button2.Text = "X" And Button8.Text = "X" And Button5.Text = "" Then
  664.             Button5.Text = "X"
  665.             Button5.Enabled = False
  666.         ElseIf Button5.Text = "X" And Button8.Text = "X" And Button2.Text = "" Then
  667.             Button2.Text = "X"
  668.             Button2.Enabled = False
  669.         ElseIf Button3.Text = "X" And Button6.Text = "X" And Button9.Text = "" Then
  670.             Button9.Text = "X"
  671.             Button9.Enabled = False
  672.         ElseIf Button3.Text = "X" And Button9.Text = "X" And Button6.Text = "" Then
  673.             Button6.Text = "X"
  674.             Button6.Enabled = False
  675.         ElseIf Button6.Text = "X" And Button9.Text = "X" And Button3.Text = "" Then
  676.             Button3.Text = "X"
  677.             Button3.Enabled = False
  678.         ElseIf Button1.Text = "X" And Button5.Text = "X" And Button9.Text = "" Then
  679.             Button9.Text = "X"
  680.             Button9.Enabled = False
  681.         ElseIf Button1.Text = "X" And Button9.Text = "X" And Button5.Text = "" Then
  682.             Button5.Text = "X"
  683.             Button5.Enabled = False
  684.         ElseIf Button5.Text = "X" And Button9.Text = "X" And Button1.Text = "" Then
  685.             Button1.Text = "X"
  686.             Button1.Enabled = False
  687.         ElseIf Button3.Text = "X" And Button5.Text = "X" And Button7.Text = "" Then
  688.             Button7.Text = "X"
  689.             Button7.Enabled = False
  690.         ElseIf Button3.Text = "X" And Button7.Text = "X" And Button5.Text = "" Then
  691.             Button5.Text = "X"
  692.             Button5.Enabled = False
  693.         ElseIf Button5.Text = "X" And Button7.Text = "X" And Button3.Text = "" Then
  694.             Button3.Text = "X"
  695.             Button3.Enabled = False
  696.         End If
  697.         WinCheak()
  698.     End Sub      '勝利
  699.     Sub AI4()
  700.         If Button1.Enabled = True Then
  701.             Button1.Text = "X"
  702.             Button1.Enabled = False
  703.         ElseIf Button7.Enabled = True Then
  704.             Button7.Text = "X"
  705.             Button7.Enabled = False
  706.         ElseIf Button9.Enabled = True Then
  707.             Button9.Text = "X"
  708.             Button9.Enabled = False
  709.         ElseIf Button2.Enabled = True Then
  710.             Button2.Text = "X"
  711.             Button2.Enabled = False
  712.         ElseIf Button4.Enabled = True Then
  713.             Button4.Text = "X"
  714.             Button4.Enabled = False
  715.         ElseIf Button6.Enabled = True Then
  716.             Button6.Text = "X"
  717.             Button6.Enabled = False
  718.         ElseIf Button8.Enabled = True Then
  719.             Button8.Text = "X"
  720.             Button8.Enabled = False
  721.         End If
  722.     End Sub      '攻擊
  723.     Sub AI5()
  724.         If Button1.Text = "○" And Button3.Text = "○" And Button2.Text = "X" And Button5.Text = "X" Then
  725.             Button4.Text = "X"
  726.             Button4.Enabled = False
  727.             att = 99
  728.         ElseIf Button3.Text = "○" And Button9.Text = "○" And Button5.Text = "X" And Button6.Text = "X" Then
  729.             Button2.Text = "X"
  730.             Button2.Enabled = False
  731.             att = 99
  732.         ElseIf Button7.Text = "○" And Button9.Text = "○" And Button5.Text = "X" And Button8.Text = "X" Then
  733.             Button6.Text = "X"
  734.             Button6.Enabled = False
  735.             att = 99
  736.         ElseIf Button1.Text = "○" And Button7.Text = "○" And Button4.Text = "X" And Button5.Text = "X" Then
  737.             Button8.Text = "X"
  738.             Button8.Enabled = False
  739.             att = 99
  740.         End If
  741.     End Sub      'Setp6特殊狀況 標記att=99[backcolor=rgb(253, 253, 253)]
複製代碼






...
瀏覽完整內容,請先 註冊登入會員
附件: 你需要登錄才可以下載或查看附件。沒有帳號?註冊

使用道具檢舉

  專 家(12000/24000)

偶素程式設計下的產物「浻」

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

帖子
1412
積分
17880 點
潛水值
38197 米
發表於 2016-12-3 11:35 PM|顯示全部樓層
如果你忘記伊莉的密碼,請在登入時按右邊出現的 '找回密碼'。輸入相關資料後送出,系統就會把密碼寄到你的E-Mail。
玩了一下 先手跟後手差別
先手 基本上絕對平手

後手 都右上角先跑
這個點可以改成隨機,因為只要擺 中間就可以平手機率很大
本人 都是寫 vb.net 如果看到本人的原創 請自備 .Net FrameWork 3.5
如果你忘記伊莉的密碼,請在登入時按右邊出現的 '找回密碼'。輸入相關資料後送出,系統就會把密碼寄到你的E-Mail。

使用道具檢舉

Rank: 1

帖子
1699
積分
174 點
潛水值
45030 米
發表於 2016-12-5 01:00 AM|顯示全部樓層
成為伊莉的版主,你將獲得更高級和無限的權限。把你感興趣的版面一步步地發展和豐盛,那種滿足感等著你來嚐嚐喔。
darkjack 發表於 2016-12-3 11:35 PM
下載: 訪客無法瀏覽下載點,請先 註冊登入會員

玩了一下 先手跟後手差別
先手 基本上絕對平手

原則上是為了簡單化中間下法,因為我已經定義好先手固定走法
...
瀏覽完整內容,請先 註冊登入會員

使用道具檢舉

  專 家(12000/24000)

偶素程式設計下的產物「浻」

Rank: 5Rank: 5Rank: 5Rank: 5Rank: 5

帖子
1412
積分
17880 點
潛水值
38197 米
發表於 2016-12-8 12:13 AM|顯示全部樓層
哈哈...井字遊戲人來玩都只是一個不注意就被贏過去了....

如果瀏覽伊莉時速度太慢或無法連接,可以使用其他分流瀏覽伊莉,www01.eyny.com(02,03)。

使用道具檢舉

帖子
10
積分
1 點
潛水值
4660 米
發表於 2016-12-21 08:16 PM|顯示全部樓層
還在學習中...
謝謝大大分享資訊





點評

zxc693491 不要為了賺積分忘記版規…你的留言偏向無意義  發表於 2016-12-22 12:59 AM
分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。

使用道具檢舉

  高級幼兒生(30/200)

大石秀一郎

Rank: 1

帖子
68
積分
84 點
潛水值
8369 米
發表於 2019-11-23 11:48 PM|顯示全部樓層
如果發覺自己無法使用一些功能或出現問題,請按重新整理一次,並待所有網頁內容完全載入後5秒才進行操作。
下載: 訪客無法瀏覽下載點,請先 註冊登入會員


雖然這己經是很久的舊文章,小弟試玩樓主的版本後,就想把小弟去年年底自己寫出的井字遊戲分享出來給大家,請不要嫌棄哦,謝謝
如果你忘記伊莉的密碼,請在登入時按右邊出現的 '找回密碼'。輸入相關資料後送出,系統就會把密碼寄到你的E-Mail。

使用道具檢舉

Rank: 1

帖子
1699
積分
174 點
潛水值
45030 米
發表於 2019-11-25 02:30 PM|顯示全部樓層
若新密碼無法使用,可能是數據未更新。請使用舊密碼看看。
sango99001 發表於 2019-11-23 11:48 PM
下載: 訪客無法瀏覽下載點,請先 註冊登入會員

井字遊戲(含AI及雙人版)

雖然這己經是很久的舊文章,小弟試玩樓主的版本後,就想把小弟去年年底自己寫出的井 ...
...
瀏覽完整內容,請先 註冊登入會員

使用道具檢舉

  高級幼兒生(30/200)

大石秀一郎

Rank: 1

帖子
68
積分
84 點
潛水值
8369 米
發表於 2019-11-27 09:25 AM|顯示全部樓層
如果發覺自己無法使用一些功能或出現問題,請按重新整理一次,並待所有網頁內容完全載入後5秒才進行操作。
zxc693491 發表於 2019-11-25 02:30 PM
下載: 訪客無法瀏覽下載點,請先 註冊登入會員

真的好久了…
井字完,要不要嘗試五子,踩地雷

小弟目前對五子棋跟踩地雷的概念還是停留在會玩的階段,完全想不到如何轉換成程式...
瀏覽完整內容,請先 註冊登入會員

點評

zxc693491 因為版面大不能用絕對位置判斷,要用相對位置, 可以嘗試看別人的作品,大多會有一個陣列包著八個方向的座標  發表於 2019-11-28 11:53 AM

使用道具檢舉

Rank: 3Rank: 3Rank: 3

帖子
1335
積分
1012 點
潛水值
30767 米
發表於 2020-1-8 08:30 PM|顯示全部樓層
其實位置陣列是比較簡單的,難的是電腦端的智力。
踩地雷倒還好,就用亂數產生地雷就好,
而五子棋,你就要讓電腦端能有"推算"的能力,推算自己與玩家後幾步的走法。

使用道具檢舉

Rank: 1

帖子
281
積分
109 點
潛水值
5470 米
發表於 2020-3-4 01:30 PM|顯示全部樓層
分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。
這是你學校的作業吧!!




點評

zxc693491 這我高一的時候自學生出來的東西…過了五年多了吧 現在重寫一次這程式不用5分鐘 ̄﹃ ̄  發表於 2020-3-8 07:28 AM

使用道具檢舉

Rank: 1

帖子
281
積分
109 點
潛水值
5470 米
發表於 2020-3-11 08:31 AM|顯示全部樓層
如果你忘記伊莉的密碼,請在登入時按右邊出現的 '找回密碼'。輸入相關資料後送出,系統就會把密碼寄到你的E-Mail。
網路有很多類似的遊戲程式!去看看寫法!
如果瀏覽伊莉時速度太慢或無法連接,可以使用其他分流瀏覽伊莉,www01.eyny.com(02,03)。

使用道具檢舉

帖子
46
積分
28 點
潛水值
15047 米
發表於 2020-4-5 11:42 PM|顯示全部樓層
分享使你變得更實在,可以使其他人感到快樂,分享是我們的動力。今天就來分享你的資訊、圖片或檔案吧。
謝謝大大的分享..大大辛苦了

使用道具檢舉

您需要登錄後才可以回帖 登錄 | 註冊

Powered by Discuz!

© Comsenz Inc.

重要聲明:本討論區是以即時上載留言的方式運作,對所有留言的真實性、完整性及立場等,不負任何法律責任。而一切留言之言論只代表留言者個人意見,並非本網站之立場,用戶不應信賴內容,並應自行判斷內容之真實性。於有關情形下,用戶應尋求專業意見(如涉及醫療、法律或投資等問題)。 由於本討論區受到「即時上載留言」運作方式所規限,故不能完全監察所有留言,若讀者發現有留言出現問題,請聯絡我們。有權刪除任何留言及拒絕任何人士上載留言,同時亦有不刪除留言的權利。切勿上傳和撰寫 侵犯版權(未經授權)、粗言穢語、誹謗、渲染色情暴力或人身攻擊的言論,敬請自律。本網站保留一切法律權利。
回頂部