- //文件名 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;
- }
- }
復制代碼
|