智能五子棋基本思路

前些天闲时写的,在学数据结构的时拿来练手的.没技术含量,最有技术含量的AI部分,我是看别人(园子里叫二十四生的)的算法改的.刚弄了一下午小程序弄不过去,头疼,现无聊的紧,闲着发着玩.当消遣
主要发下AI核心算法.有兴趣的同学用VB,VC.VC#都可以一起做着玩.保持对编程的兴趣.其它没了.


一,说下五子棋的原理:5子成一线即赢.
所以可以这样做,当一子落下时,判断该子是否成5子,下面的代码说的很清楚了

ExpandedBlockStart.gifContractedBlock.gif        /**//// <summary>当一棋子落子时检查该色子是否胜利
InBlock.gif        
/// 当一棋子落子时检查该色子是否胜利
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="chessPoint">落子位置</param>
InBlock.gif        
/// <param name="color">棋子色</param>
InBlock.gif        
/// <returns>bool</returns>
InBlock.gif        
/// 把棋子分8个方向计算
InBlock.gif        
/// 2    3     4
InBlock.gif        
/// 1    x,y   5
ExpandedBlockEnd.gif        
/// 8     7    6

None.gif        public bool CheckeWin(ChessPoint chessPoint, CheckerColor color)  //检查是否胜利
ExpandedBlockStart.gifContractedBlock.gif
        dot.gif{
InBlock.gif            
int X = chessPoint.X;
InBlock.gif            
int Y = chessPoint.Y;
InBlock.gif
InBlock.gif            
int times = 1;
InBlock.gif            
int tempX = X - 1;
InBlock.gif            
int tempY = Y;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**///检查 1 方向//
InBlock.gif            while (true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (NextHasChecker(tempX, tempY, 1, color))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    times
++;
InBlock.gif                    tempX
--;
InBlock.gif                    
continue;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**/////检查 5  方向////
InBlock.gif            tempX = X + 1;
InBlock.gif            
while (true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (NextHasChecker(tempX, tempY, 5, color))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    times
++;
InBlock.gif                    tempX
++;
InBlock.gif                    
continue;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if (times >= 5)
InBlock.gif                
return true;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**/////1-5 方向检查完毕
InBlock.gif            times = 1;
InBlock.gif            tempX 
= X;
InBlock.gif            tempY 
= Y - 1;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**///检查 3 方向////
InBlock.gif            while (true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (NextHasChecker(tempX, tempY, 3, color))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    times
++;
InBlock.gif                    tempY
--;
InBlock.gif                    
continue;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**///检查 7 方向
InBlock.gif            tempY = Y + 1;
InBlock.gif            
while (true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (NextHasChecker(tempX, tempY, 7, color))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    times
++;
InBlock.gif                    tempY
++;
InBlock.gif                    
continue;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if (times >= 5)
InBlock.gif                
return true;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**//3-7 方向检查完毕////
InBlock.gif            times = 1;
InBlock.gif            tempX 
= X - 1;
InBlock.gif            tempY 
= Y - 1;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**////检查 2 方向
InBlock.gif            while (true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (NextHasChecker(tempX, tempY, 2, color))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    times
++;
InBlock.gif                    tempX
--;
InBlock.gif                    tempY
--;
InBlock.gif                    
continue;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            tempX 
= X + 1;
InBlock.gif            tempY 
= Y + 1;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**//检查 6 方向/
InBlock.gif            while (true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (NextHasChecker(tempX, tempY, 6, color))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    times
++;
InBlock.gif                    tempX
++;
InBlock.gif                    tempY
++;
InBlock.gif                    
continue;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if (times >= 5)
InBlock.gif                
return true;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**/2-6方向检查完毕////
InBlock.gif            times = 1;
InBlock.gif            tempX 
= X + 1;
InBlock.gif            tempY 
= Y - 1;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**////检查 4 方向
InBlock.gif            while (true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (NextHasChecker(tempX, tempY, 4, color))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    times
++;
InBlock.gif                    tempX
++;
InBlock.gif                    tempY
--;
InBlock.gif                    
continue;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            tempX 
= X - 1;
InBlock.gif            tempY 
= Y + 1;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
/**////检查 8 方向/
InBlock.gif            while (true)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (NextHasChecker(tempX, tempY, 8, color))
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    times
++;
InBlock.gif                    tempX
--;
InBlock.gif                    tempY
++;
InBlock.gif                    
continue;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
if (times >= 5)
InBlock.gif                
return true;
InBlock.gif
InBlock.gif            
return false;   //默认返回False
InBlock.gif

ExpandedBlockEnd.gif        }

ContractedBlock.gifExpandedBlockStart.gif       
检查1.2.3.4.5.6.7.8 方向是否有该色的子#region  检查1.2.3.4.5.6.7.8 方向是否有该色的子
InBlock.gif       
public bool NextHasChecker(int x, int y, int direction, CheckerColor color)
ExpandedSubBlockStart.gifContractedSubBlock.gif       
dot.gif{
InBlock.gif           
switch (direction)
ExpandedSubBlockStart.gifContractedSubBlock.gif           
dot.gif{
InBlock.gif               
case 1:
InBlock.gif                   
if (x < 0return false;
InBlock.gif                   
if (GoBang[x, y] != null && GoBang[x, y].CheckColor == color)
InBlock.gif                       
return true;
InBlock.gif                   
else
InBlock.gif                       
return false;
InBlock.gif               
case 5:
InBlock.gif                   
if (x > 14return false;
InBlock.gif                   
if (GoBang[x, y] != null && GoBang[x, y].CheckColor == color)
InBlock.gif                       
return true;
InBlock.gif                   
else
InBlock.gif                       
return false;
InBlock.gif               
case 3:
InBlock.gif                   
if (y < 0return false;
InBlock.gif                   
if (GoBang[x, y] != null && GoBang[x, y].CheckColor == color)
InBlock.gif                       
return true;
InBlock.gif                   
else
InBlock.gif                       
return false;
InBlock.gif               
case 7:
InBlock.gif                   
if (y > 14return false;
InBlock.gif                   
if (GoBang[x, y] != null && GoBang[x, y].CheckColor == color)
InBlock.gif                       
return true;
InBlock.gif                   
else
InBlock.gif                       
return false;
InBlock.gif               
case 2:
InBlock.gif                   
if (x < 0 || y < 0return false;
InBlock.gif                   
if (GoBang[x, y] != null && GoBang[x, y].CheckColor == color)
InBlock.gif                       
return true;
InBlock.gif                   
else
InBlock.gif                       
return false;
InBlock.gif               
case 6:
InBlock.gif                   
if (x > 14 || y > 14return false;
InBlock.gif                   
if (GoBang[x, y] != null && GoBang[x, y].CheckColor == color)
InBlock.gif                       
return true;
InBlock.gif                   
else
InBlock.gif                       
return false;
InBlock.gif               
case 4:
InBlock.gif                   
if (x > 14 || y < 0return false;
InBlock.gif                   
if (GoBang[x, y] != null && GoBang[x, y].CheckColor == color)
InBlock.gif                       
return true;
InBlock.gif                   
else
InBlock.gif                       
return false;
InBlock.gif               
case 8:
InBlock.gif                   
if (x < 0 || y > 14return false;
InBlock.gif                   
if (GoBang[x, y] != null && GoBang[x, y].CheckColor == color)
InBlock.gif                       
return true;
InBlock.gif                   
else
InBlock.gif                       
return false;
InBlock.gif               
default:
InBlock.gif                   
return false;
InBlock.gif
ExpandedSubBlockEnd.gif           }

ExpandedSubBlockEnd.gif       }

ExpandedBlockEnd.gif       
#endregion
            //检查1.2.3.4.5.6.7.8 方向是否有该色的子
None.gif
(二),这样只是达到判断胜否的目的.做一个单机版的五子棋.要求有个电脑和你玩.那么就是个AI的问题,COMPUTER,根椐盘上的棋子作出相应的攻守.
一个稍微简单点的AI,也是我能理解的AI思路.当电脑下子时,递归或循环棋盘上每一个未下子的位置,对每个位置下子进行打分,比如当电脑色棋面上有三子已成一线,且成"活三"必胜局面,那么在此位置下子应当是得分比较高的点,或者当对手的成"活三","双三","禁手"的点,在那点电脑下子也应当是得分比较高的,其次是成二子,成一子..依次分配合理的权值.最后把权值相加,取得分最高点着子.所以不同情况的权值的取大小直接影响到电脑对该位置落子认可度.当然我没有,要很多的测试才能得出,下面给一个别人的权值计算公式,相对合理.
           //找自己的取胜点(10000)
           int w1 = 100000;
           //找对手的取胜点(50000)
           int w2 = 50000;
           //找自己的三个相连的点(10000)
           int w3 = 10000;
           //找对手的三个相连的点(5000)
           int w4 = 5000;
           //找自己的两个相连的点(1000)
           int w5 = 1000;
           //找对手的两个相连的点(500)
           int w6 = 500;
           //找自己的相连的点(100)
           int w7 = 100;
           //找对方的相连的点(50)
           int w8 = 50;
           //找自己的失败点
           int w9 = -1000000;
(三),明白了COMPUTER找最佳落子位置原理后就是计算棋盘上落子的分值的时候了.
前面已说过.一个棋子在盘中有四个方向,水平,竖值,两个方向斜,前面说是1.2.3.4.5.6.7.8那么也就是计算这4个方向的棋子的连子数,我给出参考算法:
ContractedBlock.gifExpandedBlockStart.gif
ContractedBlock.gifExpandedBlockStart.gif从四个方向检测,连子个数#region 从四个方向检测,连子个数
InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 正东正西检测与m,n点棋子相同的棋子个数
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="m"></param>
InBlock.gif        
/// <param name="n"></param>
InBlock.gif        
/// <param name="arrchessboard"></param>
ExpandedSubBlockEnd.gif        
/// <returns>如果返回负值则表示改方向在无子可下</returns>

InBlock.gif        public static int Xnum(int m, int n, Checker[,] arrchessboard,CheckerColor color)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//检查是否无子可下(当flag=2时表示无子可下)
InBlock.gif
            int flag = 0;
InBlock.gif            
//连子个数
InBlock.gif
            int num = 1;
InBlock.gif
InBlock.gif            
//正东方向检查(x+)
InBlock.gif
            int i = m + 1;
InBlock.gif            
//不超出棋格
InBlock.gif
            while (i < 15)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif
InBlock.gif                
//前方的棋子与m,n点不同时跳出循环
InBlock.gif
                if (arrchessboard[i, n] != null && arrchessboard[i, n].CheckColor == color)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    num
++;
InBlock.gif                    i
++;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
//正东方向超出棋格
InBlock.gif
            if (i == 15)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                flag
++;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//正东方向有别的子不可在下
InBlock.gif
                if (arrchessboard[i, n] != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    flag
++;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
//正西方向检查(x-)
InBlock.gif
            i = m - 1;
InBlock.gif            
while (i >= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//前方的棋子与m,n点不同时跳出循环
InBlock.gif
                if (arrchessboard[i, n] != null && arrchessboard[i, n].CheckColor == color)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    num
++;
InBlock.gif                    i
--;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
//正西方向超出棋格
InBlock.gif
            if (i == -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                flag
++;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//正西方向有别的子不可在下
InBlock.gif
                if (arrchessboard[i, n] != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    flag
++;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif
InBlock.gif            
if (flag == 2)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return -num;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (flag == 1 && num == 3)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//连子数为3时有一边不能下就不是活三
InBlock.gif
                    return -num;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return num;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 正南正北方向检测
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="m"></param>
InBlock.gif        
/// <param name="n"></param>
InBlock.gif        
/// <param name="arrchessboard"></param>
ExpandedSubBlockEnd.gif        
/// <returns>如果返回负值则表示改方向在无子可下</returns>

InBlock.gif      public static int Ynum(int m, int n, Checker[,] arrchessboard, CheckerColor color)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//检查是否无子可下(当flag=2时表示无子可下)
InBlock.gif
            int flag = 0;
InBlock.gif            
//连子个数
InBlock.gif
            int num = 1;
InBlock.gif            
//正南方向检查(y+)
InBlock.gif
            int i = n + 1;
InBlock.gif            
while (i < 15)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//前方的棋子与m,n点不同时跳出循环
InBlock.gif
                if (arrchessboard[m,i] != null && arrchessboard[m, i].CheckColor == color)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    num
++;
InBlock.gif                    i
++;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
//正南方向超出棋格
InBlock.gif
            if (i == 15)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                flag
++;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//正南方向有别的子不可在下
InBlock.gif
                if (arrchessboard[m, i] != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    flag
++;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
//正北方向检查(y-)
InBlock.gif
            i = n - 1;
InBlock.gif            
while (i >= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//前方的棋子与m,n点不同时跳出循环
InBlock.gif
                if (arrchessboard[m,i] != null && arrchessboard[m, i].CheckColor == color)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    num
++;
InBlock.gif                    i
--;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
//正北方向超出棋格
InBlock.gif
            if (i == -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                flag
++;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//正北方向有别的子不可在下
InBlock.gif
                if (arrchessboard[m, i] != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    flag
++;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
if (flag == 2)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return -num;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (flag == 1 && num == 3)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//连子数为3时有一边不能下就不是活三
InBlock.gif
                    return -num;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return num;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 西北东南方向检查
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="m"></param>
InBlock.gif        
/// <param name="n"></param>
InBlock.gif        
/// <param name="arrchessboard"></param>
ExpandedSubBlockEnd.gif        
/// <returns>如果返回负值则表示改方向在无子可下</returns>

InBlock.gif      public static int YXnum(int m, int n, Checker[,] arrchessboard, CheckerColor color)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//检查是否无子可下(当flag=2时表示无子可下)
InBlock.gif
            int flag = 0;
InBlock.gif            
//连子个数
InBlock.gif
            int num = 1;
InBlock.gif
InBlock.gif            
//东南方向(x+,y+)
InBlock.gif
            int i = m + 1;
InBlock.gif            
int j = n + 1;
InBlock.gif            
//不超出棋格
InBlock.gif
            while (i < 15 && j < 15)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//前方的棋子与m,n点不同时跳出循环
InBlock.gif
                if (arrchessboard[i,j] != null && arrchessboard[i, j].CheckColor== color)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    num
++;
InBlock.gif                    i
++;
InBlock.gif                    j
++;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
//东南方向超出棋格
InBlock.gif
            if (i == 15 || j == 15)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                flag
++;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//东南方向有别的子不可在下
InBlock.gif
                if (arrchessboard[i, j] != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    flag
++;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
//西北方向(x-,y-)
InBlock.gif
            i = m - 1;
InBlock.gif            j 
= n - 1;
InBlock.gif            
//不超出棋格
InBlock.gif
            while (i >= 0 && j >= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//前方的棋子与m,n点不同时跳出循环
InBlock.gif
                if (arrchessboard[i, j] != null && arrchessboard[i, j].CheckColor == color)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    num
++;
InBlock.gif                    i
--;
InBlock.gif                    j
--;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
//西北方向超出棋格
InBlock.gif
            if (i == -1 || j == -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                flag
++;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//西北方向有别的子不可在下
InBlock.gif
                if (arrchessboard[i, j] != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    flag
++;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
if (flag == 2)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return -num;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (flag == 1 && num == 3)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//连子数为3时有一边不能下就不是活三
InBlock.gif
                    return -num;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return num;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 西南东北方向检查
InBlock.gif        
/// </summary>
InBlock.gif        
/// <param name="m"></param>
InBlock.gif        
/// <param name="n"></param>
InBlock.gif        
/// <param name="arrchessboard"></param>
ExpandedSubBlockEnd.gif        
/// <returns>如果返回负值则表示改方向在无子可下</returns>

InBlock.gif      public static int XYnum(int m, int n, Checker[,] arrchessboard, CheckerColor color)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
//检查是否无子可下(当flag=2时表示无子可下)
InBlock.gif
            int flag = 0;
InBlock.gif            
//连子个数
InBlock.gif
            int num = 1;
InBlock.gif
InBlock.gif            
//西南方向(x-,y+)
InBlock.gif
            int i = m - 1;
InBlock.gif            
int j = n + 1;
InBlock.gif            
//不超出棋格
InBlock.gif
            while (i >= 0 && j < 15)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//前方的棋子与m,n点不同时跳出循环
InBlock.gif
                if (arrchessboard[i, j] != null && arrchessboard[i, j].CheckColor == color)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    num
++;
InBlock.gif                    i
--;
InBlock.gif                    j
++;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
//西南方向超出棋格
InBlock.gif
            if (i == -1 || j == 15)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                flag
++;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//西南方向有别的子不可在下
InBlock.gif
                if (arrchessboard[i, j] != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    flag
++;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
//东北方向(x+,y-)
InBlock.gif
            i = m + 1;
InBlock.gif            j 
= n - 1;
InBlock.gif            
//不超出棋格
InBlock.gif
            while (i < 15 && j >= 0)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//前方的棋子与m,n点不同时跳出循环
InBlock.gif
                if (arrchessboard[i, j] != null && arrchessboard[i, j].CheckColor == color)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    num
++;
InBlock.gif                    i
++;
InBlock.gif                    j
--;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
break;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
//东北方向超出棋格
InBlock.gif
            if (i == 15 || j == -1)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                flag
++;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
//东北方向有别的子不可在下
InBlock.gif
                if (arrchessboard[i, j] != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    flag
++;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif
InBlock.gif            
if (flag == 2)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return -num;
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
if (flag == 1 && num == 3)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
//连子数为3时有一边不能下就不是活三
InBlock.gif
                    return -num;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
return num;
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedBlockEnd.gif        
#endregion

(四),上面是对一点计算如果在该处落子时得分,设四个数组,就是那四个方向的连子数*相应权值
           arrf[0]
           arrf[1]
           arrf[2]
           arrf[3]
那么找最高分就是一个循环或递归的过程,不多说.
找到该点坐标,落子.交换棋子色,人下子,COMPUTER下子,...只到有5子有人成功.

我用C#,VS2005完整解决方案放下,关于人工智能,何其深奥,已此简单的算法基础我对AI有一点初步认识.

 

转载于:https://www.cnblogs.com/solo/archive/2007/01/09/616068.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/264831.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

webpack 4.0 配置文件 webpack.config.js文件的放置位置

一般webpack.config.js是默认放在根目录的&#xff0c;不在根目录的时候需要在package.json中制定位置&#xff0c;我的配置文件目录是config/webpack.config.js,在package.json文件中的配置为&#xff1a; "scripts": { "build": "webpack --mode p…

Python-memcached的基本使用 - Flynewton成长点滴 - 开源中国社区

Python-memcached的基本使用 - Flynewton成长点滴 - 开源中国社区Python-memcached的基本使用 发表于3年前(2010-12-04 00:02) 阅读&#xff08;9601&#xff09; | 评论&#xff08;3&#xff09; 12人收藏此文章, 我要收藏 赞1 python memcached 想学Python&#xff0c;又想…

快速构建ceph可视化监控系统

https://my.oschina.net/colben/blog/1844602 https://my.oschina.net/u/3626804/blog/1859613转载于:https://www.cnblogs.com/diyunpeng/p/10363183.html

阳奉阴违(转载)

这个词不是好词&#xff0c;大家都这么看&#xff0c;但现在生活里却经常要照它做&#xff0c;表面上应付一下&#xff0c;表示一下&#xff0c;然后再怎么做就随便&#xff1b;如果你不表示这一下&#xff0c;那就怎么也不行。 MSN和Yahoo就已经理解了这个问题&#xff0c;并且…

PowerShell远程管理Windows Server(2):公网访问【web形式】

*此文章只适合于windows server 2012版本以上&#xff1b;Powershell Web Access需要两个步骤才能使用&#xff1a;一、安装powershell web access功能&#xff1b;二、配置powershell web access&#xff1b;只要在服务器上启用powershell web access功能&#xff0c;即可通过…

POJ 3090 Visible Lattice Points 【欧拉函数】

<题目链接> 题目大意&#xff1a; 给出范围为(0, 0)到(n, n)的整点&#xff0c;你站在(0,0)处&#xff0c;问能够看见几个点。 解题分析&#xff1a;很明显&#xff0c;因为 N (1 ≤ N ≤ 1000) &#xff0c;所以无论 N 为多大&#xff0c;(0,1),(1,1),(1,0)这三个点一定…

2005的行列转换

2005的行列转换: create table ta(编号 int,人员 varchar(5), 年份 int,月份 int ,[1号] varchar(5), [2号] varchar(5),[3号] varchar(5),[4号] varchar(5))insert ta select 1, 张三,2006, 1, 正常, 迟到, 迟到, 事假union all select 2, 张三, 2006, 2, 迟到, 事假, 正常, 正…

精选 5 个漂亮的 CSS3 图片滑过特效

这篇文章将为大家分享5款漂亮的CSS3图片滑过特效&#xff0c;比如滑过后显示图片的详细文字介绍&#xff0c;又比如滑过后对图片进行淡入淡出的效果等等。让我们一起来看看&#xff0c;喜欢的朋友赶紧收藏。 1、非常酷的CSS3图片说明效果 在线演示 / 源码下载 2、纯CSS3图片相…

Koa2 静态服务及代理配置

const path require(path) const Koa require(koa) const static require(koa-static) const httpProxyMiddleware require(http-proxy-middleware) const koaConnect require(koa2-connect)const app new Koa()// 引入静态文件 app.use(static(path.join(__dirname, dis…

问题:上司说「看你每天准时下班就知道你工作量不饱和」,如何回应

问题&#xff1a;上司说「看你每天准时下班就知道你工作量不饱和」&#xff0c;如何回应正常下班时间6点&#xff0c;只要是6点半前下班的&#xff0c;上司都认为没有加班。Eno-Bea回答&#xff0c;注重感受&#xff0c;不一定是别人的虽然我不知道你具体从事什么工作与职业&am…

请不要做浮躁的人

1.不要看到别人的回复第一句话就说&#xff1a;给个代码吧&#xff01;你应该想想为什么。当你自己想出来再参考别人的提示&#xff0c;你就知道自己和别人思路的差异。2.初学者请不要看太多太多的书那会误人子弟的&#xff0c;先找本系统的学&#xff0c;很多人用了很久都是只…

framework 2.0 新增的一个string.split()方法重载

在1.1版本的时候&#xff0c;出现的split方法只能够使用分隔符分开一个字符串得到一个数组&#xff0c;如果2个分隔符连续的话&#xff0c;那么这个方法会把他解析成一个空字符串在数组中&#xff0c;但是现在的framework2.提供一个重载&#xff0c;支持不把连续的分隔符解析成…

1_Why DL work ?

1 . Why Deep? 李宏毅的解释&#xff1a;Modularization 【模块化的益处】https://zhuanlan.zhihu.com/p/22888385 【另一个知乎大佬】转载于:https://www.cnblogs.com/LS1314/p/10380789.html

Java 全半角转换

* 全角转半角的 转换函数* return String*/public static final String full2HalfChange(String QJstr){StringBuffer outStrBuf new StringBuffer("");String Tstr "";byte[] b null;for (int i 0; i < QJstr.length(); i) {Tstr QJstr.substring…

异或特性

异或的两个特性 两个相等的数的异或为0&#xff1b;任何一个数和0异或之后&#xff0c;还是这个数不变应用 在 1 到 n 的数字中&#xff0c;有且只有唯一的一个数字 m 重复出现偶数次&#xff0c;其他数字都只出现一次&#xff0c;请用异或把这个数字找出来。 原始数据: 1,2...…

Cocos2d-x 3.0新引擎文件夹结构

Cocos2d-x 3.0新引擎文件夹结构2014年4月29日 Cocos2d-x 3.0学习作为一个Cocos2d-x的菜鸟&#xff0c;我倒是挺愿意关注不同版本号之间的差别&#xff0c;Cocos2d-x 3.0自2013年7月份開始公布alpha0-pre版本号&#xff0c;到2014年4月23日公布正式版&#xff0c;历经9个版本号…

SOA系列文章(二):服务设计原理:服务模式和反模式

服务设计系列的法则已经发展到最佳通信实践和取样相关编码的程度。本文提供了设计和实现网络服务的基本原理&#xff0c;并且对面向服务的体系结构(SOA)的相关概念做了一个简要的回顾&#xff0c;以及有关于几种模式和反模式的详细讨论&#xff0c;当构建网络服务时&#xff0c…

iOS程序启动原理(上)

为什么80%的码农都做不了架构师&#xff1f;>>> iOS程序启动原理 Info.plist 常见设置 建立一个工程后,会在Supporting files文件夹下看到一个"工程名-Info.plist"的文件,该文件对工程做一些运行期的配置,非常重要,不能删除. 在旧版Xcode创建的工程中,这…

何时使用委托而不使用接口

委托和接口都允许类设计器分离类型声明和实现。给定的接口可由任何类或结构继承和实现&#xff1b;可以为任何类中的方法创建委托&#xff0c;前提是该方法符合委托的方法签名。接口引用或委托可由不了解实现该接口或委托方法的类的对象使用。既然存在这些相似性&#xff0c;那…

microsoft project 出现不能保存为xls文件时可以按照如下方法解决

工具-》选项-》安全性转载于:https://www.cnblogs.com/oymx/p/3753291.html