首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >制造简单人工智能的麻烦

制造简单人工智能的麻烦
EN

Stack Overflow用户
提问于 2015-09-17 01:21:04
回答 1查看 57关注 0票数 1

我目前正在尝试制作一个抽搐-战术-脚趾游戏,其中pc随机选择一个数字从一个数组,并根据数字,它选择一个按钮,并改变它的文本属性。如何使它不选择已经具有文本属性的按钮?这是我的代码:

代码语言:javascript
复制
   Dim AIChoice As Integer
   AIChoice = AIChoic.Next(0, AI.Length - 1)

   If AI.GetValue(AIChoice) = 1 And Button1.Text = "" Then
       Button1.Text = "O"
       AIChoice = AIChoic.Next(0, AI.Length)
   ElseIf AI.GetValue(AIChoice) = 2 And Button2.Text = "" Then
       Button2.Text = "O"
       AIChoice = AIChoic.Next(0, AI.Length)
   ElseIf AI.GetValue(AIChoice) = 3 And Button3.Text = "" Then
       Button3.Text = "O"
       AIChoice = AIChoic.Next(0, AI.Length)
   ElseIf AI.GetValue(AIChoice) = 4 And Button4.Text = "" Then
       Button4.Text = "O"
       AIChoice = AIChoic.Next(0, AI.Length)
   ElseIf AI.GetValue(AIChoice) = 5 And Button5.Text = "" Then
       Button5.Text = "O"
       AIChoice = AIChoic.Next(0, AI.Length)
   ElseIf AI.GetValue(AIChoice) = 6 And Button6.Text = "" Then
       Button6.Text = "O"
       AIChoice = AIChoic.Next(0, AI.Length)
   ElseIf AI.GetValue(AIChoice) = 7 And Button7.Text = "" Then
       Button7.Text = "O"
       AIChoice = AIChoic.Next(0, AI.Length)
   ElseIf AI.GetValue(AIChoice) = 8 And Button8.Text = "" Then
       Button8.Text = "O"
       AIChoice = AIChoic.Next(0, AI.Length)
   ElseIf AI.GetValue(AIChoice) = 9 And Button9.Text = "" Then
       Button9.Text = "O"
       AIChoice = AIChoic.Next(0, AI.Length)

我前面还有一个数组,上面有数字1-9。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-17 12:16:34

这应该与您发布的代码相同,只是它将继续选择一个随机数,直到找到一个带有空字符串的按钮作为其Text。请注意,最好将按钮创建为数组,而不是创建一个额外的数组来引用它们,但这是最简单的修复方法,我认为您不会遇到其他方法会避免的任何问题。

代码语言:javascript
复制
Dim AllButtons() As Button = {Button1, Button2, Button3, Button4, Button5, Button6, Button7, Button8, Button9}
Dim AIChoice As Integer
Do
    AIChoice = AIChoic.Next(0, AI.Length - 1)
Loop Until AllButtons(AI.GetValue(AIChoice) - 1).Text = ""
AllButtons(AI.GetValue(AIChoice) - 1).Text = "O"
AIChoice = AIChoic.Next(0, AI.Length)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32621202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档