实际上我已经编写了这段代码,但它不起作用。请帮帮我。
unsigned short checkCollisionOrFood(unsigned short rowHead,unsigned short colHead)
/*this the functionother then main function where i am changing value of "rowHead",but on checking it remain same*/
{
if(turn==0){
if(address[colHead]&(1<<((rowHead+1)%8))){
if(((int)(address[(colHead+7)%8]&(1<<(rowHead+1)%8))
+(int)(address[colHead]& (1<<(rowHead+2)%8))
+(int)(address[(colHead+1)%8]&(1<<(rowHead+1)%8)))>1) return -1;
else{
rowHead=(rowHead+1)%8;//this value of rowHead is not getting change.
return 1;
}
}
}
变量 "turn","rowHead","colHead" 是全局变量。现在按照 Daniel Fischer 的指令修改此代码后,它是
unsigned short checkCollisionOrFood()
{
if(turn==0){
if(address[colHead]&(1<<((rowHead+1)%8))){
if(((int)(address[(colHead+7)%8]&(1<<(rowHead+1)%8))
+(int)(address[colHead]&(1<<(rowHead+2)%8))
+(int)(address[(colHead+1)%8]&(1<<(rowHead+1)%8)))>1) return -1;
else{
rowHead=(rowHead+1)%8;
return 1;
}
}
}