Ejemplo n.º 1
0
    public Sequence CreateTrans(MoveContext blockMove)
    {
        if (blockMove == null)
        {
            Debug.LogError("Must not be null");
        }

        Sequence ret = new Sequence(ExportMatrix());
        ret.DoTrans(blockMove);
        return ret;
    }
Ejemplo n.º 2
0
    void DoTrans(MoveContext moveContext)
    {
        if (moveContext == null)
        {
            return;
        }

        if (Mathf.Abs(moveContext.offsetX) > 0)
        {
            int count = moveContext.offsetX;
            while (count < 0)
            {
                count += blocks.width;
            }
            count %= blocks.width;
            int y = moveContext.selectY;
            for (int i = 0; i < count; i++)
            {
                RotateOnceH(y);
            }
        }
        else if (Mathf.Abs(moveContext.offsetY) > 0)
        {
            int count = moveContext.offsetY;
            while (count < 0)
            {
                count += blocks.height;
            }
            count %= blocks.height;
            int x = moveContext.selectX;
            for (int i = 0; i < count; i++)
            {
                RotateOnceV(x);
            }
        }
    }
Ejemplo n.º 3
0
 public void StopMove()
 {
     cursor = null;
     lastMove = null;
 }
Ejemplo n.º 4
0
    public void Update(float deltaTime)
    {
        if (deltaTime == 0)
        {
            return;
        }

        if (cursor != null)
        {
            cursor.Update();

            if (lastMove != cursor.move)
            {
                lastMove = cursor.move;

                if (cursor.move == null)
                {
                    fsm.Event("invalidMoved");
                }
                else
                {
                    fsm.Event("cursorMoved");
                }
            }
        }

        if (IsClicked())
        {
            if (InputTool.GetMouseButtonUp(0))
            {
                fsm.Event("IsMouseReleased");
            }
        }
        else
        {
            if (InputTool.GetMouseButtonDown(0) && ContainsPos(InputTool.mousePosition))
            {
                fsm.Event("IsMouseClicked");
            }

            // cheat
            InEditor.Do(delegate()
            {
                if (InputTool.GetMouseButtonDown(1) && ContainsPos(InputTool.mousePosition))
                {
                    Vector2 pos = InputTool.mousePosition;
                    Coord selectCoord = layout.FindCellContains(pos);
                    if (selectCoord != null)
                    {
                        //sequence.blocks.Get(selectCoord.x, selectCoord.y).ChangeTo(BlockType.WildCard);
                    }
                }
            });
        }

        float aniFrame = GetAniFrame(TimeTool.time);
        if (0f <= aniFrame && aniFrame <= 1f)
        {
            DrawFill(aniFrame);
        }
        else if (cursor != null)
        {
            selectPosX = cursor.selectPosX;
            selectPosY = cursor.selectPosY;
            cursorOffset = cursor.Offset;
            ApplyCursor(selectPosX, selectPosY, cursorOffset);
        }
        else if (cursorOffset.magnitude > 0.1f)
        {
            cursorOffset /= 2f;
            ApplyCursor(selectPosX, selectPosY, cursorOffset);
        }
        else
        {
            ResetPos();
        }

        fsm.Update(deltaTime);


        if (matchingResult != null)
        {
            foreach (var matching in matchingResult)
            {
                matching.Update(deltaTime);
            }
        }
    }
Ejemplo n.º 5
0
    private static void DrawCursor(MoveContext move)
    {
        Vector2 pos = InputTool.mousePosition;
        int size = 10;
        Rect touchRect = new Rect(pos.x - size / 2, pos.y - size / 2, size, size);
        Color color = new Color(1f, 0.4f, 0.4f, 0.7f);
        GUITool.DrawRect(touchRect, color);

        if (move != null)
        {
            Rect labelRect = new Rect(touchRect.x + touchRect.width, touchRect.y, 30, 30);
            string text = string.Format("{0},{1}\n{2},{3}", move.selectX, move.selectY, move.offsetX, move.offsetY);
            GUITool.DrawText(labelRect, text, color, Constants.Instance.Font.ScreenLabel);
        }
    }
