Ejemplo n.º 1
0
        public override List <ChessMove> AvailableMoves(Board board)
        {
            List <ChessMove> moves = new List <ChessMove>();
            //Front movement
            Tile nextTile;

            if (IsRelTileEmpty(1, 0, board, out nextTile))
            {
                ChessMove move = CreateMoveTo(nextTile);
                if (nextTile.row == GetRowColorRelative(7))
                {
                    move.isPromotionMove = true;
                }
                moves.Add(move);

                if (currentTile.row == GetRowColorRelative(1))
                {
                    Tile twoTilesAhead;
                    if (IsRelTileEmpty(2, 0, board, out twoTilesAhead))
                    {
                        moves.Add(CreateMoveTo(twoTilesAhead));
                    }
                }
            }
            //Left Attack
            Tile leftAttackTile;

            if (IsRelTileEnemy(1, -1, board, out leftAttackTile))
            {
                ChessMove leftAttack = CreateMoveTo(leftAttackTile);
                if (GetRowColorRelative(7) == leftAttackTile.row)
                {
                    leftAttack.isPromotionMove = true;
                }
                moves.Add(leftAttack);
            }
            //Right Attack
            Tile rightAttackTile;

            if (IsRelTileEnemy(1, 1, board, out rightAttackTile))
            {
                ChessMove rightAttack = CreateMoveTo(rightAttackTile);
                if (GetRowColorRelative(7) == rightAttackTile.row)
                {
                    rightAttack.isPromotionMove = true;
                }
                moves.Add(rightAttack);
            }
            //En Passant

            if (currentTile.row == GetRowColorRelative(4))
            {
                ChessMove lastMove = moveManager.GetLastMove();
                if (lastMove.activePiece.GetPieceType() == PieceType.Pawn &&
                    lastMove.fromTile.row == GetRowColorRelative(6) &&
                    lastMove.toTile.row == GetRowColorRelative(4) &&
                    Mathf.Abs((int)lastMove.fromTile.col - (int)currentTile.col) == 1)
                {
                    Tile      enPassantTile = board.GetTile(GetRowColorRelative(5), lastMove.fromTile.col);
                    ChessMove enPassantMove = new ChessMove(currentTile, enPassantTile, lastMove.activePiece);
                    moves.Add(enPassantMove);
                }
            }

            return(moves);
        }