Пример #1
0
 public Board(Board b)
 {
     this.board = (Piece[,])b.board.Clone();
     this.State = b.State;
     this.CurrentColor = b.CurrentColor;
     this.CurrentTurn = b.CurrentTurn;
     lastMoves = new Stack<PreviousMove>();
 }
Пример #2
0
        public static int negaMaxNodoUndo(Board board, int depth, int awful, int best, double sec)
        {
            //If the board has ended or the depth has been reached, return value
            if (board.State != Board.BoardState.Playing || 0 <= depth || sec <= 0) {
                return board.evaluateCurrentBoard();
            }
            int result = 0;
            TTableEntry t = table.getByHash(board.Hash);
            if (t != null) {
                if (((t.A < t.Value && t.Value < t.B) || (t.A <= awful && best <= t.B)) && t.Depth >= depth)
                    return t.Value;
            }
            TimeSpan tleft = TimeSpan.FromSeconds(sec);
            List<Move> moves = board.getMoves(board.CurrentColor);
            int a0 = awful;
            int v = -100000;
            DateTime start = DateTime.Now;
            Board tmpBoard;
            foreach (Move m in moves) {
                if (DateTime.Now - start > tleft)
                    break;
                tmpBoard = new Board(board);
                if (tmpBoard.makeMove(m)) {
                    result = AI.negaMaxNodoUndo(tmpBoard, depth - 1, -best, -a0, (tleft - (DateTime.Now - start)).TotalSeconds);
                    v = Math.Max(v, -result);
                    a0 = Math.Max(a0, v);
                    if (v >= best) {
                        best = v;
                        break;
                    }
                }

            }
            TTableEntry tt = new TTableEntry(board.Hash, awful, best, v, depth);
            table.store(tt);
            return v;
        }
Пример #3
0
 public object Clone()
 {
     Board b = new Board(this);
     return b;
 }
Пример #4
0
        static void Main(string[] args)
        {
            if (args.Length > 0) {
                foreach (string arg in args) {
                    if (arg.Contains("-c:")) {
                        switch (arg.Replace("-c:", "")) {
                            case "B":
                                player = Mode.AIBlack;
                                break;
                            case "A":
                                player = Mode.AIBoth;
                                break;
                            case "N":
                                player = Mode.AINone;
                                break;
                            case "W":
                            default:
                                player = Mode.AIWhite;
                                break;
                        }
                    }
                    if (arg.Contains("-i")) {
                        outputICMS = true;
                    }
                    if (arg.Contains("-t:")) {
                        int usrtime;
                        if (int.TryParse(arg.Replace("-t:", ""), out usrtime))
                            moveTime = usrtime;
                    }
                    if (arg.Contains("-s"))
                        showBoard = true;
                    if (arg.Contains("-b"))
                        stepOutput = true;
                }
            }
            Board board = new Board();
            board.resetBoard();
            Random rand = new Random();
            Move m = null;
            Boolean t = false;
            while (board.State == Board.BoardState.Playing) {
                if (showBoard) {
                    board.printToStdOut();
                    Console.WriteLine();
                }
                if (player == Mode.AIBoth || (player == Mode.AIBlack && board.CurrentColor == Piece.Color.Black) || (player == Mode.AIWhite && board.CurrentColor == Piece.Color.White)) {
                    while (!t) {
                        m = board.findBestMoveForCurrentPlayer(moveTime);
                        t = board.makeMove(m);
                    }
                    t = false;
                    if (outputICMS) {
                        Console.WriteLine("Giving my move to skirmish");
                        Console.Write("! ");
                    }
                    Console.WriteLine(m);
                }
                else {
                    while (!t) {
                        if (outputICMS)
                            Console.WriteLine("Getting move from skirmish");
                        else
                            Console.WriteLine("Please enter your move");
                        string play = Console.ReadLine();
                        if (string.IsNullOrEmpty(play))
                            continue;
                        play = play.Replace("!", "");
                        play = play.Trim();
                        m = new Move(play);
                        t = board.makeMove(m);
                    }
                    t = false;
                }
                if (stepOutput && !outputICMS)
                    Console.ReadLine();
            }

            if (outputICMS)
                Console.Write("= ");
            Console.WriteLine(Board.getStateString(board.State));
            AI.saveTTable();
            Board.saveCache();
            if(stepOutput && !outputICMS)
                Console.ReadLine();
        }