大道五目Flash英文版(Renju Problems)程序分析之禁手判断
生活随笔
收集整理的這篇文章主要介紹了
大道五目Flash英文版(Renju Problems)程序分析之禁手判断
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
現在界面已經完成了,
?
剛剛完成了禁手算法,把代碼共享出來:
Codeprivate?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);
????????????
????????????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;
????????????for(i=0;?i<4;?i++)?{
????????????????
????????????????//?calculate?open?4's?count.
????????????????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&&
????????????????????????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&&
????????????????????????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&&
????????????????????????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&&?
????????????????????????array[i][j+3]==CellType.BLACK&&array[i][j+4]==CellType.BLACK)?{
????????????????????????if(this.IsEmpty(i,j,array)&&this.IsNotBlack(i,j-1,array)&&this.IsNotBlack(i,j+5,array))?{
????????????????????????????count4++;
????????????????????????????continue;
????????????????????????}
????????????????????????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
????????????????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)&&
????????????????????????(this.IsNotBlack(i,j-2,array)||this.IsNotBlack(i,j+5,array)))?{
????????????????????????tmpIndex?=?this.IndexConverter(i,j+1,x,y);
????????????????????????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)&&
????????????????????????(this.IsNotBlack(i,j-2,array)||this.IsNotBlack(i,j+5,array)))?{
????????????????????????tmpIndex?=?this.IndexConverter(i,j+2,x,y);
????????????????????????if(this.IsForbidden(Math.floor(tmpIndex/15),tmpIndex%15,board)==ResultType.NOTHING)?{????
????????????????????????????count3++;
????????????????????????}
????????????????????????continue;
????????????????????}
????????????????????//?patten:???000??
????????????????????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)&&
????????????????????????????this.IsEmpty(i,j+3,array)&&this.IsNotBlack(i,j-3,array))?{
????????????????????????????tmpIndex?=?this.IndexConverter(i,j-1,x,y);
????????????????????????????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)&&
????????????????????????????this.IsEmpty(i,j+4,array)&&this.IsNotBlack(i,j+5,array))?{
????????????????????????????tmpIndex?=?this.IndexConverter(i,j+3,x,y);
????????????????????????????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;
????????????if(count3>1)?{
????????????????return?ResultType.DOUBLE_THREE;
????????????}
????????????if(count4>1)?{
????????????????return?ResultType.DOUBLE_FOUR;
????????????}
????????????return?ResultType.NOTHING;
????????}
就是通過一個遞歸判斷是否當前下子為禁手。
測試后發現可以判斷復雜的禁手,如:
轉載于:https://www.cnblogs.com/boringlamb/archive/2008/11/04/1326291.html
總結
以上是生活随笔為你收集整理的大道五目Flash英文版(Renju Problems)程序分析之禁手判断的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Silverlight 解谜游戏 之十六
- 下一篇: 安装Ubuntu之后一定要安装Docky