public void ToList_1_Correct() { SquareFlag square = SquareFlag.H1; var asList = square.ToList(); Assert.Collection(asList, item => Assert.Equal(SquareFlag.H1, item)); }
private SquareFlag AddPinnedMovesInternal( MoveGenerationWorkspace workspace, Square kingSquare, SquareFlag potentialPins, SquareFlag pinners, bool diagonal, SquareFlag pushMask, SquareFlag captureMask) { var pinnedSquares = (SquareFlag)0; var pinnersAsList = pinners.ToList(); foreach (var pinner in pinnersAsList) { var path = AttackBitmaps.Paths[kingSquare.Index][pinner.ToSquareIndex()]; var squarePinnedByThisPiece = path & potentialPins; if (squarePinnedByThisPiece == 0) { continue; } pinnedSquares |= squarePinnedByThisPiece; var pushPath = path & pushMask; var capturePath = path & captureMask; var pieceType = workspace.RelativeBitBoard.GetPieceType(squarePinnedByThisPiece); switch (pieceType) { case PieceType.Pawn when !diagonal: AddIndividualPawnPushes(workspace, squarePinnedByThisPiece.ToSquare(), pushPath); break; case PieceType.Pawn when diagonal: AddIndividualPawnCaptures(workspace, squarePinnedByThisPiece.ToSquare(), pushPath, capturePath); break; case PieceType.Rook: AddIndividualRayMoves(workspace, squarePinnedByThisPiece.ToSquare(), PieceType.Rook, PieceType.Rook, pushPath | capturePath); break; case PieceType.Bishop: AddIndividualRayMoves(workspace, squarePinnedByThisPiece.ToSquare(), PieceType.Bishop, PieceType.Bishop, pushPath | capturePath); break; case PieceType.Queen: AddIndividualQueenMoves(workspace, squarePinnedByThisPiece.ToSquare(), pushPath | capturePath); break; } } return(pinnedSquares); }
public void ToList_4_Correct() { SquareFlag square = SquareFlag.H1 | SquareFlag.A5 | SquareFlag.E6 | SquareFlag.H8; var asList = square.ToList(); Assert.Collection( asList, item => Assert.Equal(SquareFlag.H1, item), item => Assert.Equal(SquareFlag.A5, item), item => Assert.Equal(SquareFlag.E6, item), item => Assert.Equal(SquareFlag.H8, item)); }
private void GenerateAllOccupancyCombinations(int square, SquareFlag occupancyMask, Action <SortedDictionary <int, SquareFlag>, int, SquareFlag> addToList, SortedDictionary <int, SquareFlag> dictionary) { var squares = new List <SquareFlag>(); foreach (var occupancyMaskSquare in occupancyMask.ToList()) { squares.Add(occupancyMaskSquare); } var numSquares = squares.Count(); // Generate each 'length' combination for (var combinationLength = 0; combinationLength <= numSquares; ++combinationLength) { CombinationUtil(squares, square, new SquareFlag[numSquares], 0, numSquares - 1, 0, combinationLength, addToList, dictionary); } }
private void ToOrdinaryMoves(MoveGenerationWorkspace workspace, PieceType pieceType, Square fromSquare, SquareFlag attackableSquares) { var attackableSquaresAsList = attackableSquares.ToList(); foreach (var toSquare in attackableSquaresAsList) { if (!workspace.RelativeBitBoard.OpponentSquares.HasFlag(toSquare)) { workspace.NonCaptureMoveBuffer.Add(MoveBuilder.Create(workspace.Colour, pieceType, fromSquare, toSquare.ToSquare(), PieceType.None, MoveType.Ordinary, workspace.NumCheckers)); continue; } var capturePieceType = workspace.RelativeBitBoard.GetPieceType(toSquare); workspace.CaptureMoveBuffer.Add(MoveBuilder.Create(workspace.Colour, pieceType, fromSquare, toSquare.ToSquare(), capturePieceType, MoveType.Ordinary, workspace.NumCheckers)); } }
private void AddPieces(Colour colour, PieceType pieceType, SquareFlag squares, int gridSize) { var dropShadowEffect = new DropShadowEffect { BlurRadius = 2, Direction = 315, Opacity = 0.5, ShadowDepth = 2 }; foreach (var square in squares.ToList()) { var squareIndex = square.ToSquareIndex(); var pieceName = pieceType.ToString(); var imagePath = $"Images/Icons-40x40-{colour}{pieceName}.png"; var bitmapImage = new BitmapImage(new Uri(imagePath, UriKind.Relative)); var image = new Image { Source = bitmapImage, Width = ImageSizeInPixels, Height = ImageSizeInPixels, Opacity = 0.95, Effect = dropShadowEffect }; BoardCanvas.Children.Add(image); image.Visibility = Visibility.Visible; var rank = this.IndexToRank(squareIndex); var file = this.IndexToFile(squareIndex); var xy = this.GetScreenPosition(GridSizeInPixels, rank, file); Canvas.SetLeft(image, xy.X); Canvas.SetTop(image, xy.Y); } }