带有多维数组和乌龟的井字游戏AI

时间:2019-04-08 17:46:49

标签: python

我正试图通过使用乌龟在Repl.it上绘制棋盘来制作井字游戏。效率不是很高,但是我正在尝试开发一种AI,而不必对每种可能的电路板组合进行编程。

我对python还是很陌生;我正在学校参加AP ComSciPri课程。我在函数和计算等方面学到了很多基础知识,但是在宏大的计划中,我却错过了很多。除了创建分支以绑定每个游戏之外,还有一种方法可以创建执行此操作的过程?

不确定这是否有帮助,但是:

gameArray = [["-","-","-"],["-","-","-"],["-","-","-"]]

uArray = [["0","0","0"],["0","0","0"],["0","0","0"]]

cpuArray = [["0","0","0"],["0","0","0"],["0","0","0"]]

winningArrays = [
[["X","X","X"],["0","0","0"],["0","0","0"]],
[["0","0","0"],["X","X","X"],["0","0","0"]],
[["0","0","0"],["0","0","0"],["X","X","X"]],
[["X","0","0"],["X","0","0"],["X","0","0"]],
[["0","X","0"],["0","X","0"],["0","X","0"]],
[["0","0","X"],["0","0","X"],["0","0","X"]],
[["X","0","0"],["0","X","0"],["0","0","X"]],
[["0","0","X"],["0","X","0"],["X","0","0"]]]

我使用乌龟画板并放置图章,以及操纵调试板(gameArray,uArray,cpuArray)。


如果userInput == 1:

spaceList.remove(1)

turt1.shape("circle")

turt1.color("black")

turt1.penup()

turt1.goto(-75,-25)

turt1.stamp()

gameArray[2][0] = "U"

uArray[2][0] = "X"

将我在hastebin中的所有内容链接起来。通常,我想了解一些我可以研究的信息,或者是否有人建议给我。预先感谢!

1 个答案:

答案 0 :(得分:0)

拥有一个AI所需要的最重要的事情就是衡量板卡状态的好坏。作为一个非常简单的示例,可以说度量标准是董事会是否处于获胜状态(连续三个X)。然后让AI检查其轮到的所有不同板(最多9个),如果一个人是赢家,我们就选那个!否则,随机挑选一些东西。这肯定比随机机会要好,并且可能是程序的良好“轻松模式”计算机播放器。如果您可以创建更复杂的功能以使板状态更好,那么您可以创建更复杂的计算机播放器。