Пример #1
0
        public static string toAlgebraicNotation(string s)
        {
            string an = null;

            int  c1, r1, c2, r2;
            char piece;

            if (Notations.parse(s, out c1, out r1, out c2, out r2) &&
                (piece = Board.pieces[c1, r1]) != '\0')
            {
                an = piece.ToString();
                PieceType  type  = Board.GetType(piece);
                PieceColor color = Board.GetColor(piece);
                if (Board.GetColor(piece) == PieceColor.WHITE)
                {
                    an = an.ToLower();
                }

                char dest = Board.pieces[c2, r2];
                if (dest != '\0' && Board.GetColor(dest) != color && Board.GetType(dest) != PieceType.KING)
                {
                    an += "x";
                }/*
                  * if (type != PieceType.PAWN && type > PieceType.QUEEN)
                  * {
                  * int i = Board.GetPos(piece, c1 * 8 + r1);
                  * if (i != -1)
                  * {
                  *     int pc = i / 8;
                  *     int pr = i % 8;
                  *     int p2 = Board.pieces[pc, pr];
                  *     int capture = -1;
                  *     if (Board.ValidMove(type, pc, pr, c2, r2, out capture))
                  *     {
                  *         if (c1 == pc)
                  *             an += Math.Abs(r1 - 8);
                  *         else
                  *             an += (char)(c1 + 97);
                  *     }
                  * }
                  * }*/

                an += string.Format("{0}{1}", (char)(c2 + 97), Math.Abs(r2 - 8));
                if (dest != '\0' && Board.GetType(dest) == PieceType.KING)
                {
                    an += "++";
                }
            }

            return(an);
        }
Пример #2
0
 public void MoveFromHistory(ArrayList history, int n)
 {
     InitBoard();
     for (int i = 0; i < n; i++)
     {
         HMove move = (HMove)history[i];
         if (move.Nn == string.Empty)
         {
             move.Nn = Notations.fromAlgebraicNotation(move.An);
         }
         int c, r, c2, r2;
         Notations.parse(move.Nn, out c, out r, out c2, out r2);
         Piece p = (Piece)Board._pieces[c + "x" + r];
         p.Move(c2, r2);
         Board.whites = !Board.whites;
     }
 }
Пример #3
0
        public void InternalOnMove()
        {
            canvas1.OnMove += (int acol, int arow, int bcol, int brow, PieceColor color) =>
            {
                Func <int, int, string> n1 = (a, b) =>
                {
                    return(MainColor == PieceColor.WHITE ?
                           (char)(a + 97) + "x" + Fix(b - 1) : (char)(Fix(a) + 97) + "x" + (b + 1));
                };
                string nn = acol + "x" + arow + ":" + bcol + "x" + brow;
                string an = Notations.toAlgebraicNotation(nn);

                if (Type != GameType.REPLAY)
                {
                    History.Add(new HMove {
                        Nn = nn, An = an
                    });
                }

                uimoves.Text += (color == PieceColor.WHITE ? "\r\n" : " - ") + an;// (color == PieceColor.WHITE ? "\r\n" : " - ") + n1(acol, arow) + ":" + n1(bcol, brow);

                uimoves.ScrollToEnd();
            };
        }