gpt4 book ai didi

vb.net - 让它看起来像电脑在井字游戏中思考

转载 作者:行者123 更新时间:2023-12-01 04:01:54 26 4
gpt4 key购买 nike

这是我在 VB.net 中编写的一段代码

Private Sub L00_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles L00.Click, L01.Click, L02.Click, L03.Click, L10.Click, L11.Click, L12.Click, L13.Click, L20.Click, L21.Click, L22.Click, L23.Click, L30.Click, L31.Click, L32.Click, L33.Click
Dim ticTac As Label = CType(sender, Label)
Dim strRow As String
Dim strCol As String

'Once a move is made, do not allow user to change whether player/computer goes first, because it doesn't make sense to do so since the game has already started.
ComputerFirstStripMenuItem.Enabled = False
PlayerFirstToolStripMenuItem.Enabled = False

'Check to make sure clicked tile is a valid tile i.e and empty tile.
If (ticTac.Text = String.Empty) Then
ticTac.Text = "X"
ticTac.ForeColor = ColorDialog1.Color
ticTac.Tag = 1


'After the player has made his move it becomes the computers turn.
computerTurn(sender, e)

Else
MessageBox.Show("Please pick an empty tile to make next move", "Invalid Move")
End If
End Sub

Private Sub computerTurn(ByVal sender As System.Object, ByVal e As System.EventArgs)
Call Randomize()
row = Int(4 * Rnd())
col = Int(4 * Rnd())

'Check to make sure clicked tile is a valid tile i.e and empty tile.
If Not ticTacArray(row, col).Tag = 1 And Not ticTacArray(row, col).Tag = 4 Then
ticTacArray(row, col).Text = "O"
ticTacArray(row, col).ForeColor = ColorDialog2.Color
ticTacArray(row, col).Tag = 4

checkIfGameOver(sender, e)
Else
'Some good ole pseudo-recursion(doesn't require a base case(s)).
computerTurn(sender, e)
End If

End Sub

一切都很顺利,除了我试图让计算机看起来像在移动之前必须“思考”。所以我试图做的是在上面代码的不同位置放置一个 System.Threading.Sleep() 调用。

问题是程序并没有让计算机看起来像它的想法,而是等待,然后同时将 X 和 O 放在一起。有人可以帮我制作它,以便程序在我点击的任何地方放置一个 X,然后在放置 O 之前等待吗?

编辑:如果你们中有人想知道,我意识到计算机 AI 非常愚蠢,但它现在只是乱七八糟。稍后我将实现一个严肃的人工智能......希望如此。

最佳答案

正如格雷格所说,我会使用计时器,我会首先从您的计算机Turn Click 事件中取出逻辑并创建一个方法,您可以使用随机数生成器使其看起来像计算机被认为是不同的时间,然后例如,您可以将光标更改为等待光标。像这样的东西:

Public Class Form1
Dim rnd As Random = New Random(1)
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Me.Cursor = Cursors.WaitCursor
Timer1.Interval = CInt(rnd.NextDouble * 1000)
Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Timer1.Stop()
computerTurn()
End Sub

Private Sub computerTurn()
Me.Cursor = Cursors.Default
'Your Move Logic Here
End Sub

End Class

关于vb.net - 让它看起来像电脑在井字游戏中思考,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12993380/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com