Ejemplo n.º 1
0
        private void PawnMove(ChessBoard[,] board, int posLet, int posNum, int letOfPiece, int numOfPiece)
        {
            if (posLet == 1 || posLet == 8)
            {
                Coms.RenderComs(7);
                UserInput userinput = new UserInput();
                string    input     = userinput.GetPromotionInput();
                switch (input[0])
                {
                case 'K':
                    board[posLet, posNum] = (ChessBoard)((int)ChessBoard.whiteKnight * (int)board[letOfPiece, numOfPiece]);
                    break;

                case 'B':
                    board[posLet, posNum] = (ChessBoard)((int)ChessBoard.whiteBishop * (int)board[letOfPiece, numOfPiece]);
                    break;

                case 'T':
                    board[posLet, posNum] = (ChessBoard)((int)ChessBoard.whiteTower * (int)board[letOfPiece, numOfPiece]);
                    break;

                case 'Q':
                    board[posLet, posNum] = (ChessBoard)((int)ChessBoard.whiteQueen * (int)board[letOfPiece, numOfPiece]);
                    break;
                }
            }
            else
            {
                board[posLet, posNum] = board[letOfPiece, numOfPiece];
            }
        }
Ejemplo n.º 2
0
        public string GetPromotionInput()
        {
            string input = Console.ReadLine();

            if (CheckPromotionInput(input))
            {
                return(input);
            }
            Coms.RenderComs(2);
            return(GetPromotionInput());
        }
Ejemplo n.º 3
0
        public int GetInput()
        {
            string tmp = Console.ReadLine();

            tmp = tmp.Trim();
            if (CheckInput(tmp))
            {
                Transform transfrom = new Transform();
                return(transfrom.TransformToInt(tmp));
            }
            else
            {
                Coms.RenderComs(2);
                return(GetInput());
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            RenderBoard   renderboard   = new RenderBoard(board);
            UserInput     userinput     = new UserInput();
            Pieces        pieces        = new Pieces();
            bool          whoseTurn     = true; //white - true, black - false
            Transform     transform     = new Transform();
            PossbileMoves possiblemoves = new PossbileMoves();
            Moves         moves         = new Moves();
            string        attackedTiles = "AA";

            string movesInt = "";

            //renderboard.CostumBoard(board);
            while (true) // to be changed to IsGameOver method
            {
                attackedTiles = "AA";
                int        posToWhichMove, posOfPiece;
                ChessBoard piece;
                //renderboard.CostumBoard(board); //DEBUG
                renderboard.Render(board);
                Coms.RenderComs(1);
                posOfPiece = userinput.GetInput();
                if (!pieces.IsPlayerPiece(board[posOfPiece / 10, posOfPiece % 10], whoseTurn))
                {
                    Coms.RenderComs(6);
                    continue;
                }
                Coms.RenderComs(3);
                posToWhichMove = userinput.GetInput(); // get input to where should the piece be moved
                movesInt       = ListMoves.RememberAsInt(posToWhichMove / 10, posToWhichMove % 10, movesInt);


                if (moves.Controller(board, posToWhichMove / 10, posToWhichMove % 10, posOfPiece / 10, posOfPiece % 10, whoseTurn, movesInt).IndexOf(posToWhichMove.ToString()) != -1)
                {
                    ChessBoard[,] copyOfBoard = new ChessBoard[8, 8];
                    for (int i = 0; i < 8; i++)
                    {
                        for (int j = 0; j < 8; j++)
                        {
                            copyOfBoard[i, j] = board[i, j];
                        }
                    }
                    moves.ExecuteMove(copyOfBoard, posToWhichMove / 10, posToWhichMove % 10, posOfPiece / 10, posOfPiece % 10, whoseTurn);
                    if (whoseTurn)
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            for (int j = 0; j < 8; j++)
                            {
                                if (board[i, j] < 0 && board[i, j] != 0)
                                {
                                    attackedTiles = String.Concat(attackedTiles, transform.TransformFromIntToNotation((moves.ListAttackedTiles(board, i, j, !whoseTurn))));
                                }
                            }
                        }
                    }
                    else
                    {
                        for (int i = 0; i < 8; i++)
                        {
                            for (int j = 0; j < 8; j++)
                            {
                                if (board[i, j] > 0 && board[i, j] != 0)
                                {
                                    attackedTiles = String.Concat(attackedTiles, transform.TransformFromIntToNotation((moves.ListAttackedTiles(board, i, j, !whoseTurn))));
                                }
                                //, Console.WriteLine(attackedTiles);
                            }
                        }
                    }
                    //Console.WriteLine(attackedTiles);
                    if (attackedTiles.IndexOf(possiblemoves.SearchForKing(copyOfBoard, whoseTurn)) == -1)
                    {
                    }
                    else
                    {
                        //write funciton that lists all moves white can move and then check if after any of those moves the check is still in place, if it is then game over!!
                        Coms.RenderComs(8);
                        continue;
                    }
                    moves.ExecuteMove(board, posToWhichMove / 10, posToWhichMove % 10, posOfPiece / 10, posOfPiece % 10, whoseTurn);
                }
                else
                {
                    Coms.RenderComs(5);
                    continue;
                }
                if (whoseTurn)
                {
                    whoseTurn = false;
                }
                else
                {
                    whoseTurn = true;
                }
            }
        }