| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 579 人关注过本帖
标题:帮忙。。。黑白棋食棋
只看楼主 加入收藏
Gfung
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2009-11-18
收藏
 问题点数:0 回复次数:1 
帮忙。。。黑白棋食棋
程序代码:
import java.util.Scanner;
public class Blackwhite{
    public static void main(String args[]){

     int x,y;
     //int xy;   
     int board[][]=new int[8][8];
     int col=8;
     int black=1,white=2;
     board[3][3]=black;
     board[4][4]=black;
     board[3][4]=white;
     board[4][3]=white;//中心的4棋
      
     board[0][0]=col;
     board[0][1]=col;
     board[0][2]=col;
     board[0][3]=col;
     board[0][4]=col;
     board[0][5]=col;    
     board[0][6]=col;
     board[0][7]=col;
     board[1][0]=col;
     board[2][0]=col;
     board[3][0]=col;
     board[4][0]=col;
     board[5][0]=col;
     board[6][0]=col;
     board[7][0]=col;
     board[7][1]=col;
     board[7][2]=col;
     board[7][3]=col;
     board[7][4]=col;
     board[7][5]=col;
     board[7][6]=col;
     board[7][7]=col;
     board[1][7]=col;
     board[2][7]=col;
     board[3][7]=col;
     board[4][7]=col;
     board[5][7]=col;
     board[6][7]=col;//外栏
    

          for ( int i = 0; i <board.length; i++ ) {
                   System.out.print(i+" :");

                  for ( int j = 0; j <board.length; j++ ) {
                      System.out.print(" "+board[i][j]  );
                  }
                  System.out.print("\n");
              }
System.out.print("    0 1 2 3 4 5 6 7 "+"\n");//棋盘



do{
    do{
System.out.print("black Enter : ");
Scanner scanner = new Scanner(System.in);
y = scanner.nextInt();
x = scanner.nextInt();
if(x>7||y>7||board[y][x]!=0||board[x+1][y]==0&&board[x-1][y]==0&&board[x][y-1]==0&&board[x][y+1]==0
    &&board[x+1][y+1]==0&&board[x+1][y-1]==0&&board[x-1][y-1]==0&&board[x-1][y+1]==0||board[x+1][y]!=white          
     &&board[x-1][y]!=white&&board[x][y-1]!=white&&board[x][y+1]!=white&&board[x+1][y+1]!=white&&board[x+1][y-1]!=white    
     &&board[x-1][y-1]!=white&&board[x-1][y+1]!=white){System.out.println("error");}
                                                         

      }while(y>6||x>6||board[y][x]!=0||
      
                 board[x+1][y]==0
               &&board[x-1][y]==0
               &&board[x][y-1]==0
               &&board[x][y+1]==0
               &&board[x+1][y+1]==0
               &&board[x+1][y-1]==0
                  &&board[x-1][y-1]==0
               &&board[x-1][y+1]==0||
                 board[x+1][y]!=white
               &&board[x-1][y]!=white
               &&board[x][y-1]!=white
               &&board[x][y+1]!=white
               &&board[x+1][y+1]!=white
               &&board[x+1][y-1]!=white
                  &&board[x-1][y-1]!=white
               &&board[x-1][y+1]!=white);//要重新入棋的规则
      


 board[y][x]=black;

       for ( int i = 0; i <board.length; i++ ) {
                   System.out.print(i+" :");

                  for ( int j = 0; j <board.length; j++ ) {
                      System.out.print(" "+board[i][j]  );
                  }
                  System.out.print("\n");
              }
System.out.print("    0 1 2 3 4 5"+"\n");//黑子的输入



    do{
System.out.print("white Enter : ");
Scanner scanner = new Scanner(System.in);
y = scanner.nextInt();
x = scanner.nextInt();
if(y>7||x>7||board[x][y]!=0||board[x+1][y]==0&&board[x-1][y]==0&&board[x][y-1]==0&&board[x][y+1]==0
    &&board[x+1][y+1]==0&&board[x+1][y-1]==0&&board[x-1][y-1]==0&&board[x-1][y+1]==0||board[x+1][y]!=white          
     &&board[x-1][y]!=white&&board[x][y-1]!=white&&board[x][y+1]!=white&&board[x+1][y+1]!=white&&board[x+1][y-1]!=white    
     &&board[x-1][y-1]!=white&&board[x-1][y+1]!=white){System.out.println("error");}
                                                         

      }while(x>6||y>6||board[y][x]!=0||
      
                 board[x+1][y]==0
               &&board[x-1][y]==0
               &&board[x][y-1]==0
               &&board[x][y+1]==0
               &&board[x+1][y+1]==0
               &&board[x+1][y-1]==0
                  &&board[x-1][y-1]==0
               &&board[x-1][y+1]==0||
                 board[x+1][y]!=black
               &&board[x-1][y]!=black
               &&board[x][y-1]!=black
               &&board[x][y+1]!=black
               &&board[x+1][y+1]!=black
               &&board[x+1][y-1]!=black
                  &&board[x-1][y-1]!=black
               &&board[x-1][y+1]!=black);//要重新入棋的规则
      


 board[y][x]=white;

       for ( int i = 0; i <board.length; i++ ) {
                   System.out.print(i+" :");

                  for ( int j = 0; j <board.length; j++ ) {
                      System.out.print(" "+board[i][j]  );
                  }
                  System.out.print("\n");
              }
System.out.print("    0 1 2 3 4 5"+"\n");//白子的输入

  

}while(board[y][x]!=0);//如果有空位


}
}

小弟在做一个没有GUI的黑白棋
现在卡在食棋的部分
有没有人能帮帮忙吗


[ 本帖最后由 Gfung 于 2009-12-2 15:48 编辑 ]
搜索更多相关主题的帖子: 黑白棋 
2009-12-02 15:34
观星
Rank: 2
等 级:论坛游民
帖 子:77
专家分:45
注 册:2008-5-1
收藏
得分:0 
问题说清楚些~~ 什么样的问题啊?是做不出食棋么? 你可以像八个方向遍历,看看能符合条件的就把子吃掉~~
2010-03-02 11:38
快速回复:帮忙。。。黑白棋食棋
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021380 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved