- //文件名 xq_main.java
- import xq.*;
- //声明一个类
- public class xq_main {
- //声明一个方法
- public static void main(String[] args){
- //程序的入口
- //初始化一个棋盘
- int qipan[][]=new int[][]{{2,3,6,5,1,5,6,3,2},{0,0,0,0,0,0,0,0,0},{0,4,0,0,0,0,0,4,0},{7,0,7,0,7,0,7,0,7},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{14,0,14,0,14,0,14,0,14},{0,11,0,0,0,0,0,11,0},{0,0,0,0,0,0,0,0,0},{9,10,13,12,8,12,13,10,9}};
- int x,y;
- for(y=0;y<=9;y++)
- {
- for(x=0;x<=8;x++)
- {
- switch (qipan[y][x]){
- case 0:
- System.out.print(" ");//空格
- break;
- case 1:
- System.out.print("黑帅 ");//黑帅
- break;
- case 2:
- System.out.print("黑车 ");//黑车
- break;
- case 3:
- System.out.print("黑马 ");//黑马
- break;
- case 4:
- System.out.print("黑炮 ");//黑炮
- break;
- case 5:
- System.out.print("黑士 ");//黑士
- break;
- case 6:
- System.out.print("黑象 ");//黑象
- break;
- case 7:
- System.out.print("黑兵 ");//黑兵
- break;
- case 8:
- System.out.print("红将 ");//红将
- break;
- case 9:
- System.out.print("红车 ");//红车
- break;
- case 10:
- System.out.print("红马 ");//红马
- break;
- case 11:
- System.out.print("红砲 ");//红砲
- break;
- case 12:
- System.out.print("红仕 ");//红仕
- break;
- case 13:
- System.out.print("红相 ");//红相
- break;
- case 14:
- System.out.print("红卒 ");//红卒
- break;
- }
- }
- if(y==4) System.out.print("\n\n\n");else System.out.print("\n\n");
- }
- GuiZe AI=new GuiZe();
- //调试AI棋步生成情况
- for(int z=0;z<30;z++)
- {
- ChessMove qibu=AI.searchAGoodMove(qipan);
- System.out.print("AI生成一个当前最佳棋步:\n");//空格
- switch (qibu.ChessID){
- case 0:
- System.out.print(" ");//空格
- break;
- case 1:
- System.out.print("黑帅 ");//黑帅
- break;
- case 2:
- System.out.print("黑车 ");//黑车
- break;
- case 3:
- System.out.print("黑马 ");//黑马
- break;
- case 4:
- System.out.print("黑炮 ");//黑炮
- break;
- case 5:
- System.out.print("黑士 ");//黑士
- break;
- case 6:
- System.out.print("黑象 ");//黑象
- break;
- case 7:
- System.out.print("黑兵 ");//黑兵
- break;
- case 8:
- System.out.print("红将 ");//红将
- break;
- case 9:
- System.out.print("红车 ");//红车
- break;
- case 10:
- System.out.print("红马 ");//红马
- break;
- case 11:
- System.out.print("红砲 ");//红砲
- break;
- case 12:
- System.out.print("红仕 ");//红仕
- break;
- case 13:
- System.out.print("红相 ");//红相
- break;
- case 14:
- System.out.print("红卒 ");//红卒
- break;
- }
- System.out.print("现在位置:Y "+qibu.fromY+" X "+qibu.fromX+" 移动到:Y "+qibu.toY+" X "+qibu.toX+"\n");
- }
-
-
- }
- }
- AI主模块会用到这个类要放到同一个包里
- package xq;
- /**
- * 该类为棋子的一个走法
- * 包含是什么棋子
- * 起始点的位置
- * 目标点的位置
- * 以及估值时所用到的score
- */
- public class ChessMove {
- public int ChessID;//表明是什么棋子
- public int fromX;//起始的坐标
- public int fromY;
- public int toX;//目的地的坐标
- public int toY;
- public int score;//值,估值时会用到
- public ChessMove(int ChessID, int fromX,int fromY,int toX,int toY,int score){//构造器
- this.ChessID = ChessID;//棋子的类型
- this.toY = toY;//棋子的目标点y坐标
- this.fromX = fromX;//棋子的起始坐标
- this.fromY = fromY;
- this.toX = toX;//棋子的目标点x坐标
- this.score = score;
- }
- }
复制代码
|