// TODO: You must write this method.
        public virtual bool Equals(ChessMove other)
        {
            ChessMoveType type = ChessMoveType.PawnPromote;

            // Most chess moves are equal to each other if they have the same start and end position.
            // PawnPromote moves must also be promoting to the same piece type.
            if (this.StartPosition == other.StartPosition)
            {
                if (this.EndPosition == other.EndPosition)
                {
                    if (this.MoveType == other.MoveType && other.MoveType == type)
                    {
                        if (this.PromotePiece == other.PromotePiece)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                        //Console.WriteLine(this.mov)
                    }
                    else
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }
Beispiel #2
0
 public ChessMove(BoardPosition start, BoardPosition end, ChessPieceType piece, ChessMoveType moveType = ChessMoveType.PawnPromote)
 {
     StartPosition  = start;
     EndPosition    = end;
     ChessPieceType = piece;
     MoveType       = moveType;
 }
Beispiel #3
0
 public GameMoveData(ChessMoveType moveType, ChessColor color, ChessPieceCoord from, ChessPieceCoord to)
 {
     MoveType = moveType;
     Color    = color;
     From     = from;
     To       = to;
 }
Beispiel #4
0
        /// <summary>
        /// Constructs a ChessMove that moves a piece from one position to another
        /// </summary>
        /// <param name="start">the starting position of the piece to move</param>
        /// <param name="end">the position where the piece will end up</param>
        /// <param name="moveType">the type of move represented</param>
        /// <param name="pieceType">the piece to replace pawn during promotion</param>

        public ChessMove(BoardPosition start, BoardPosition end, ChessMoveType moveType = ChessMoveType.Normal, ChessPieceType pieceType = ChessPieceType.Empty)
        {
            StartPosition  = start;
            EndPosition    = end;
            MoveType       = moveType;
            PromotionPiece = pieceType;
        }
Beispiel #5
0
 public ChessMove(BoardPosition start, BoardPosition end, ChessPieceType promoteTo, ChessMoveType moveType = ChessMoveType.Normal)
 {
     StartPosition = start;
     EndPosition   = end;
     MoveType      = moveType;
     PromoteTo     = promoteTo;
 }
        /// <summary>
        /// Parses a string representing a ChessMove into a ChessMove object.
        /// </summary>
        /// <param name="move">a string in the format "(start, end)", where start and end use
        /// algebraic notation for board positions. In pawn promotion moves, "end" is a string name
        /// for the piece to replace the promoted pawn with, e.g., "queen", "bishop", "knight", or "rook".
        /// </param>
        public IGameMove ParseMove(string move)
        {
            string[]      split = move.ToLower().Trim(new char[] { '(', ')' }).Split(',');
            BoardPosition start = ParsePosition(split[0].Trim());
            ChessMoveType type  = ChessMoveType.Normal;

            string        second = split[1].Trim();
            BoardPosition end;

            if (second == "queen")
            {
                end  = new BoardPosition(-1, (int)ChessPieceType.Queen);
                type = ChessMoveType.PawnPromote;
            }
            else if (second == "bishop")
            {
                end  = new BoardPosition(-1, (int)ChessPieceType.Bishop);
                type = ChessMoveType.PawnPromote;
            }
            else if (second == "knight")
            {
                end  = new BoardPosition(-1, (int)ChessPieceType.Knight);
                type = ChessMoveType.PawnPromote;
            }
            else if (second == "rook")
            {
                end  = new BoardPosition(-1, (int)ChessPieceType.RookPawn);
                type = ChessMoveType.PawnPromote;
            }
            else
            {
                end = ParsePosition(split[1].Trim());
            }
            return(new ChessMove(start, end, type));
        }
 public ChessMove(BoardPosition start, BoardPosition end, ChessPieceType _promoteto, ChessMoveType moveType = ChessMoveType.PawnPromote)
 {
     StartPosition = start;
     EndPosition   = end;
     MoveType      = moveType;
     promoteTo     = _promoteto;
 }
 public ChessMove(BoardPosition start, BoardPosition end, ChessPieceType chessPieceType, ChessMoveType moveType = ChessMoveType.Normal)
 {
     StartPosition = start;
     EndPosition   = end;
     MoveType      = moveType;
     ChessPiece    = chessPieceType;
 }
 /// <summary>
 /// Constructs a ChessMove that moves a piece from one position to another
 /// </summary>
 /// <param name="start">the starting position of the piece to move</param>
 /// <param name="end">the position where the piece will end up</param>
 /// <param name="moveType">the type of move represented</param>
 public ChessMove(BoardPosition start, BoardPosition end, ChessMoveType moveType = ChessMoveType.Normal)
 {
     StartPosition = start;
     EndPosition   = end;
     MoveType      = moveType;
     PromoteType   = ChessPieceType.Empty;
     IsCapturing   = false;
 }
Beispiel #10
0
 public ChessMoveData(ObjectGuid playerGuid, ObjectGuid pieceGuid, GameMoveData data)
 {
     Type       = data.MoveType;
     PlayerGuid = playerGuid;
     Color      = data.Color;
     PieceGuid  = pieceGuid;
     From       = data.From;
     To         = data.To;
 }
 /// <summary>
 /// Constructs a ChessMove that moves a piece from one position to another
 /// </summary>
 /// <param name="start">the starting position of the piece to move</param>
 /// <param name="end">the position where the piece will end up</param>
 /// <param name="moveType">the type of move represented</param>
 public ChessMove(BoardPosition start, BoardPosition end, ChessMoveType moveType = ChessMoveType.Normal)
 {
     StartPosition = start;
     EndPosition   = end;
     MoveType      = moveType;
     if (moveType.Equals(ChessMoveType.PawnPromote))
     {
         promoteTo = ChessPieceType.Empty;
     }
 }
Beispiel #12
0
        /// <summary>
        /// Converts the given ChessMove to a string representation in the form
        /// "(start, end)", where start and end are board positions in algebraic
        /// notation (e.g., "a5").
        ///
        /// If this move is a pawn promotion move, the selected promotion piece
        /// must also be in parentheses after the end position, as in
        /// "(a7, a8, Queen)".
        /// </summary>
        public string MoveToString(ChessMove move)
        {
            var row_map = new Dictionary <char, char>();

            row_map.Add('0', '8');
            row_map.Add('1', '7');
            row_map.Add('2', '6');
            row_map.Add('3', '5');
            row_map.Add('4', '4');
            row_map.Add('5', '3');
            row_map.Add('6', '2');
            row_map.Add('7', '1');


            var col_map = new Dictionary <char, char>();

            col_map.Add('0', 'a');
            col_map.Add('1', 'b');
            col_map.Add('2', 'c');
            col_map.Add('3', 'd');
            col_map.Add('4', 'e');
            col_map.Add('5', 'f');
            col_map.Add('6', 'g');
            col_map.Add('7', 'h');


            String start_position = move.StartPosition.ToString();

            start_position = start_position.Replace(" ", "");
            start_position = start_position.Replace("(", "");
            start_position = start_position.Replace(")", "");
            start_position = start_position.Replace(",", "");

            char[] start_array = start_position.ToCharArray(0, start_position.Length);
            start_array[0] = row_map[start_array[0]];
            start_array[1] = col_map[start_array[1]];

            String start_moveString = start_array[1].ToString() + start_array[0].ToString();


            String end_position = move.EndPosition.ToString();

            end_position = end_position.Replace(" ", "");
            end_position = end_position.Replace("(", "");
            end_position = end_position.Replace(")", "");
            end_position = end_position.Replace(",", "");
            char[] end_array = end_position.ToCharArray(0, end_position.Length);
            end_array[0] = row_map[end_array[0]];
            end_array[1] = col_map[end_array[1]];

            String        end_moveString = end_array[1].ToString() + end_array[0].ToString();
            ChessMoveType movetype       = move.MoveType;

            //if (movetype == ChessMoveType.PawnPromote)
            //{
            //	return ("(" + start_moveString + "," + end_moveString + "," + move.ChessPieceType + ")");
            //}
            //else
            if (movetype == ChessMoveType.Normal)
            {
                return("(" + start_moveString + "," + end_moveString + ")");
            }
            if (movetype == ChessMoveType.PawnPromote)
            {
                return("(" + start_moveString + "," + end_moveString + "," + move.chessPiece + ")");
            }
            else
            {
                return("(" + start_moveString + "," + end_moveString + "," + move.MoveType + ")");
            }
        }
 /// <summary>
 /// Constructs a ChessMove that performs a "special" move from one position to another.
 /// </summary>
 /// <param name="start">the starting position of the piece to move</param>
 /// <param name="end">the position where the piece will end up</param>
 /// <param name="type">the special chess move type to perform</param>
 public ChessMove(BoardPosition start, BoardPosition end, ChessMoveType type) :
     this(start, end)
 {
     MoveType = type;
 }
        /// <summary>
        /// Converts a string representation of a move into a ChessMove object.
        /// Must work with any string representation created by MoveToString.
        /// </summary>
        public ChessMove ParseMove(string moveText)
        {
            var col_map = new Dictionary <char, int>();

            col_map.Add('a', 0);
            col_map.Add('b', 1);
            col_map.Add('c', 2);
            col_map.Add('d', 3);
            col_map.Add('e', 4);
            col_map.Add('f', 5);
            col_map.Add('g', 6);
            col_map.Add('h', 7);

            var row_map = new Dictionary <char, int>();

            row_map.Add('8', 0);
            row_map.Add('7', 1);
            row_map.Add('6', 2);
            row_map.Add('5', 3);
            row_map.Add('4', 4);
            row_map.Add('3', 5);
            row_map.Add('2', 6);
            row_map.Add('1', 7);

            //Console.WriteLine(moveText);
            moveText = Regex.Replace(moveText, @" ", "");
            moveText = moveText.Replace("(", "");
            moveText = moveText.Replace(")", "");
            moveText = moveText.Replace(" ", "");

            //Console.WriteLine(moveText);
            String[] move = moveText.Split(",");

            String start_move = "";
            String end_move   = "";

            if (move.Length > 0)
            {
                start_move = move[0];
                end_move   = move[1];
            }
            //Console.WriteLine("parsed start move:" + row_map[start_move[1]] + "," + col_map[start_move[0]]);

            int parsedStart_row = row_map[start_move[1]];
            int parsedStart_col = col_map[start_move[0]];

            int parsedEnd_row = row_map[end_move[1]];
            int parsedEnd_col = col_map[end_move[0]];

            String    moveType = "";
            ChessMove test     = null;

            if (move.Length > 2)
            {
                moveType = move[move.Length - 1];
                Console.WriteLine(moveType);
                if (moveType == "Queen" || moveType == "queen")
                {
                    test = new ChessMove(new BoardPosition(parsedStart_row, parsedStart_col), new BoardPosition(parsedEnd_row, parsedEnd_col), ChessPieceType.Queen, ChessMoveType.PawnPromote);
                }
                else if (moveType == "Bishop" || moveType == "bishop")
                {
                    test = new ChessMove(new BoardPosition(parsedStart_row, parsedStart_col), new BoardPosition(parsedEnd_row, parsedEnd_col), ChessPieceType.Bishop, ChessMoveType.PawnPromote);
                }
                else if (moveType == "Rook" || moveType == "rook")
                {
                    test = new ChessMove(new BoardPosition(parsedStart_row, parsedStart_col), new BoardPosition(parsedEnd_row, parsedEnd_col), ChessPieceType.Rook, ChessMoveType.PawnPromote);
                }
                else if (moveType == "Knight" || moveType == "knight")
                {
                    test = new ChessMove(new BoardPosition(parsedStart_row, parsedStart_col), new BoardPosition(parsedEnd_row, parsedEnd_col), ChessPieceType.Knight, ChessMoveType.PawnPromote);
                }
                else
                {
                    ChessMoveType typeParsed = (ChessMoveType)(Enum.Parse(typeof(ChessMoveType), move[move.Length - 1]));
                    test = new ChessMove(new BoardPosition(parsedStart_row, parsedStart_col), new BoardPosition(parsedEnd_row, parsedEnd_col), typeParsed);
                }
            }
            else
            {
                test = new ChessMove(new BoardPosition(parsedStart_row, parsedStart_col), new BoardPosition(parsedEnd_row, parsedEnd_col));
            }
            return(test);
        }
Beispiel #15
0
 /// <summary>
 /// Creates a ChessMove using the given start and end positions.
 /// </summary>
 protected ChessMove Move(BoardPosition start, BoardPosition end, ChessMoveType type = ChessMoveType.Normal) =>
 new ChessMove(start, end, type);