Exemplo n.º 1
0
        /**
         * Two Part MoveHandler
         * First Square received is pushed onto a stack.
         * Second Square is then received, and the First Square gets popped. They are combined to create a move.
         * If the Move is valid it is played. If it is not, the Second Square gets pushed onto the stack, and the cycle repeats.
         */
        public void MoveHandler(Square tapped)
        {
            if (tutorialFlag)
            {
                // Play differently if in tutorial mode
                Console.WriteLine("Tutorial square " + tapped.Name + " tapped");
                tutorialQueue.Enqueue(tapped);
            }
            else if (blackIsAI && whiteIsAI)
            {
                // Ignore non-AI input
                Console.WriteLine("Both players AI, square tap ignored.");
            }
            else if ((blackIsAI && !position.whiteMove) || (whiteIsAI & position.whiteMove))
            {
                // Ignore input during AI turn
                Console.WriteLine("Safety ignore.");
            }
            else
            {
                Console.WriteLine("Square " + tapped.Name + " tapped");
                moveQueue.Enqueue(tapped);
                if (this.oneClick)
                {
                    Square orig = moveQueue.Dequeue();
                    Square dest = moveQueue.Dequeue();

                    if (orig.getSquareNumber() == dest.getSquareNumber())
                    {
                        DoColourations();
                        this.oneClick = false;
                        return;
                    }

                    PieceType promoteTo = ((dest.getSquareNumber() <= 7 | dest.getSquareNumber() > 55) & (orig.getPiece().Equals(PieceType.p) | orig.getPiece().Equals(PieceType.P))) ? getPromotion(orig.getPiece()) : PieceType.Empty;

                    Move current = new Move(orig.getSquareNumber(), dest.getSquareNumber(), promoteTo);
                    if (MoveCheck(current))
                    {
                        performMove(current);
                    }
                    else
                    {
                        moveQueue.Enqueue(dest);
                        DoColourations();
                        this.ColourLegalMoves(dest.getSquareNumber());
                    }

                }
                else
                {
                    this.ColourLegalMoves(tapped.getSquareNumber());
                    this.oneClick = true;
                }
            }
        }
Exemplo n.º 2
0
        /**
         * Performs a move based on the origin and destination squares
         */
        public void MoveHandler(Square orig, Square dest)
        {
            PieceType promoteTo = ((dest.getSquareNumber() <= 7 | dest.getSquareNumber() > 55) & (orig.getPiece().Equals(PieceType.p) | orig.getPiece().Equals(PieceType.P))) ? getPromotion(orig.getPiece()) : PieceType.Empty;

            Move current = new Move(orig.getSquareNumber(), dest.getSquareNumber(), promoteTo);
            if (MoveCheck(current))
            {
                performMove(current);
            }
        }