public void RotateClockWise(int times) { var finalMatrix = Figures; for (int i = 0; i < times; i++) { var newMatrix = new TrackingFieldState[finalMatrix.GetLength(1), finalMatrix.GetLength(0)]; int newRow = 0; for (int oldColumn = finalMatrix.GetLength(1) - 1; oldColumn >= 0; oldColumn--) { var newColumn = 0; for (int oldRow = 0; oldRow < finalMatrix.GetLength(0); oldRow++) { newMatrix[newRow, newColumn] = finalMatrix[oldRow, oldColumn]; newColumn++; } newRow++; } finalMatrix = newMatrix; } Figures = finalMatrix; }
/// <summary> /// Gets tracking states of given chessboard /// </summary> /// <returns>Tracking states of given chessboard</returns> public TrackingState GetTrackingStates() { var figures = new TrackingFieldState[8, 8]; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { if (Figures[x, y] == null) { figures[x, y] = TrackingFieldState.None; } else if (Figures[x, y].Color == PlayerColor.White) { figures[x, y] = TrackingFieldState.White; } else { figures[x, y] = TrackingFieldState.Black; } } } var state = new TrackingState(figures); return(state); }
/// <summary> /// Performs vertical flip of tracking state /// </summary> public void VerticalFlip() { var newMatrix = new TrackingFieldState[Figures.GetLength(1), Figures.GetLength(0)]; for (int column = 0; column < 0; column++) { for (int row = 0; row < Figures.GetLength(0); row++) { newMatrix[row, column] = Figures[row, (Figures.GetLength(0) - 1) - column]; } } Figures = newMatrix; }
/// <summary> /// Decides which fields contain figure and decides its color /// -> if there are more points over field than threshold, the figure is considered as present /// -> color is decided by thresholding average fitness of points over field /// </summary> /// <param name="inputColorsData">Colors of points over individual fields</param> /// <param name="userParameters">User defined parameters</param> /// <returns>Tracking state of chessboard</returns> private TrackingState DetectPresenceAndColorOfFiguresOnFields(List <Point2DWithColor>[,] inputColorsData, TrackingState gameTrackingState, UserDefinedParameters userParameters) { var figures = new TrackingFieldState[8, 8]; for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { int presenceInfluence = 0; float colorInfluence = 0; if (gameTrackingState != null) { presenceInfluence = gameTrackingState.Figures[x, y] != TrackingFieldState.None ? userParameters.GameStateInfluenceOnPresence : 0; colorInfluence = (userParameters.GameStateInfluenceOnColor / 100f) * (gameTrackingState.Figures[x, y] == TrackingFieldState.None ? 0 : gameTrackingState.Figures[x, y] == TrackingFieldState.White ? 1 : -1 ); } if ((inputColorsData[x, y].Count + presenceInfluence) < userParameters.NumberOfPointsIndicatingFigure) { figures[x, y] = TrackingFieldState.None; } else { if (gameTrackingState != null && inputColorsData[x, y].Count == 0) { figures[x, y] = gameTrackingState.Figures[x, y]; continue;; } double averageBrightnessInField; if (userParameters.IsFiguresColorMetricExperimental) { averageBrightnessInField = inputColorsData[x, y].Sum(f => 1 - Math.Pow(-2.5f * (Color.FromArgb(f.Color.R, f.Color.G, f.Color.B).CustomBrightness() - 0.5f), 2) + colorInfluence) / inputColorsData[x, y].Count; } else { averageBrightnessInField = inputColorsData[x, y].Sum(f => Color.FromArgb(f.Color.R, f.Color.G, f.Color.B).GetBrightness() + colorInfluence) / inputColorsData[x, y].Count; } figures[x, y] = averageBrightnessInField > 0.5 + userParameters.ColorCalibrationAdditiveConstant ? TrackingFieldState.White : TrackingFieldState.Black; } } } return(new TrackingState(figures)); }