001    package test;
002    import core.*;
003    import rules.*;
004    import ai.AIFactory;
005    
006    public class AIFight {
007        private AIFactory aiFactory;
008        private GameState game;
009        private Player white;
010        private Player black;
011    
012        public static void main(String[] args){
013            int[] w = new int[8];
014            for(int i = 0; i < 8; i++)
015                w[i] = Integer.parseInt(args[i]);
016            AIFight aiFight = new AIFight(w);
017            aiFight.runGame();
018        }
019    
020        public AIFight(int[] w){
021            aiFactory = new AIFactory();
022            game = new GameState();
023            white = aiFactory.createPlayer(true, 0, 0, null, w[0], w[1], w[2], w[3]);
024            black = aiFactory.createPlayer(false, 0, 0, null, w[4], w[5], w[6], w[7]);
025        }
026        public void runGame(){
027            Move lastMove = new Move();
028            int moveNum = 0;
029            long whiteTime = 60000 * 5;
030            long blackTime = 60000 * 5;
031            long startTime;
032            Color winner = Color.NONE;
033            while(true) {
034                moveNum += 1;
035                System.out.println("Move "  + moveNum);
036                startTime = System.currentTimeMillis();
037                lastMove = white.askForMove(lastMove, whiteTime, blackTime);
038                whiteTime -= System.currentTimeMillis() - startTime;
039                game.makeMove(lastMove);
040                if (game.getWinner() != Color.NONE){
041                    winner = game.getWinner();
042                } else if (whiteTime <= 100)
043                    winner = Color.BLACK;
044                if (winner != Color.NONE) {
045                    System.out.println("WINNER: " + winner);
046                    break;
047                }
048                startTime = System.currentTimeMillis();
049                lastMove = black.askForMove(lastMove, blackTime, whiteTime);
050                blackTime -= System.currentTimeMillis() - startTime;
051                game.makeMove(lastMove);
052                if (game.getWinner() != Color.NONE){
053                    winner = game.getWinner();
054                } else  if (blackTime <= 100) {
055                    winner = Color.WHITE;
056                }
057                if (winner != Color.NONE) {
058                    System.out.println("WINNER: " + winner);
059                    break;
060                }
061                if (moveNum > 150) { //Draw
062                    System.out.println("DRAW");
063                    break;
064                }
065            }
066        }
067    }