gpt4 book ai didi

function - 如何在 Golang 中以整数作为参数在 boolean 变量和函数之间进行逻辑运算

转载 作者:数据小太阳 更新时间:2023-10-29 03:42:29 34 4
gpt4 key购买 nike

我想知道如何在 boolean 变量和函数调用之间进行逻辑运算“或”

func Move(x int, y int, m int) int{

if IsvisitedNode(x,y){
var possiblemove bool
possiblemove = possiblemove || Move( x+2, y+1, m+1)
possiblemove = possiblemove || Move( x+2, y-1, m+1)
possiblemove = possiblemove || Move( x-2, y+1, m+1)
possiblemove = possiblemove || Move( x-2, y-1, m+1)
possiblemove = possiblemove || Move( x+1, y+2, m+1)
possiblemove = possiblemove || Move( x+1, y-2, m+1)
possiblemove = possiblemove || Move( x-1, y+2, m+1)
possiblemove = possiblemove || Move( x-1, y-2, m+1)

if possiblemove == true {
fmt.Println(x,y)

return true
}else{

visithistory[p] && visithistory[q] = false
return false

}
}
return 1
}

有人可以帮帮我吗?

最佳答案

假设您想将 0 评估为假,将任何其他数字评估为真,您可以这样做:

possiblemove = possiblemove || Move( x+2, y+1, m+1) != 0

关于function - 如何在 Golang 中以整数作为参数在 boolean 变量和函数之间进行逻辑运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39250007/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com