Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 编程语言 > .NET > C#.NET > Monkey黑白棋 所使用的经典算法(源代码)
【标  题】:Monkey黑白棋 所使用的经典算法(源代码)
【关键字】:Monkey
【来  源】:http://blog.csdn.net/fengart/archive/2007/04/18/1568955.aspx

Monkey黑白棋 所使用的经典算法(源代码)

Your Ad Here
         /// <summary>
        
/// AlphaBeta剪枝法
        
/// </summary>
        
/// <returns></returns>

        private int AlphaBetaSearch(int curDepth, int alpha, int beta)
        
{
            
lock (this)
            
{
                
if (curDepth >= Depth || times >= MaxTimes)
                
{
                    times
++;
                    
//开局或中局对棋盘评分,boardState指定是开局还是中局
                    MonkeyOthello.BoardFX(boardState);
                    SetNums(
0);
                    SetNums(
1);
                    
//返回估值
                    return SetScore(boardState);
                }

                
else
                
{
                    
//if (times < MaxTimes)
                    
//{
                    
//    StaticObject.ThinkingProgressBar.Value = times;
                    
//}
                    if (!MonkeyOthello.CanDown())
                    
{
                        
//如果没棋可下,交换对手
                        MonkeyOthello.CurrentColor = 1 - MonkeyOthello.CurrentColor;
                        
if (!MonkeyOthello.CanDown())
                        
{
                            
//双方都没棋可下,则不用再往下搜索
                            MonkeyOthello.CurrentColor = 1 - MonkeyOthello.CurrentColor;
                            
//中局就已经结束游戏,获取中局的结果
                            GameResult result = MonkeyOthello.GetMidGameResult((int)MonkeyOthello.CurrentColor);
                            
//中局就已经结束游戏,返回游戏结束的估值
                            return EvalGameOver(result, beta);
                        }

                        
else
                        
{
                            
//其中一方无棋可下,继续由对方下
                            return -AlphaBetaSearch(curDepth + 1-beta, -alpha);
                            
//alpha = -beta; beta = -alpha; curDepth++;
                        }

                    }

                    
//进栈(当前的所有棋步)
                    AllStepStack.Push(new Stack<Step>(MonkeyOthello.Mobility));
                    
//当前估值
                    int score;
                    
//棋步数量
                    int Num = MonkeyOthello.MobilityNum[(int)MonkeyOthello.CurrentColor];
                    
for (int i = 0; i < Num; i++)
                    
{
                        
//获取没有访问过的棋步
                        Step step = GetNotVisitedStep();
                        
//模拟下一步棋
                        MonkeyOthello.DownStones(step);
                        
// 搜索下一步(递归)
                        score= -AlphaBetaSearch(curDepth + 1-beta, -alpha);
                        
//退一步
                        MonkeyOthello.Reback();
                        
//搜索到比上次高的估值,替换
                        if (score > alpha)
                        
{
                            alpha 
= score;
                            
//如果认为已经赢定,则可以终止搜索
                            if (score >= beta)
                                
break;
                        }

                    }

                    
//退栈(当前的所有棋步)
                    AllStepStack.Pop();
                    
return alpha;
                }

            }

        }


      我把它用在开局和中局的思考,当然开局跟中局的评估函数有区别

     而当离游戏还有10-12步时,用它来搜索最大赢子数.

Windows内核API HOOK 之 Inline Hook:【上一篇】
.NET2.0抓取网页全部链接:【下一篇】
【相关文章】
  • 编译seamonkey
  • SpiderMonkey-让你的C++程序支持JavaScript脚本
  • 我的第一个 C++ 配合 XML以及GameMonkey脚本的DEMO程序
  • 使用greasemonkey扩展web应用
  • Fix SeaMonkey/Firefox 与紫光拼音输入法的兼容问题
  • Mozilla新产品:SeaMonkey
  • 用UltraMonkey(Linux Virtual Server)实现负载均衡
  • 风玩转MP3:使用Monkeys Audio转换APE为MP3
  • Monkey 病毒的分析和防治
  • 【随机文章】
  • aix操作系统的版本查询办法
  • 带有行数和标尺的RichTextBox
  • RMAN 初学者指南
  • XML四种解析器原理及性能比较
  • Ontology,RDFS,OWL
  • 为wiki集成“插入代码”& AspectWeaver Step by Step AOP在线教程
  • 硬盘安装Ubuntu经验分享(转)
  • POSIX线程编程
  • 如何正确区分国内行货、水货、香港行货?
  • 通过样式表实现固定表头和列
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.