private void RecalculateBoardPieces() { object bitmapLocker = new object(); object locker = new object(); Parallel.For(0, 64, i => { int x = i % 8; int y = i / 8; Bitmap bitmap; lock (bitmapLocker) { bitmap = this.boardImage.Clone() as Bitmap; } var matches = BoardPiece.FindMatches(bitmap, x, y); var closestMatch = matches.GetClosestMatch().BoardPiece; lock (locker) { this.boardPositions[y, x].SetPiece(closestMatch, y, x); } }); }
public bool Equals(BoardPiece other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.RootBoardPiece, RootBoardPiece)); }
private void RectangleOnMouseUp(object sender, MouseButtonEventArgs e) { if (this.imgBoardBitmap.Source == null) { return; } var rectangle = (System.Windows.Shapes.Rectangle)sender; var name = rectangle.Name; var rectangleX = Convert.ToInt32(name.Substring(2, 1)) - 1; var rectangleY = Convert.ToInt32(name.Substring(1, 1)) - 1; this.highlightedPiece = new Point(rectangleX, rectangleY); imageHighlight.Stroke = Brushes.Red; imageHighlight.StrokeThickness = 3; imageHighlight.Fill = Brushes.Transparent; imageHighlight.Visibility = Visibility.Visible; var bitmapTopLeftY = Canvas.GetTop(imgBoardBitmap) + (rectangleY * BoardPiece.Height); var bitmapTopLeftX = Canvas.GetLeft(this.imgBoardBitmap) + (rectangleX * BoardPiece.Width); Canvas.SetTop(imageHighlight, bitmapTopLeftY); Canvas.SetLeft(imageHighlight, bitmapTopLeftX); var matches = BoardPiece.FindMatches(this.board.BoardImage, rectangleX, rectangleY); var closestMatch = matches.GetClosestMatch(); listBox1.Items.Clear(); foreach (var match in matches) { bool isClosest = closestMatch.BoardPiece.Name == match.BoardPiece.Name; var listBoxMatch = new ListBoxMatch(match, isClosest); listBox1.Items.Add(listBoxMatch); if (isClosest) { listBox1.SelectedItem = listBoxMatch; } } this.ListBox1_OnPreviewMouseUp(listBox1, null); }
public MatchPair(MatchData weight, BoardPiece piece) { Weight = weight; BoardPiece = piece; }
public void SetPiece(BoardPiece piece, int arrayY, int arrayX) { Piece = piece; ArrayPosition = new Point(arrayX, arrayY); }