Exemplo n.º 1
0
        public bool Move(int col, int row)
        {
            bool valid   = false;
            int  capture = -1;

            if (Board.ValidMove(Type, Col, Row, col, row, out capture, FirstMove))
            {
                if (capture != -1)
                {
                    Board.Capture(Board.GetPiece(capture / 8, capture % 8));
                }

                Board.Move(this.Col, this.Row, col, row);
                this.Col = col;
                this.Row = row;

                valid = true;
            }

            this.SetPosition((this.X = this.Col * 75), (this.Y = this.Row * 75));

            System.Windows.Controls.Canvas.SetZIndex(this, 100);

            return(valid);
        }
Exemplo n.º 2
0
        public static string fromAlgebraicNotation(string s)
        {
            //bool check = false;
            if (s.Contains("+"))
            {
                s = s.Replace("+", "");
                // check = true;
            }

            Queue <char> qc = new Queue <char>(s.ToArray());
            char         c  = qc.Count < 3 ? 'p' : qc.Dequeue();
            // bool capture = false;
            char       amb   = '\0';
            string     nn    = "";
            PieceColor color = char.IsLower(c) ? PieceColor.WHITE : PieceColor.BLACK;

            if (qc.Peek() == 'x')
            {
                // capture = true;
                qc.Dequeue();
            }

            if (qc.Count == 3)
            {
                amb = qc.Dequeue();
            }

            Func <int, int> n1 = (a) => {
                return(Math.Abs(a - 8));
            };

            int dcol = (((int)qc.Dequeue()) - 97);
            int drow = n1(Math.Abs(((int)qc.Dequeue() - '0')));

            int i = 0;

            if (c == 'p' || c == 'P')
            {
                for (int n = 0; n < 8; n++)
                {
                    if (Board.pieces[dcol, n] == c)
                    {
                        i = (dcol * 8) + n;
                    }
                }
            }
            else
            {
                i = Board.GetPos(c);
            }

            int col = i / 8;
            int row = i % 8;
            int capture;

            if (!Board.ValidMove(Board.GetType(c), col, row, dcol, drow, out capture) ||
                amb != '\0' && (!char.IsDigit(amb) && (((int)amb) - 97) != col || (Math.Abs(((int)amb - '0') - 8)) != row))
            {
                if ((i = Board.GetPos(c, i)) != -1)
                {
                    col = i / 8;
                    row = i % 8;
                }
            }

            if (i != -1)
            {
                nn = string.Format("{0}x{1}:{2}x{3}", col, row, dcol, drow);
            }

            return(nn);
        }