博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
从零开始拼凑的_如何从零开始拼凑AI
阅读量:2520 次
发布时间:2019-05-11

本文共 4198 字,大约阅读时间需要 13 分钟。

从零开始拼凑的

by Christopher Phillips

克里斯托弗·菲利普斯(Christopher Phillips)

如何从零开始拼凑AI (How to Patch Together an AI from Scratch)

Yesterday I started the Tic Tac Toe project from .

昨天,我从开始了Tic Tac Toe项目。

It’s a “programming” challenge in many ways, as it involves creating AI that responds intelligently to your moves. In fact, the goal is to create an AI that’s unbeatable.

从许多方面来说,这都是一个“编程”挑战,因为它涉及创建可以对您的动作进行智能响应的AI。 实际上,目标是创建无与伦比的AI。

This seemed a little more complex than getting some elements from the DOM, turning them into jQuery objects, and applying some methods to them, like we were doing with earlier projects. So I started googling around, only to get lost in MiniMax theories, horrendous YouTube tutorials, and poorly written guides.

这似乎比从DOM中获取一些元素,将它们转换为jQuery对象,并对它们应用某些方法要复杂得多,就像我们在早期项目中所做的那样。 因此,我开始四处搜寻,却迷失在MiniMax理论,可怕的YouTube教程和编写不当的指南中。

I decided to take it upon myself to jump straight in. And that decision has lead me to learn so much.

我决定自己跳进去。这个决定使我学到了很多东西。

知道你不知道的 (Know what you don’t know)

It’s really important in coding to recognize your current knowledge and it’s limits. So how do you approach a challenge that involves far more than you already know.

在编码中识别您当前的知识及其局限性非常重要。 因此,您如何应对所涉及的挑战远远超过您已经知道的。

1. Think about how you will approach the problem. Create a plan of attack, even if you’re not sure how each step will work yet. If it’s with , make sure you include the user stories in this plan and how you will include each one.

1.考虑如何解决问题。 即使您不确定每个步骤的工作方式,也要制定攻击计划。 如果与 ,请确保在此计划中包括用户案例,以及如何包括每个案例。

2. Start with the basics. For Tic Tac Toe, that meant creating the HTML and CSS with buttons that could be taken from the DOM and worked with in JS.

2.从基础开始。 对于Tic Tac Toe,这意味着使用可以从DOM提取并可以在JS中使用的按钮来创建HTML和CSS。

3. Work with methods that you have used before. I have worked with elements from the DOM many times using jQuery and JavaScript so getting a button, giving it an innerHTML text value and a class, was not an issue.

3.使用以前使用的方法。 我使用jQuery和JavaScript处理过DOM中的元素很多次,因此获得一个按钮,为其提供一个innerHTML文本值和一个类,这不是问题。

4. Create a simpler solution. This for me involved creating a game for 2 players with no AI. You can see this . A simple overview:

4.创建一个更简单的解决方案 。 对我而言,这涉及为2个没有AI的玩家创建游戏。 你可以看到。 简单概述:

  • When a user clicks a button, it adds an “X” to that button. Then the player symbol alternates to a “O” for the next player. It then toggles back and forth.

    用户单击按钮时,会在该按钮上添加“ X”。 然后,玩家符号交替显示为下一个玩家的“ O”。 然后,它来回切换。
  • When a winning line is created, an alert message is created which says “Congratulations” + player symbol + “You won”.

    创建中奖线时,会创建一条警告消息,显示“恭喜” +玩家符号+“您赢了”。
  • If no winning line is created, it is a draw, with an appropriate alert message.

    如果未创建获胜线,则为平局,并带有适当的警报消息。

5. Add layers of functionality with what you know. I added buttons that would let you choose which symbol the first player would like to be. These were simple, just changing a variable. The next thing I had to do was to create some AI. I tried two things.

5.使用已知的知识添加功能层 。 我添加了一些按钮,可让您选择第一个玩家想要的符号。 这些很简单,只需更改变量即可。 我要做的下一件事是创建一些AI。 我尝试了两件事。

  • A loop that places a computer response in the next available box. This created a very simple AI that was really easy to beat. See it .

    将计算机响应放入下一个可用框中的循环。 这创建了一个非常简单的AI,非常容易被击败。 看到它。

  • A loop that generated a random number between 1 and 9, and put a value in that box if it was free. More complex, but ultimately a very stupid AI! See it .

    一个循环,它生成一个介于1到9之间的随机数,如果有空则将一个值放在该框中。 更复杂,但最终是非常愚蠢的AI! 看到它。

6. Research, learn and perfect your solution. I am now researching MiniMax theory which is a recursive function to generate possible scenarios based on theoretical player/computer turns. I will aim to apply this functionality as soon as I have a good grasp. I also need to my code as it is a bit messy.

6.研究,学习和完善您的解决方案 。 我现在正在研究MiniMax理论,它是一种递归函数,可以根据理论玩家/计算机的回合生成可能的情况。 我将一掌握就会尽快应用此功能。 我还需要我的代码,因为它有点混乱。

No problem is too great. Start with small steps utilizing your current knowledge, build upon it, and then research the tasks remaining that you can’t accomplish. This challenge has taught me the most so far out of all the curriculum.

没有太大的问题。 从利用您当前的知识的小步骤开始,以其为基础,然后研究您尚无法完成的剩余任务。 到目前为止,在所有“ 课程中,这一挑战教会了我最多的知识。

Originally published at .

最初发表于 。

翻译自:

从零开始拼凑的

转载地址:http://yrewd.baihongyu.com/

你可能感兴趣的文章
文本框过滤特殊符号
查看>>
教育行业安全无线网络解决方案
查看>>
7个杀手级的开源监测工具
查看>>
软件架构学习小结
查看>>
C语言实现UrlEncode编码/UrlDecode解码
查看>>
返回用户提交的图像工具类
查看>>
树链剖分 BZOJ3589 动态树
查看>>
挑战程序设计竞赛 P131 区间DP
查看>>
【例9.9】最长公共子序列
查看>>
NSFileManager打印目录下的文件的函数
查看>>
Selenium自动化-调用Mysql数据库
查看>>
项目一
查看>>
[转载]AAF灵便应用框架简介系列(6):休息一下,泛谈面向对象 Why OO+多层结构?...
查看>>
android EditView ime
查看>>
javascript 学习随笔7
查看>>
<P>标签小细节
查看>>
Linux 命令 - netstat
查看>>
mac 关闭&&显示隐藏文件命令
查看>>
JavaScript 循环绑定之变量污染
查看>>
poj 1038 Bugs Integrated, Inc. 三进制状态压缩 DFS 滚动数组
查看>>