示例#1
0
        static double _ScoreToplevelMove(EvalState state, UInt64 board, int move)
        {
            UInt64 newboard = ExecuteMove(move, board);

            if (board == newboard)
            {
                return(0);
            }

            return(ScoreTilechooseNode(state, newboard, 1.0f) + 1e-6);
        }
示例#2
0
        static double ScoreTilechooseNode(EvalState state, UInt64 board, float cprob)
        {
            if (cprob < CPROB_THRESH_BASE || state.curdepth >= state.depthLimit)
            {
                state.maxdepth = Math.Max(state.curdepth, state.maxdepth);
                return(ScoreHeurBoard(board));
            }

            if (state.curdepth < CACHE_DEPTH_LIMIT)
            {
                if (state.transTable.ContainsKey(board))
                {
                    state.cachehits++;
                    return(state.transTable[board]);
                }
            }

            int num_open = CountEmpty(board);

            cprob /= num_open;

            double res    = 0.0f;
            UInt64 tmp    = board;
            UInt64 tile_2 = 1;

            while (tile_2 != 0)
            {
                if ((tmp & 0xf) == 0)
                {
                    res += ScoreMoveNode(state, board | tile_2, cprob * 0.9f) * 0.9f;
                    res += ScoreMoveNode(state, board | (tile_2 << 1), cprob * 0.1f) * 0.1f;
                }
                tmp    >>= 4;
                tile_2 <<= 4;
            }
            res = res / num_open;

            if (state.curdepth < CACHE_DEPTH_LIMIT)
            {
                state.transTable[board] = res;
            }

            return(res);
        }
示例#3
0
        static double ScoreMoveNode(EvalState state, UInt64 board, float cprob)
        {
            double best = 0.0f;

            state.curdepth++;
            for (int move = 0; move < 4; ++move)
            {
                UInt64 newboard = ExecuteMove(move, board);
                state.moves_evaled++;

                if (board != newboard)
                {
                    best = Math.Max(best, ScoreTilechooseNode(state, newboard, cprob));
                }
            }
            state.curdepth--;

            return(best);
        }
示例#4
0
        static double ScoreToplevelMove(UInt64 board, int move)
        {
            double   res;
            DateTime start, finish;

            double    elapsed;
            EvalState state = new EvalState();

            state.transTable = new Dictionary <ulong, double>();
            state.depthLimit = Math.Max(3, count_distinct_tiles(board) - 2);

            start  = DateTime.Now;
            res    = _ScoreToplevelMove(state, board, move);
            finish = DateTime.Now;

            elapsed  = (finish.Second - start.Second);
            elapsed += (finish.Millisecond - start.Millisecond) / 1000000.0;

            Console.WriteLine("Move " + move.ToString() + ": result " + res.ToString() + ": eval'd " + state.moves_evaled.ToString() + " moves ( " + state.cachehits.ToString() + "cache hits, " + state.transTable.Count.ToString() + " cache size) in " + elapsed.ToString() + " seconds (maxdepth=" + state.maxdepth.ToString() + ")");

            return(res);
        }
示例#5
0
        static double ScoreToplevelMove(UInt64 board, int move) {
            double res;
            DateTime start, finish;
            
            double elapsed;
            EvalState state = new EvalState();
            state.transTable = new Dictionary<ulong, double>();
            state.depthLimit = Math.Max(3, count_distinct_tiles(board) - 2);

            start = DateTime.Now;
            res = _ScoreToplevelMove(state, board, move);
            finish = DateTime.Now;

            elapsed = (finish.Second - start.Second);
            elapsed += (finish.Millisecond - start.Millisecond) / 1000000.0;

            Console.WriteLine("Move " + move.ToString() + ": result " + res.ToString() + ": eval'd " + state.moves_evaled.ToString() + " moves ( " + state.cachehits.ToString() + "cache hits, " + state.transTable.Count.ToString() + " cache size) in " + elapsed.ToString() + " seconds (maxdepth=" + state.maxdepth.ToString() + ")");

            return res;
        }
示例#6
0
        static double _ScoreToplevelMove(EvalState state, UInt64 board, int move) {
            UInt64 newboard = ExecuteMove(move, board);

            if(board == newboard)
                return 0;

            return ScoreTilechooseNode(state, newboard, 1.0f) + 1e-6;
        }
示例#7
0
        static double ScoreTilechooseNode(EvalState state, UInt64 board, float cprob) {
            if (cprob < CPROB_THRESH_BASE || state.curdepth >= state.depthLimit) {
                state.maxdepth = Math.Max(state.curdepth, state.maxdepth);
                return ScoreHeurBoard(board);
            }

            if (state.curdepth < CACHE_DEPTH_LIMIT) {
                if (state.transTable.ContainsKey(board)) {
                    state.cachehits++;
                    return state.transTable[board];
                }
            }

            int num_open = CountEmpty(board);
            cprob /= num_open;

            double res = 0.0f;
            UInt64 tmp = board;
            UInt64 tile_2 = 1;
            while (tile_2 != 0) {
                if ((tmp & 0xf) == 0) {
                    res += ScoreMoveNode(state, board |  tile_2      , cprob * 0.9f) * 0.9f;
                    res += ScoreMoveNode(state, board | (tile_2 << 1), cprob * 0.1f) * 0.1f;
                }
                tmp >>= 4;
                tile_2 <<= 4;
            }
            res = res / num_open;

            if (state.curdepth < CACHE_DEPTH_LIMIT) {
                state.transTable[board] = res;
            }

            return res;
        }
示例#8
0
        static double ScoreMoveNode(EvalState state, UInt64 board, float cprob) {
            double best = 0.0f;
            state.curdepth++;
            for (int move = 0; move < 4; ++move) {
                UInt64 newboard = ExecuteMove(move, board);
                state.moves_evaled++;

                if (board != newboard) {
                    best = Math.Max(best, ScoreTilechooseNode(state, newboard, cprob));
                }
            }
            state.curdepth--;

            return best;
        }