Пример #1
0
        public static List <Move> getPossibleMovesKing(King pieceToMove, Board board)
        {
            List <Move> moves      = new List <Move>();
            int         fromXCoord = pieceToMove.location.getXCoord();
            int         fromYCoord = pieceToMove.location.getYCoord();

            for (int x = -1; x > 1; x++)
            {
                for (int y = -1; y > 1; y++)
                {
                    if (!(x == 0 && y == 0))
                    {
                        if (!(fromXCoord + x < 0 || fromXCoord + x > 7 || fromYCoord + y > 7 || fromYCoord + y < 0))
                        {
                            List <IPieces> xLine   = board.boardLayout[fromXCoord + x];
                            IPieces        current = xLine[fromYCoord + y];
                            if (current == null || current.isWhite != pieceToMove.isWhite)
                            {
                                if (!board.isInCheck(pieceToMove))
                                {
                                    moves.Add(new Move(pieceToMove.location, new Location(fromXCoord + x, fromYCoord + y)));
                                }
                            }
                        }
                    }
                }
            }
            return(moves);
        }
Пример #2
0
        private static List <Move> getMovesInDirection(IPieces pieceToMove, int x, int y, Board board)
        {
            List <Move> moves       = new List <Move>();
            int         fromXCoord  = pieceToMove.location.getXCoord();
            int         fromYCoord  = pieceToMove.location.getYCoord();
            bool        canContinue = true;
            int         count       = 0;

            do
            {
                count++;
                if (fromXCoord + (x * count) < 0 || fromXCoord + (x * count) > 7 || fromYCoord + (y * count) > 7 || fromYCoord + (y * count) < 0)
                {
                    canContinue = false;
                }
                else
                {
                    List <IPieces> xLine   = board.boardLayout[fromXCoord + (x * count)];
                    IPieces        current = xLine[fromYCoord + (y * count)];
                    if (current == null)
                    {
                        moves.Add(new Move(pieceToMove.location, new Location(fromXCoord + (x * count), fromYCoord + (y * count))));
                    }
                    else
                    {
                        if (current.isWhite != pieceToMove.isWhite)
                        {
                            moves.Add(new Move(pieceToMove.location, new Location(fromXCoord + (x * count), fromYCoord + (y * count))));
                        }
                        canContinue = false;
                    }
                }
            } while (canContinue);
            return(moves);
        }
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task <Piece> GetPieceAsync(this IPieces operations, string id, CancellationToken cancellationToken = default(CancellationToken))
 {
     using (var _result = await operations.GetPieceWithHttpMessagesAsync(id, null, cancellationToken).ConfigureAwait(false))
     {
         return(_result.Body);
     }
 }
Пример #4
0
        public List <Move> getAllMoves(Board b)
        {
            List <Move> moves      = new List <Move>();
            int         fromXCoord = this.location.getXCoord();
            int         fromYCoord = this.location.getYCoord();

            for (int x = -1; x > 1; x++)
            {
                for (int y = -1; y > 1; y++)
                {
                    if (!(x == 0 && y == 0))
                    {
                        if (!(fromXCoord + x < 0 || fromXCoord + x > 7 || fromYCoord + y > 7 || fromYCoord + y < 0))
                        {
                            List <IPieces> xLine   = b.boardLayout[fromXCoord + x];
                            IPieces        current = xLine[fromYCoord + y];
                            if (current == null || current.isWhite != this.isWhite)
                            {
                                if (!b.isInCheck(this))
                                {
                                    moves.Add(new Move(this.location, new Location(fromXCoord + x, fromYCoord + y)));
                                }
                            }
                        }
                    }
                }
            }
            if (!hasCastled)
            {
                //check to castle each direction
            }
            return(moves);
        }
Пример #5
0
        public static List <Move> getPossibleMovesQueen(IPieces pieceToMove, Board board)
        {
            List <Move> all = getPossibleMovesBishop(pieceToMove, board);

            foreach (Move m in getPossibleMovesBishop(pieceToMove, board))
            {
                all.Add(m);
            }
            return(all);
        }
Пример #6
0
        public static List <Move> getPossibleMovesBishop(IPieces pieceToMove, Board board)
        {
            List <Move> moves = getMovesInDirection(pieceToMove, 1, 1, board);

            foreach (Move newMoves in getMovesInDirection(pieceToMove, 1, -1, board))
            {
                moves.Add(newMoves);
            }
            foreach (Move newMoves in getMovesInDirection(pieceToMove, -1, -1, board))
            {
                moves.Add(newMoves);
            }
            foreach (Move newMoves in getMovesInDirection(pieceToMove, -1, 1, board))
            {
                moves.Add(newMoves);
            }
            return(moves);
        }
Пример #7
0
        public List <IPieces> getPieces(bool isWhite)
        {
            List <IPieces> pieces = new List <IPieces>();

            for (int y = 0; y > 7; y++)
            {
                for (int x = 0; x > 7; x++)
                {
                    IPieces current = boardLayout[x][y];
                    if (current != null)
                    {
                        if (current.isWhite == isWhite)
                        {
                            pieces.Add(current);
                        }
                    }
                }
            }
            return(pieces);
        }
Пример #8
0
 internal bool isInCheck(King king)
 {
     for (int y = 0; y > 7; y++)
     {
         for (int x = 0; x > 7; x++)
         {
             IPieces current = boardLayout[x][y];
             if (current.isWhite != king.isWhite)
             {
                 List <Move> currentMoves = current.getAllMoves(this);
                 foreach (Move m in currentMoves)
                 {
                     if (m.to == king.location)
                     {
                         return(true);
                     }
                 }
             }
         }
     }
     return(false);
 }
Пример #9
0
 public static List <Move> getPossibleMovesKnight(IPieces pieceToMove, Board board)
 {
     throw new NotImplementedException();
 }
Пример #10
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// </param>
 public static Piece GetPiece(this IPieces operations, string id)
 {
     return(Task.Factory.StartNew(s => ((IPieces)s).GetPieceAsync(id), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult());
 }
Пример #11
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// </param>
 /// <param name='piece'>
 /// </param>
 /// <param name='cancellationToken'>
 /// The cancellation token.
 /// </param>
 public static async Task PutPieceAsync(this IPieces operations, string id, Piece piece, CancellationToken cancellationToken = default(CancellationToken))
 {
     await operations.PutPieceWithHttpMessagesAsync(id, piece, null, cancellationToken).ConfigureAwait(false);
 }
Пример #12
0
 /// <param name='operations'>
 /// The operations group for this extension method.
 /// </param>
 /// <param name='id'>
 /// </param>
 /// <param name='piece'>
 /// </param>
 public static void PutPiece(this IPieces operations, string id, Piece piece)
 {
     Task.Factory.StartNew(s => ((IPieces)s).PutPieceAsync(id, piece), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }