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

现在界面已经完成了,

 

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

ContractedBlock.gifExpandedBlockStart.gifCode
ExpandedBlockStart.gifContractedBlock.gifprivate function IsForbidden(x:int, y:int, board:Array):int {
            var index:
int = x*15+y;
            
            
// set this position(x,y) to black.
            board[index] = CellType.BLACK;
            
            
// 1st check whether there is overline.
            var array:Array =this.GetAnalyseArray(x,y,board);
            
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if(this.IsOverline(array)) {
                board[index] 
= CellType.EMPTY;
                
return ResultType.OVERLINE;
            }

            
            
// use recursion to check whether there is double-4 or double-3.
            
// the check methord is count the open 3 and open 4's count,
            
// if one of them larger than 1 so is a forbidden.
            var count3:int = 0;
            var count4:
int = 0;
            
            var i, j:
int = 0;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
for(i=0; i<4; i++{
                
                
// calculate open 4's count.
ExpandedSubBlockStart.gifContractedSubBlock.gif
                for(j=3; j<7; j++{
                    
// patten: ?0x000?
                    if(array[i][j]==CellType.BLACK&&this.IsEmpty(i,j+1,array)&& 
                        array[i][j
+2]==CellType.BLACK&&array[i][j+3]==CellType.BLACK&&
                        array[i][j
+4]==CellType.BLACK&&
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
this.IsNotBlack(i,j-1,array)&&this.IsNotBlack(i,j+5,array)) {
                        count4
++;
                        
continue;    
                    }

                    
// patten: ?00x00?
                    if(array[i][j]==CellType.BLACK&&array[i][j+1]==CellType.BLACK&& 
                        
this.IsEmpty(i,j+2,array)&&array[i][j+3]==CellType.BLACK&&
                        array[i][j
+4]==CellType.BLACK&&
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
this.IsNotBlack(i,j-1,array)&&this.IsNotBlack(i,j+5,array)) {
                        count4
++;
                        
continue;
                    }

                    
// patten: ?000x0?
                    if(array[i][j]==CellType.BLACK&&array[i][j+1]==CellType.BLACK && 
                        array[i][j
+2]==CellType.BLACK&&this.IsEmpty(i,j+3,array) &&
                        array[i][j
+4]==CellType.BLACK&&
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
this.IsNotBlack(i,j-1,array)&&this.IsNotBlack(i,j+5,array)) {
                        count4
++;
                        
continue;
                    }

                    
// patten: ??0000??
                    
// not like above three, this check index is the above index plus 1.
                    
// in other words, the check index is 4 to 8 and above index is 3 to 7.
                    if(array[i][j+1]==CellType.BLACK&&array[i][j+2]==CellType.BLACK&& 
ExpandedSubBlockStart.gifContractedSubBlock.gif                        array[i][j
+3]==CellType.BLACK&&array[i][j+4]==CellType.BLACK) {
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
if(this.IsEmpty(i,j,array)&&this.IsNotBlack(i,j-1,array)&&this.IsNotBlack(i,j+5,array)) {
                            count4
++;
                            
continue;
                        }

ExpandedSubBlockStart.gifContractedSubBlock.gif                        
if(this.IsEmpty(i,j+5,array)&&this.IsNotBlack(i,j+4,array)&&this.IsNotBlack(i,j,array)) {
                            count4
++;
                            
continue;
                        }

                    }

                }

                
                var tmpIndex:
int;
                
// calculate open 3's count
ExpandedSubBlockStart.gifContractedSubBlock.gif
                for(j=4; j<7; j++{
                    
// patten: ??0x00??
                    if(array[i][j]==CellType.BLACK&&this.IsEmpty(i,j+1,array)&&
                        array[i][j
+2]==CellType.BLACK&&array[i][j+3]==CellType.BLACK&&
                        
this.IsEmpty(i,j-1,array)&&this.IsEmpty(i,j+4,array)&&
ExpandedSubBlockStart.gifContractedSubBlock.gif                        (
this.IsNotBlack(i,j-2,array)||this.IsNotBlack(i,j+5,array))) {
                        tmpIndex 
= this.IndexConverter(i,j+1,x,y);
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
if(this.IsForbidden(Math.floor(tmpIndex/15),tmpIndex%15,board)==ResultType.NOTHING){
                            count3
++;
                        }

                        
continue;
                    }

                    
// patten: ??00x0??
                    if(array[i][j]==CellType.BLACK&&array[i][j+1]==CellType.BLACK&&
                        
this.IsEmpty(i,j+2,array)&&array[i][j+3]==CellType.BLACK&&
                        
this.IsEmpty(i,j-1,array)&&this.IsEmpty(i,j+4,array)&&
ExpandedSubBlockStart.gifContractedSubBlock.gif                        (
this.IsNotBlack(i,j-2,array)||this.IsNotBlack(i,j+5,array))) {
                        tmpIndex 
= this.IndexConverter(i,j+2,x,y);
ExpandedSubBlockStart.gifContractedSubBlock.gif                        
if(this.IsForbidden(Math.floor(tmpIndex/15),tmpIndex%15,board)==ResultType.NOTHING) {    
                            count3
++;
                        }

                        
continue;
                    }

                    
// patten: ??000??
ExpandedSubBlockStart.gifContractedSubBlock.gif
                    if(array[i][j]==CellType.BLACK&&array[i][j+1]==CellType.BLACK&&array[i][j+2]==CellType.BLACK) {
                        
if(this.IsEmpty(i,j-2,array)&&this.IsEmpty(i,j-1,array)&&
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
this.IsEmpty(i,j+3,array)&&this.IsNotBlack(i,j-3,array)) {
                            tmpIndex 
= this.IndexConverter(i,j-1,x,y);
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
if(this.IsForbidden(Math.floor(tmpIndex/15),tmpIndex%15,board)==ResultType.NOTHING) {
                                count3
++;
                                
continue;
                            }

                        }

                        
if(this.IsEmpty(i,j-1,array)&&this.IsEmpty(i,j+3,array)&&
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
this.IsEmpty(i,j+4,array)&&this.IsNotBlack(i,j+5,array)) {
                            tmpIndex 
= this.IndexConverter(i,j+3,x,y);
ExpandedSubBlockStart.gifContractedSubBlock.gif                            
if(this.IsForbidden(Math.floor(tmpIndex/15),tmpIndex%15,board)==ResultType.NOTHING) {
                                count3
++;
                                
continue;
                            }

                        }

                    }

                }

            }
    
            
            
// reset the position to empty and return result.
            board[index] = CellType.EMPTY;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if(count3>1{
                
return ResultType.DOUBLE_THREE;
            }

ExpandedSubBlockStart.gifContractedSubBlock.gif            
if(count4>1{
                
return ResultType.DOUBLE_FOUR;
            }

            
return ResultType.NOTHING;
        }

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

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


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

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

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

相关文章

Google Earth的十个常用技巧应用

2004年10月27日Google宣布收购了美国的一家卫星图像公司Keyhole公司&#xff0c;并于2005年6月推出了Google Earth系列软件。用户们可以通过下载一个Google Earth客户端软件&#xff0c;就可以免费浏览全球各地的高清晰度卫星图片。 Google卫星地图的横空出世&#xff0c;催生了…

[导入]判断学号前十位的年龄最大的女学生是否是汉族的

USE XSCJGOIF object_id(tempdb..#tmpTable) IS NOT NULLDROP TABLE #tmpTableSELECT TOP 10 *INTO #tmpTableFROM 学生基本信息表WHERE 性别 女GODECLARE zbs CHAR(10)SELECT zbs 族别 FROM #tmpTableWHERE 出生日期 (SELECT MIN(出生日期) FROM #tmpTable)IF zbs 汉族PRI…

TCP/IP协议端口大全

TCP/IP协议端口大全 应用层网关服务Internet 连接共享 (ICS)/Internet 连接防火墙 (ICF) 服务的这个子组件对允许网络协议通过防火墙并在 Internet 连接共享后面工作的插件提供支持。应用层网关 (ALG) 插件可以打开端口和更改嵌入在数据包内的数据&#xff08;如端口和 IP 地址…

BENET上海分公司网络改造项目设计实施方案(S1项目实践)

BENET上海分公司网络改造项目设计实施方案 目录 目录- - 1 - 一、企业用户需求分析- - 2 - 1.1、项目概述-- - 2 - 1.2、系统需求概括-- - 3 - 1.3、项目建设的要求-- - 4 - 二、项目方案的整体设计与实施- - 5 - 2.1、网络系统的分析与设计-- - 5 - 2.2、系统及应用服务的分析…

java 的转义字符,在正则表达式中应用

点的转义&#xff1a;. > u002E 美元符号的转义&#xff1a;$ > u0024 乘方符号的转义&#xff1a;^ > u005E 左大括号的转义&#xff1a;{ > u007B 左方括号的转义&#xff1a;[ > u005B 左圆括号的转义&#xff1a;( > u0028 竖线的转义&#xff1a;…

Oracle 统计信息备份/表分析

众所周知,统计信息直接影响到Oracle优化器最后的执行计划,所以定期收集统计信息成为DBA一项常规的工作,但是,对于一些大表,比如数据量超过几千万条,表分析后却有可能会导致应用系统一些SQL执行计划变差,比如出现大量的全表扫,严重影响数据库性能.如果出现这种情况,一种方法是对…

Type mismatch: cannot convert from int to Object错误

第一, 需要装 jre1.5.0及以上的版本第二, 在eclipse的Window Preference Java里,Install JREs里设置你装的jre第三,在eclipse的Window Preference Java里,Compiler里设Compiler compliance level为5.0以上关键是第三步, 兼容级别转载于:https://blog.51cto.com/xu20cn/116852

IIS6.0应用程序池回收和工作进程【转:http://www.cnblogs.com/freshman0216/archive/2008/06/02/1212460.html】...

公司的一个网站程序长时间运行后&#xff0c;速度变慢&#xff0c;重新启动网站后速度明显变快&#xff0c;估计是网站程序占用的内存和CPU资源没能及时释放&#xff0c;才需要每隔一段时间重启网站释放资源。但手工重启总不能算解决问题的方法&#xff0c;怎样才能实现自动管理…

配置IPsec on GRE Tunnel with IOS Firewall and NAT

配置IPsec on GRE Tunnel with IOS Firewall and NAT<?xml:namespace prefix o ns "urn:schemas-microsoft-com:office:office" />详细配置见附件

广播地址详谈!

一、问题的提出大家看到这个标题&#xff0c;一定会觉得非常简单&#xff0c;不错&#xff0c;对于高手们来说&#xff0c;这确实不值一提&#xff0c;但是&#xff0c;对于广大非高手的兄弟&#xff0c;还是有必要了解一下。以前&#xff0c;我对广播地址的认识也是模模糊糊&a…

SearchRequest用于与搜索文档、聚合、定制查询有关的任何操作

SearchRequest用于与搜索文档、聚合、定制查询有关的任何操作&#xff0c;还提供了在查询结果的基于上&#xff0c;对于匹配的关键词进行突出显示的方法。 1&#xff0c;首先创建搜索请求对象&#xff1a;SearchRequest searchRequest new SearchRequest(); 2&#xff0c;对搜…

截网页全屏图的方法-截网页全屏软件-Web2Pic Pro

抓取整个网页的最强工具:Web2Pic Pro http://www.pconline.com.cn/pcedu/tuijian/photo/snap/0507/acc/w2psetup.exe 使用方法你到下面的地址: http://www.pconline.com.cn/pcedu/tuijian/photo/snap/0507/675763.html 在上网过程中我们经常会抓取保存一些网页内容为图像格式…

ES Search API

Search API 搜索请求 SearchRequest用于与搜索文档、聚合、suggestions相关的任何操作&#xff0c;还提供了在结果文档上请求高亮的方法。 在最基本的表单中&#xff0c;我们可以向请求添加查询&#xff1a; SearchRequest searchRequest new SearchRequest(); SearchSourceB…

silverlight 跨域socket

http://msdn.microsoft.com/en-us/library/cc645032(VS.95).aspx一切都是临时的&#xff0c;beta2相对于beta1改了很多&#xff0c;不知道正式发布时是否还会改变。翻译的作用是备忘。Silverlight 2 beta 支持2种访问远程服务器的方式&#xff1a;System.Net命名空间中的WebCli…

OCP-052考试题库汇总(54)-CUUG内部解答版

USER1 grants SELECT and UPDATE privileges on USER1.EMP to USER2。 SYS executes this command&#xff1a; SQL> REVOKE SELECT ON user1.emp FROM user1; What will be the outcome? A)It will succeed and USER2 will be unable to perform SELECT on USER1.EMP B)It…

ES 创建mapping

mapping的写入与查看首先创建一个索引&#xff1a; curl -XPUT "http://erp2.es.kd1.pagoda.com.cn:80/erp_stock_index"{"acknowledged":true} 现在只创建了一个索引&#xff0c;并没有设置mapping&#xff0c;查看一下索引mapping的内容&#xff1a; cur…

关于C语言野指针的问题

typedef struct{int id;char username [6];} user;int main(void){user *userr;strncpy(userr->username, "hello", 3);strcat(userr->username, ""0");printf("userr->username%s."n", userr->username);return 0;} 便已…

简单 屏蔽 assert

简介 屏蔽 assert 如何实现 Makefile 中加 CFLAGS -DNDEBUG 或者 gcc -DNDEBUG 转载于:https://www.cnblogs.com/eat-too-much/p/11512524.html

多核分布式队列的实现:“偷”与“自私”的运用(1)

多核分布式队列的实现&#xff1a;"偷"与"自私"的运用 在讨论本文的正题前&#xff0c;不得不先说一些闲话&#xff0c;嫌哆嗦者可以跳过"前言"部分不读。1. 前言在发表了"老子是伟大的多核计算科学家" &#xff08;链接&#xff1a;[…

近期刷题记录表

9月14日&#xff1a;   luogu P1627 [CQOI2009]中位数 题意&#xff1a;给出1~n的一个排列&#xff0c;统计该排列有多少个长度为奇数的连续子序列的中位数是b。中位数是指把所有元素从小到大排列后&#xff0c;位于中间的数。 题解&#xff1a;根据中位数的性质&#xff0c…