コード例 #1
0
ファイル: AI.cs プロジェクト: TheBosZ/Endless-Waffle
        public static int negaMax(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;
            foreach (Move m in moves) {
                if (DateTime.Now - start > tleft)
                    break;
                if (board.makeMove(m)) {
                    result = AI.negaMax(board, depth - 1,  -best, -a0, (tleft - ( DateTime.Now - start)).TotalSeconds);
                    v = Math.Max(v, -result);
                    board.undoLastMove();
                    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;
        }
コード例 #2
0
ファイル: TTable.cs プロジェクト: TheBosZ/Endless-Waffle
 public void store(TTableEntry entry)
 {
     if (IsReady)
         Entries[entry.Hash] = entry;
 }