public override List <PieceMove> GetMovesMask(Board board, Point position) { List <PieceMove> ret = new List <PieceMove>(); BitBoard locked = new BitBoard(); board[position] = null; board.ForEach( (Piece piece) => piece.GetColour() != GetColour(), (Point point) => locked |= board[point].GetSeen(board, point)); board[position] = this; IEnumerable <Point> kingMoves = GetSeen(board, position).GetAllSet().Where(kingMove => !locked[kingMove] && board[kingMove]?.GetColour() != GetColour()); foreach (Point kingMove in kingMoves) { ret.Add(new PieceMove(new Vector(position, kingMove), board[kingMove] == null? MoveType.Move : MoveType.Capture)); } if (!board.GetHistory().Any(historicalMove => historicalMove.p2 == position)) { foreach (CastelingMask mask in castelingMasks) { if (!board.GetHistory().Any(historicalMove => historicalMove.p1 == new Point(mask.rookInitial, position.y)) && Extentions.Extentions.Enumerate(position.x, mask.kingFinal).All(kingMoveX => board.FindAttacks(GetColour(), new Point(kingMoveX, position.y)).Count() == 0) && Extentions.Extentions.Enumerate(mask.rookInitial, position.x).SubArray(1, 1).All(movedThrough => board[movedThrough, position.y] == null)) { ret.Add(new PieceMove(new Vector(position, new Point(mask.kingFinal, position.y)), new Vector[] { new Vector(new Point(mask.rookInitial, position.y), new Point(mask.rookFinal, position.y)) }, MoveType.Move)); } } } return(ret); }
public static BitBoard operator |(BitBoard l, BitBoard r) { BitBoard ret = new BitBoard(); Board.ForEach(point => { if (l[point] || r[point]) { ret[point] = true; } }); return(ret); }
public List <Point> GetAllSet() { List <Point> ret = new List <Point>(); Board.ForEach( (Point p) => { if (this[p]) { ret.Add(p); } }); return(ret); }
public Renderer(Grid grid, Mouse mouse) { grid.RowDefinitions.Clear(); grid.ColumnDefinitions.Clear(); grid.Children.Clear(); for (int i = 0; i < 8; i++) { grid.RowDefinitions.Add(new RowDefinition()); grid.ColumnDefinitions.Add(new ColumnDefinition()); } Board.ForEach( (point) => { cells[point.x, point.y] = new Cell(new Point(point.x, point.y), mouse); grid.Children.Add(cells[point.x, point.y]); }); Icons.RegisterListener(RenderIcons); }