我想学习brain.js,所以我决定做一个小项目。我想做一个石头,纸,剪刀的游戏,每次游戏后背景颜色会在三种颜色之间随机变化。
如果您选择每次显示某种背景颜色时都将播放一个选项,则网站应使用brain.js并学习该模式。
首先,网站还会选择一个随机选项。
example:
background-color=blue youPlay=rock
background-color=red youPlay=paper
background-color=yellow youPlay=scissors
//when all three colors were used, the website will use a function with brain.js
background-color=red -> website knows that you will most likely play paper based on your previous plays and it will play scissors to win
这是功能最关键的部分:
const net = new brain.NeuralNetwork();
for(i=0; i < dataPlay.length; i++){
net.train([{ input: [dataColor[i]], output: [dataPlay[i]] }]);
}
var output = net.run([colorVar]);
背景色保存在dataColor []中,而您的剧本保存在dataPlay []中。实际的背景颜色保存在colorVar中。
for循环的问题是输出仅基于dataColor和dataPlay中的最后一项。我想训练dataColor和dataPlay中所有项目的数据。