Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/function/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Function 在Golang中如何在布尔变量和以整数为参数的函数之间进行逻辑运算_Function_Go_Boolean_Logical Operators - Fatal编程技术网

Function 在Golang中如何在布尔变量和以整数为参数的函数之间进行逻辑运算

Function 在Golang中如何在布尔变量和以整数为参数的函数之间进行逻辑运算,function,go,boolean,logical-operators,Function,Go,Boolean,Logical Operators,我想知道如何在布尔变量和函数调用之间进行逻辑运算“OR” 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 ||

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

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计算为false,将任何其他数字计算为true,您可以这样做:

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

我得到这个错误:无效操作:可能移动| |移动(x+2,y+1,m+1)(不匹配的类型bool和int),这是显而易见的,但我找不到解决方案帮助!!!当然,不能在int和bool之间进行转换。问题是:你想要实现什么?你认为移动(x+1,y-2,m+1)应该是什么?通过这个,我试图在go lang中找到骑士之旅解决方案通过这个,使函数移动返回布尔值,而不是整数。我得到这个,索引超出范围错误@Daniel WisehartIm得到索引超出范围错误@朱修斯