【发布时间】:2021-10-09 08:40:56
【问题描述】:
我是一个初学者,我想做一款井字游戏。
我想创建一个函数来查找游戏的获胜者,如果 x 获胜则返回“x”,如果获胜则返回“o”,如果没有人获胜则返回“平局”,如果有两个获胜者则返回“错误”。
function winner(x){
//x is an array that includes 3 child arrays, every child represents a row of tic tac toe matrix
// example x =[["x","o","x"],["o","x","o"],["o","o","x"]]
// It should return "x" because "x" player is the winner
}
我尝试了很多方法,但我仍然无法做到。 你能帮帮我吗?
【问题讨论】:
-
到目前为止你尝试过什么?例如,检查一行意味着检查 arr[n] 是否仅包含“x”或仅包含“o”。
-
您可以设置可能获胜的“模式”,然后检查数组中是否存在。
标签: javascript arrays tic-tac-toe