Ejemplo n.º 6
0
    public void Update()
    {
        deltaPos = GetDeltaPos(moveStartPos, InputTool.mousePosition);

        const float threshold = 0.5f;
        int offsetX = 0;
        int offsetY = 0;
        bool isValidOffset = TryGetOffset(blockWidth, threshold, (int)deltaPos.x, out offsetX)
                            && TryGetOffset(blockHeight, threshold, (int)deltaPos.y, out offsetY);

        if (isValidOffset)
        {
            if (move != null && move.offsetX == offsetX && move.offsetY == offsetY)
            {
                // exists, not changed
            }
            else
            {
                move = new MoveContext(selectPosX, selectPosY, offsetX, offsetY);
            }
        }
        else
        {
            move = null;
        }
    }
Ejemplo n.º 7
0
	public MoveContext move() {
		MoveContext _localctx = new MoveContext(Context, State);
		EnterRule(_localctx, 4, RULE_move);
		try {
			EnterOuterAlt(_localctx, 1);
			{
			State = 19; Match(MOV);
			State = 20; _localctx._DIR = Match(DIR);
			State = 21; _localctx._VAL = Match(VAL);
			 Compiler.AddMoveCommand((_localctx._DIR!=null?_localctx._DIR.Text:null), (_localctx._VAL!=null?_localctx._VAL.Text:null)); 
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			ErrorHandler.ReportError(this, re);
			ErrorHandler.Recover(this, re);
		}
		finally {
			ExitRule();
		}
		return _localctx;
	}
Ejemplo n.º 8
0
        public MoveScenarios GetBestMove(Board board, int maxDepth, int secTimeout)
        {
            MiniMax       miniMax       = new MiniMax(maxDepth);
            WorkerManager workerManager = WorkerManager.getInstance();

            if (workerManager.getWorkersCount() == 0)
            {
                return(miniMax.getBestMove(board, secTimeout));
            }

            int         maxColor    = board.CurrentColor;
            MoveContext rootContext = new MoveContext(board, null, null, 0, null, true);

            Stack <MoveContext> mainStack   = new Stack <MoveContext>();
            Stack <MoveContext> childsStack = new Stack <MoveContext>();
            List <MoveContext>  contextList = new List <MoveContext>();

            int generatedChilds = miniMax.generateMoveContext(rootContext, workerManager.getWorkersCount(), contextList);

            if (generatedChilds == 0)
            {
                return(null);
            }
            else if (generatedChilds == 1)
            {
                rootContext = contextList[0];
                miniMax.resolve(contextList[0].ChildsContext, maxColor, maxDepth, secTimeout);
            }
            else if (generatedChilds <= -1)
            {
                foreach (MoveContext mc in contextList)
                {
                    mainStack.Push(mc);
                }

                miniMax.resolve(mainStack, maxColor, 2, -1);
            }
            else
            {
                int i = 0;

                for (; i < contextList.Count - generatedChilds; i++)
                {
                    mainStack.Push(contextList[i]);
                }

                for (; i < contextList.Count; i++)
                {
                    childsStack.Push(contextList[i]);
                }

                workerManager.setParameters(childsStack, mainStack, maxDepth, maxColor, secTimeout - 15);
                workerManager.runWorkers();
                workerManager.waitForWorkers();

                childsStack.Clear();

                miniMax.resolve(mainStack, maxColor, maxDepth, -1);
            }

            if (rootContext.BestValue != int.MinValue)
            {
                return(new MoveScenarios(rootContext.CurrPosition, rootContext.CurrMoveScenario));
            }

            return(new MiniMax(2).getBestMove(board, -1));
        }
Ejemplo n.º 9
0
 public MoveController(MoveContext context)
 {
     _context = context;
 }