Пример #1
0
        static void Main(string[] args)
        {
            try
            {
                ChessMatch match = new ChessMatch();
                while (!match.IsMatchOver)
                {
                    try
                    {
                        System.Console.WriteLine("----------- WELCOME TO THE CHESS MATCH!!--------------");
                        System.Console.WriteLine();
                        GameScreen.PrintChess(match.Tab);
                        System.Console.WriteLine("Turn: " + match.Turn);
                        System.Console.WriteLine("Current Player: " + match.CurrentPlayer);
                        System.Console.WriteLine();
                        System.Console.Write("Origin: ");
                        Position origin = GameScreen.ReadPositionChess().ToPosition();
                        match.ValidateOriginPosition(origin);

                        bool[,] possiblePositions = match.Tab.GetPiece(origin).PossibleMoves();
                        GameScreen.PrintChess(match.Tab, possiblePositions);

                        System.Console.Write("Destination: ");
                        Position destination = GameScreen.ReadPositionChess().ToPosition();
                        match.ValidateDestinationPosition(origin, destination);
                        GameScreen.PrintChess(match.Tab, possiblePositions);
                        System.Console.Write("Destination: ");


                        match.MakeMove(origin, destination);
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine(e.Message);
                        Console.ReadLine();
                    }
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
            }

            Console.ReadLine();
        }
Пример #2
0
 /// <summary>
 /// Simple constructor
 /// </summary>
 /// <param name="board">Board</param>
 /// <param name="color">Color of piece</param>
 /// <param name="match">Match</param>
 public King(Board board, Color color, ChessMatch match) : base(board, color)
 {
     Match = match;
 }
Пример #3
0
 public Peasant(Board board, Color color, ChessMatch match) : base(board, color)
 {
     Match = match;
 }
Пример #4
0
 public Pawn(Board board, Color color, ChessMatch match) : base(board, color)
 {
     this.match = match;
 }
Пример #5
0
 public Pawn(Board board, Color color, ChessMatch chessMatch) : base(color, board)
 {
     this.cm = chessMatch;
 }
Пример #6
0
 public Pawn(Board brd, Color color, ChessMatch match) : base(color, brd)
 {
     Match = match;
 }
Пример #7
0
 public Pawn(Color color, Board board, ChessMatch match) : base(color, board)
 {
     Match = match;
 }
Пример #8
0
 public Pawn(GameBoard board, Color color, ChessMatch chess) : base(board, color)
 {
     this.chess = chess;
 }
Пример #9
0
 public King(Board bd, Color color, ChessMatch match) : base(bd, color)
 {
     this.match = match;
 }
Пример #10
0
 public Pawn(Chessboard chessboard, Color color, ChessMatch chessMatch) : base(chessboard, color)
 {
     this.chessMatch = chessMatch;
 }
Пример #11
0
 public King(Color color, Board board, ChessMatch match) : base(color, board)
 {
     KingMatch = match;
 }
Пример #12
0
        public override bool[,] possibleMov()
        {
            bool[,] mat = new bool[PieceBoard.Lines, PieceBoard.Column];
            ChessMatch match = new ChessMatch();

            if (PieceColor == Color.white)
            {
                int line   = PiecePos.Line;
                int col    = PiecePos.Column + 1;
                int revcol = PiecePos.Column - 1;

                if (PiecePos.Line == 6)
                {
                    while (line > PiecePos.Line - 3)
                    {
                        if (PieceBoard.isPosition(new Position(PiecePos.Line - 1, col)) && canCapture(new Position(PiecePos.Line - 1, col)))
                        {
                            mat[PiecePos.Line - 1, col] = true;
                        }
                        if (PieceBoard.isPosition(new Position(PiecePos.Line - 1, revcol)) && canCapture(new Position(PiecePos.Line - 1, revcol)))
                        {
                            mat[PiecePos.Line - 1, revcol] = true;
                        }
                        if (PieceBoard.isPosition(new Position(line, PiecePos.Column)) && canMov(new Position(line, PiecePos.Column)))
                        {
                            mat[line, PiecePos.Column] = true;
                        }
                        line--;
                    }
                }
                else
                {
                    if (PieceBoard.isPosition(new Position(line - 1, col)) && canCapture(new Position(line - 1, col)))
                    {
                        mat[line - 1, col] = true;
                    }
                    if (PieceBoard.isPosition(new Position(line - 1, revcol)) && canCapture(new Position(line - 1, revcol)))
                    {
                        mat[line - 1, revcol] = true;
                    }
                    if (PieceBoard.isPosition(new Position(line - 1, PiecePos.Column)) && canMov(new Position(line - 1, PiecePos.Column)))
                    {
                        mat[line - 1, PiecePos.Column] = true;
                    }
                }

                //en passant
                if (PiecePos.Line == 3)
                {
                    Position left = new Position(PiecePos.Line, PiecePos.Column - 1);
                    if (PieceBoard.isPieceOnPos(left) && isEnemy(left) && PieceBoard.GetPiece(left) == _match._vulnerableEnPassant)
                    {
                        mat[left.Line - 1, left.Column] = true;
                    }
                    Position right = new Position(PiecePos.Line, PiecePos.Column + 1);
                    if (PieceBoard.isPieceOnPos(right) && isEnemy(right) && PieceBoard.GetPiece(right) == _match._vulnerableEnPassant)
                    {
                        mat[right.Line - 1, right.Column] = true;
                    }
                }
            }
            else
            {
                int line   = PiecePos.Line;
                int col    = PiecePos.Column + 1;
                int revcol = PiecePos.Column - 1;

                if (PiecePos.Line == 1)
                {
                    while (line < PiecePos.Line + 3)
                    {
                        if (PieceBoard.isPosition(new Position(PiecePos.Line + 1, col)) && canCapture(new Position(PiecePos.Line + 1, col)))
                        {
                            mat[PiecePos.Line + 1, col] = true;
                        }
                        if (PieceBoard.isPosition(new Position(PiecePos.Line + 1, revcol)) && canCapture(new Position(PiecePos.Line + 1, revcol)))
                        {
                            mat[PiecePos.Line + 1, revcol] = true;
                        }
                        if (PieceBoard.isPosition(new Position(line, PiecePos.Column)) && canMov(new Position(line, PiecePos.Column)))
                        {
                            mat[line, PiecePos.Column] = true;
                        }
                        line++;
                    }
                }
                else
                {
                    if (PieceBoard.isPosition(new Position(line + 1, col)) && canCapture(new Position(line + 1, col)))
                    {
                        mat[line + 1, col] = true;
                    }
                    if (PieceBoard.isPosition(new Position(line + 1, revcol)) && canCapture(new Position(line + 1, revcol)))
                    {
                        mat[line + 1, revcol] = true;
                    }
                    if (PieceBoard.isPosition(new Position(line + 1, PiecePos.Column)) && canMov(new Position(line + 1, PiecePos.Column)))
                    {
                        mat[line + 1, PiecePos.Column] = true;
                    }
                }
                //en passant
                if (PiecePos.Line == 4)
                {
                    Position left = new Position(PiecePos.Line, PiecePos.Column - 1);
                    if (PieceBoard.isPieceOnPos(left) && isEnemy(left) && PieceBoard.GetPiece(left) == _match._vulnerableEnPassant)
                    {
                        mat[left.Line + 1, left.Column] = true;
                    }
                    Position right = new Position(PiecePos.Line, PiecePos.Column + 1);
                    if (PieceBoard.isPieceOnPos(right) && isEnemy(right) && PieceBoard.GetPiece(right) == _match._vulnerableEnPassant)
                    {
                        mat[right.Line + 1, right.Column] = true;
                    }
                }
            }

            return(mat);
        }