- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在做一个科学博览会项目,用不同的策略做一个 javascript 人工智能游戏,看看哪一个打败了最多的人类。我不知道如何加入人工智能或策略,请帮忙。
我的游戏的两人示例:http://xenoffpi.no-ip.org/preston/tictactoe
这是我的代码:
<HTML>
<HEAD>
<link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Crafty+Girls' rel='stylesheet' type='text/css'>
<TITLE>Tic Tac Toe!</TITLE>
<SCRIPT TYPE="TEXT/JAVASCRIPT">
var xTurn = true;
var gameOver = false;
var numMoves = 0;
function squareclicked(square)
{
var value = square.value;
var status = document.getElementById('status');
if(gameOver)
{
alert("The game is already over.");
return;
}
if(value != 'X' && value != 'O')
{
if(xTurn)
{
numMoves++;
square.value = 'X';
xTurn = false;
status.innerHTML = 'O\'s turn';
}
else
{
numMoves++;
square.value = 'O';
xTurn = true;
status.innerHTML = 'X\'s turn';
}
}
else
alert('That square has already been played.');
var winner = checkWin();
if(!winner)
{
if(numMoves == 9)
status.innerHTML = 'Tie Game!';
}
else
gameOver = true;
}
function newgame()
{
var status = document.getElementById('status');
xTurn = true;
status.innerHTML = 'X\'s turn';
gameOver = false;
numMoves = 0;
for(var x = 0; x < 3; x++)
{
for(var y = 0; y < 3; y++)
{
document.getElementById(x + '_' + y).value = ' ';
}
}
}
function checkWin()
{
var status = document.getElementById('status');
var val0;
var val1;
var val2;
for(var y = 0; y < 3; y++)
{
val0 = document.getElementById('0_'+y).value;
val1 = document.getElementById('1_'+y).value;
val2 = document.getElementById('2_'+y).value;
if(val0 == 'X' && val1 == 'X' && val2 == 'X')
{
status.innerHTML = "X WINS!";
return true;
}
else if(val0 == 'O' && val1 == 'O' && val2 == 'O')
{
status.innerHTML = "O WINS!";
return true;
}
}
for(var x = 0; x < 3; x++)
{
val0 = document.getElementById(x + '_0').value;
val1 = document.getElementById(x + '_1').value;
val2 = document.getElementById(x + '_2').value;
if(val0 == 'X' && val1 == 'X' && val2 == 'X')
{
status.innerHTML = "X WINS!";
return true;
}
else if(val0 == 'O' && val1 == 'O' && val2 == 'O')
{
status.innerHTML = "O WINS!";
return true;
}
}
val0 = document.getElementById('0_0').value;
val1 = document.getElementById('1_1').value;
val2 = document.getElementById('2_2').value;
if(val0 == 'X' && val1 == 'X' && val2 == 'X')
{
status.innerHTML = "X WINS!";
return true;
}
else if(val0 == 'O' && val1 == 'O' && val2 == 'O')
{
status.innerHTML = "O WINS!";
return true;
}
val0 = document.getElementById('2_0').value;
val1 = document.getElementById('1_1').value;
val2 = document.getElementById('0_2').value;
if(val0 == 'X' && val1 == 'X' && val2 == 'X')
{
status.innerHTML = "X WINS!";
return true;
}
else if(val0 == 'O' && val1 == 'O' && val2 == 'O')
{
status.innerHTML = "O WINS!";
return true;
}
}
</SCRIPT>
<style>
input[type=button] {
color:#08233e;
background-color: #9999FF;
font-family: 'Crafty Girls', cursive;
font-size:70%;
width: 100;
height:100;
cursor:pointer;
font-size:25;
border:groove;
border-color: 000000;
font-weight:900;
}
input[type=button]:hover {
background-color:#6666FF;
}
input[id="NEWGAME"] {
color:#08233e;
background-color: #9999FF;
width: 310;
height:60;
cursor:pointer;
font-size:30;
font-family: 'Shadows Into Light', cursive;
}
input[id=NEWGAME]:hover {
background-color:#6666FF;
}
#status{
font-family: 'Shadows Into Light', cursive;
font-size:30;
font-style:bold;
font-weight:900;
}
#stat{
background-color:#9999FF;
width:302;
height:50
}
#outline{
width:400;
height:530;
background-color:000000;
}
#header{
height:100;
width:800;
background-color:000000;
}
</style>
</HEAD>
<BODY>
<div align="center">
<div id="outline">
<br>
<br>
<INPUT TYPE="BUTTON" ID="NEWGAME" VALUE="New Game" ONCLICK="newgame();">
<br>
<br>
<INPUT TYPE="BUTTON" ID="0_0" VALUE=" " ONCLICK="squareclicked(this);">
<INPUT TYPE="BUTTON" ID="1_0" VALUE=" " ONCLICK="squareclicked(this);">
<INPUT TYPE="BUTTON" ID="2_0" VALUE=" " ONCLICK="squareclicked(this);">
<BR>
<INPUT TYPE="BUTTON" ID="0_1" VALUE=" " ONCLICK="squareclicked(this);">
<INPUT TYPE="BUTTON" ID="1_1" VALUE=" " ONCLICK="squareclicked(this);">
<INPUT TYPE="BUTTON" ID="2_1" VALUE=" " ONCLICK="squareclicked(this);">
<BR>
<INPUT TYPE="BUTTON" ID="0_2" VALUE=" " ONCLICK="squareclicked(this);">
<INPUT TYPE="BUTTON" ID="1_2" VALUE=" " ONCLICK="squareclicked(this);">
<INPUT TYPE="BUTTON" ID="2_2" VALUE=" " ONCLICK="squareclicked(this);">
<br>
<div align="center">
<div id="stat">
<P ID="status">X's turn</P>
</div>
</div>
</div>
</div>
</BODY>
</HTML>
最佳答案
既然你可以轻松快速地计算出井字棋的整个决策树,Minimax算法将使你的人工智能永远不会输:
http://en.wikipedia.org/wiki/Minimax
它不会总是赢(大多数人都会玩猫的游戏),但它保证不会输。
关于javascript - Tic Tac Toe Science Fair 人工智能与策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18884877/
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 4年前关闭。 Improve thi
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this qu
我有一个关于车床的非常简单的问题。 如果它采取的第一个 Action 包括倒带,它会向后移动超过起点,还是这是一种特殊情况,它会留在起点吗? 最佳答案 这实际上取决于您使用的是哪种形式主义。一些形式主
我正在关注这个博客 http://www.quuxlabs.com/blog/2010/09/matrix-factorization-a-simple-tutorial-and-implementa
我正在尝试在 Kaggle Iowa 住房数据集上训练 LightGBM 模型,我编写了一个小脚本来随机尝试给定范围内的不同参数。我不确定我的代码有什么问题,但脚本使用不同的参数返回相同的分数,这是不
查找图形外边缘的最佳方法是什么? 例如,这张图上的红色边: 我不知道这个算法有没有名字。这个名字足以帮助我在 Google 上找到一些东西。 最佳答案 我希望我没有误解这个问题,但我认为没有答案,除非
我正在回答一些与虚拟内存相关的问题,并希望得到一些帮助来澄清或确认我对这些东西是如何完成的理解。 问题如下: Given a byte-addressable system with 32 bit w
我知道算法是一种有效的方法,表示为用于计算函数的定义明确的指令的有限列表。但是我们如何将它与逻辑区分开来? 最佳答案 哇,你的问题带我去旅行,我发现了一些东西!这可能不能作为答案,但将其放在这里作为引
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 4年前关闭。 Improve t
您如何评价出版物?我目前正在寻找 CS 研究主题并阅读各种论文。我在阅读论文时的困境通常是 - 在这个主题上继续研究真的值得吗? 研究影响的指标是什么? 顺便说一句,我目前对 - 活性分析感兴趣。你怎
根据我的教科书,L1 = A* - L1 的补码就是正则语言,只要 L1 是正则语言。 A* 不也包括上下文无关语言、上下文敏感语言和递归可枚举语言吗? A*-L1 也会包括所有这些,不是吗?那怎么能
我正在开发用户收集标签的 Web 应用程序。我需要根据用户标签的相似性为用户创建一个建议列表。 例如,当用户登录系统时,系统获取他的标签并在用户的数据库中搜索这些标签并显示具有相似标签的用户。例如如果
假设存在图灵机 M1、M2、M3,它们识别的语言分别是 L(M1)、L(M2) 和 L(M3)。以下语言 L = {(M1, M2, M3) : L(M1), L(M2), and L(M3) 不相等
我现在正在学习一个编译器类,我们正处于必须构建一个 CFG 以实现优化的地步。我不知道的一件事是一个程序有多少个 CFG?我见过的每个示例似乎都是一个简单代码段的 CGF。因此,如果您有一个具有三个功
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 9年前关闭。 Improve this q
我正在撰写有关计算机科学主题的相当长的专着。但是,我通常发现自己必须用数学术语写一些计算机科学概念,这对我来说很困难。例如,说我想编写一个for循环或void函数。我大部分时间都去我的Knuth或Co
堆栈在微处理器中的作用是什么? 最佳答案 堆栈主要在函数调用期间使用,但根据语言和编程级别,它可用于临时存储处理器寄存器数据或其他变量。 此外,当使用递归函数将部分数据存储在堆栈中并再次调用自己时,堆
到目前为止,我想出的最好的方法是卡片目录包含有关如何 cooking 不同类型食物的说明。它不包含有关如何 cooking 食物的信息,也不包含 cooking 食物本身的说明,但它可以为您指明位于其
我是一名 CS 大二学生,我想用电子学习度过我的暑假。周围有很多公开类(class),但我不知道从哪里开始或如何进行。 编辑:感谢您的建议,但我真正的问题是我无法选择我应该参加哪个特定的讲座。 最佳答
我对数据科学还很陌生。我正在研究使用基于产品编号和商店编号作为预测变量的线性回归来预测销售需求的用例。可以有许多具有数值的商店和产品。如果这些变量/预测变量的值是数字的、无界的并且在不同的尺度上,我是
我是一名优秀的程序员,十分优秀!