示例#1
0
        protected void MisaMinoAOT(int current, int[] q, int?hold, int combo, int garbage, int spawn_pos)
        {
            if (MisaMino.Running)
            {
                MisaMino.Abort();
            }

            misasolved = false;

            if (!Danger())
            {
                MisaMino.FindMove(
                    q,
                    current,
                    hold,
                    misa_lasty = spawn_pos,
                    misaboard,
                    combo,
                    Math.Max(
                        b2b,
                        Convert.ToInt32(FuckItJustDoB2B(misaboard, 25))
                        ),
                    garbage
                    );
            }
        }
示例#2
0
        protected void NewGame(Action setup, int baseBoardHeight)
        {
            MisaMino.Reset(); // this will abort as well
            misasolved = false;
            b2b        = 1;   // Hack that makes MisaMino start like a normal person

            PerfectClear.Abort();
            pcsolved       = false;
            futurepcsolved = false;
            pcbuffer       = false;
            cachedpc       = new List <Operation>();
            searchbufpc    = false;

            setup?.Invoke();

            misaboard = (int[, ])board.Clone();
            pcboard   = (int[, ])board.Clone();

            int[] q = getClippedQueue();
            LogHelper.LogText("QUEUE FOR START: " + string.Join(" ", q));

            if (!Danger())
            {
                MisaMino.FindMove(q, current, null, misa_lasty = baseBoardHeight, misaboard, 0, b2b, 0);

                if (getPerfectClear())
                {
                    PerfectClear.Find(
                        pcboard, q, current,
                        null, HoldAllowed(), 6, GarbageBlocking(), getPerfectType(), 0, false
                        );
                }
            }
        }
