现在界面已经完成了,

大道五目Flash英文版(Renju Problems)程序分析之禁手判断 

刚刚完成了禁手算法,把代码共享出来:

大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断Code
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断private function IsForbidden(x:int, y:int, board:Array):int 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            var index:
int = x*15+y;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
// set this position(x,y) to black.
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
            board[index] = CellType.BLACK;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
// 1st check whether there is overline.
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
            var array:Array =this.GetAnalyseArray(x,y,board);
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
if(this.IsOverline(array)) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                board[index] 
= CellType.EMPTY;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                
return ResultType.OVERLINE;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
// use recursion to check whether there is double-4 or double-3.
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
// the check methord is count the open 3 and open 4's count,
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
// if one of them larger than 1 so is a forbidden.
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
            var count3:int = 0;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            var count4:
int = 0;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            var i, j:
int = 0;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
for(i=0; i<4; i++大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                
// calculate open 4's count.
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断
                for(j=3; j<7; j++大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    
// patten: ?0x000?
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
                    if(array[i][j]==CellType.BLACK&&this.IsEmpty(i,j+1,array)&& 
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        array[i][j
+2]==CellType.BLACK&&array[i][j+3]==CellType.BLACK&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        array[i][j
+4]==CellType.BLACK&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
this.IsNotBlack(i,j-1,array)&&this.IsNotBlack(i,j+5,array)) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        count4
++;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
continue;    
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    
// patten: ?00x00?
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
                    if(array[i][j]==CellType.BLACK&&array[i][j+1]==CellType.BLACK&& 
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
this.IsEmpty(i,j+2,array)&&array[i][j+3]==CellType.BLACK&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        array[i][j
+4]==CellType.BLACK&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
this.IsNotBlack(i,j-1,array)&&this.IsNotBlack(i,j+5,array)) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        count4
++;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
continue;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    
// patten: ?000x0?
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
                    if(array[i][j]==CellType.BLACK&&array[i][j+1]==CellType.BLACK && 
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        array[i][j
+2]==CellType.BLACK&&this.IsEmpty(i,j+3,array) &&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        array[i][j
+4]==CellType.BLACK&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
this.IsNotBlack(i,j-1,array)&&this.IsNotBlack(i,j+5,array)) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        count4
++;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
continue;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    
// patten: ??0000??
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    
// not like above three, this check index is the above index plus 1.
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    
// in other words, the check index is 4 to 8 and above index is 3 to 7.
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
                    if(array[i][j+1]==CellType.BLACK&&array[i][j+2]==CellType.BLACK&& 
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        array[i][j
+3]==CellType.BLACK&&array[i][j+4]==CellType.BLACK) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
if(this.IsEmpty(i,j,array)&&this.IsNotBlack(i,j-1,array)&&this.IsNotBlack(i,j+5,array)) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            count4
++;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            
continue;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
if(this.IsEmpty(i,j+5,array)&&this.IsNotBlack(i,j+4,array)&&this.IsNotBlack(i,j,array)) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            count4
++;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            
continue;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                var tmpIndex:
int;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                
// calculate open 3's count
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断
                for(j=4; j<7; j++大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    
// patten: ??0x00??
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
                    if(array[i][j]==CellType.BLACK&&this.IsEmpty(i,j+1,array)&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        array[i][j
+2]==CellType.BLACK&&array[i][j+3]==CellType.BLACK&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
this.IsEmpty(i,j-1,array)&&this.IsEmpty(i,j+4,array)&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        (
this.IsNotBlack(i,j-2,array)||this.IsNotBlack(i,j+5,array))) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        tmpIndex 
= this.IndexConverter(i,j+1,x,y);
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
if(this.IsForbidden(Math.floor(tmpIndex/15),tmpIndex%15,board)==ResultType.NOTHING)大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            count3
++;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
continue;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    
// patten: ??00x0??
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
                    if(array[i][j]==CellType.BLACK&&array[i][j+1]==CellType.BLACK&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
this.IsEmpty(i,j+2,array)&&array[i][j+3]==CellType.BLACK&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
this.IsEmpty(i,j-1,array)&&this.IsEmpty(i,j+4,array)&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        (
this.IsNotBlack(i,j-2,array)||this.IsNotBlack(i,j+5,array))) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        tmpIndex 
= this.IndexConverter(i,j+2,x,y);
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
if(this.IsForbidden(Math.floor(tmpIndex/15),tmpIndex%15,board)==ResultType.NOTHING) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{    
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            count3
++;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
continue;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    
// patten: ??000??
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断
                    if(array[i][j]==CellType.BLACK&&array[i][j+1]==CellType.BLACK&&array[i][j+2]==CellType.BLACK) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
if(this.IsEmpty(i,j-2,array)&&this.IsEmpty(i,j-1,array)&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            
this.IsEmpty(i,j+3,array)&&this.IsNotBlack(i,j-3,array)) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            tmpIndex 
= this.IndexConverter(i,j-1,x,y);
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            
if(this.IsForbidden(Math.floor(tmpIndex/15),tmpIndex%15,board)==ResultType.NOTHING) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                                count3
++;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                                
continue;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        
if(this.IsEmpty(i,j-1,array)&&this.IsEmpty(i,j+3,array)&&
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            
this.IsEmpty(i,j+4,array)&&this.IsNotBlack(i,j+5,array)) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            tmpIndex 
= this.IndexConverter(i,j+3,x,y);
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            
if(this.IsForbidden(Math.floor(tmpIndex/15),tmpIndex%15,board)==ResultType.NOTHING) 大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                                count3
++;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                                
continue;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                            }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                        }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                    }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断                }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断            }
    
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
// reset the position to empty and return result.
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
            board[index] = CellType.EMPTY;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
if(count3>1大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                
return ResultType.DOUBLE_THREE;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
if(count4>1大道五目Flash英文版(Renju Problems)程序分析之禁手判断{
大道五目Flash英文版(Renju Problems)程序分析之禁手判断                
return ResultType.DOUBLE_FOUR;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断            }

大道五目Flash英文版(Renju Problems)程序分析之禁手判断            
return ResultType.NOTHING;
大道五目Flash英文版(Renju Problems)程序分析之禁手判断        }

就是通过一个递归判断是否当前下子为禁手。

测试后发现可以判断复杂的禁手,如:

大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断

大道五目Flash英文版(Renju Problems)程序分析之禁手判断大道五目Flash英文版(Renju Problems)程序分析之禁手判断

转载于:https://www.cnblogs.com/boringlamb/archive/2008/11/04/1326291.html

相关文章:

  • 2021-07-27
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
猜你喜欢
  • 2021-10-22
  • 2022-01-24
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
  • 2021-10-10
相关资源
相似解决方案