示例#3
0
        protected bool MakeDecision(out bool wasHold, out int clear, out List <int[]> coords)
        {
            wasHold = false;
            clear   = 0;
            coords  = null;

            bool pathSuccess = false;

            movements = new List <Instruction>();
            pieceUsed = finalX = finalY = finalR = -10;
            atk       = 0;

            if (MisaMino.Running)
            {
                MisaMino.Abort();
            }
            if (PerfectClear.Running && !pcbuffer)
            {
                PerfectClear.Abort();
            }

            if (Danger())
            {
                return(false);
            }

            if (getPerfectClear() && pcsolved && BoardEquals(board, pcboard))
            {
                LogHelper.LogText("Detected PC");

                pieceUsed = executingpc[0].Piece;
                finalX    = executingpc[0].X;
                finalY    = executingpc[0].Y + baseBoardHeight - 21; // if baseboardheight happens to be 22, need to +1 this
                finalR    = executingpc[0].R;

                movements = MisaMino.FindPath(
                    board,
                    baseBoardHeight,
                    pieceUsed,
                    finalX,
                    finalY,
                    finalR,
                    current != pieceUsed,
                    out spinUsed,
                    out pathSuccess
                    );

                if (!pathSuccess)
                {
                    LogHelper.LogText($"PC PATHFINDER FAILED! piece={pieceUsed}, x={finalX}, y={finalY}, r={finalR}");
                }
            }

            if (!pathSuccess)
            {
                LogHelper.LogText("Using Misa!");

                bool equals     = BoardEquals(misaboard, board);
                bool equivalent = BoardEquivalent(misaboard, board, out int diff);

                int tempY = MisaMino.LastSolution.FinalY;

                if (!equals && equivalent)
                {
                    LogHelper.LogText("GARBAGE FIX ATTEMPT");
                    tempY -= diff;
                }

                bool misaok    = equivalent && misasolved;
                bool misasaved = false;

                if (misaok && (misa_lasty != baseBoardHeight || (!equals && equivalent)))   // oops wrong y pos
                {
                    LogHelper.LogText($"Tryna save Misa... lasty={misa_lasty} baseH={baseBoardHeight} finalY={MisaMino.LastSolution.FinalY} tempY={tempY}");

                    movements = MisaMino.FindPath(
                        board,
                        baseBoardHeight,
                        MisaMino.LastSolution.PieceUsed,
                        MisaMino.LastSolution.FinalX,
                        tempY,
                        MisaMino.LastSolution.FinalR,
                        current != MisaMino.LastSolution.PieceUsed,
                        out spinUsed,
                        out misaok
                        );

                    misasaved = misaok;

                    LogHelper.LogText($"misasaved {misasaved}");
                }

                if (!misaok)
                {
                    LogHelper.LogText("Rush (SOMETHING JUST WENT REALLY WRONG)");
                    LogHelper.LogBoard(misaboard, board);

                    int[] q = getClippedQueue();

                    LogHelper.LogText("QUEUE FOR RUSH: " + string.Join(" ", q));

                    MisaMino.FindMove(
                        q,
                        current,
                        hold,
                        baseBoardHeight,
                        board,
                        combo,
                        Math.Max(
                            b2b, // ideally this should be read from game mem right before calling
                            Convert.ToInt32(FuckItJustDoB2B(board, 25))
                            ),
                        garbage
                        );

                    Stopwatch misasearching = new Stopwatch();
                    misasearching.Start();

                    while (misasearching.ElapsedMilliseconds < RushTime())
                    {
                    }

                    MisaMino.Abort();
                }

                if (!misasaved)
                {
                    movements = MisaMino.LastSolution.Instructions;
                }
                pieceUsed = MisaMino.LastSolution.PieceUsed;
                if (!misasaved)
                {
                    spinUsed = MisaMino.LastSolution.SpinUsed;
                }
                b2b    = MisaMino.LastSolution.B2B;
                atk    = MisaMino.LastSolution.Attack;
                finalX = MisaMino.LastSolution.FinalX;
                finalY = tempY;
                finalR = MisaMino.LastSolution.FinalR;

                Window?.SetConfidence($"{MisaMino.LastSolution.Nodes} ({MisaMino.LastSolution.Depth})");
                Window?.SetThinkingTime(MisaMino.LastSolution.Time);

                pcsolved       = false;
                futurepcsolved = false;
                pcbuffer       = false;
                searchbufpc    = false;
            }
            else
            {
                LogHelper.LogText("Using PC!");

                cachedpc = executingpc.Skip(1).ToList();

                bool prev = pcbuffer;
                pcbuffer = cachedpc.Count != 0;

                searchbufpc |= !prev && pcbuffer;

                if (!pcbuffer)
                {
                    pcsolved    = futurepcsolved;
                    searchbufpc = futurepcsolved = false;
                }

                Window?.SetConfidence($"[PC] {cachedpc.Count + 1}");
                Window?.SetThinkingTime(PerfectClear.LastTime);
            }

            misasolved = false;

            wasHold = movements.Count > 0 && movements[0] == Instruction.HOLD;

            bool applied = ApplyPiece(board, pieceUsed, finalX, finalY, finalR, baseBoardHeight, out clear, out coords);

            LogHelper.LogText($"Piece applied? {applied}");

            misaboard = (int[, ])board.Clone();
            pcboard   = (int[, ])board.Clone();

            if (pathSuccess && !pcsolved)  // pathSuccess here means that I had used PC finder to make the decision
            {
                b2b = Convert.ToInt32(isPCB2BEnding(clear, pieceUsed, finalR));
            }

            // Filter L->R and R->L
            if (movements.Count >= 2)
            {
                for (int i = movements.Count - 2; i >= 0; i--)
                {
                    if ((movements[i] == Instruction.L && movements[i + 1] == Instruction.R) || (movements[i] == Instruction.R && movements[i + 1] == Instruction.L))
                    {
                        movements.RemoveAt(i);
                        movements.RemoveAt(i);
                        i--;
                    }
                }
            }

            LogHelper.LogText($"Movements generated for piece {pieceUsed} ({finalX}, {finalY}, {finalR}) => {string.Join(", ", movements)}");

            return(applied);
        }