public Chip(int[,] chipMatrix) { if (chipMatrix.GetLength(0) != MatrixSize || chipMatrix.GetLength(1) != MatrixSize) { throw new Exception($"not {MatrixSize}x{MatrixSize} matrix"); } this._matrix = chipMatrix; ChipStates = new List <ChipState>(); for (int j = 0; j < 2; j++) { YMirror(); for (int k = 0; k < 4; k++) { Rotate90(); Normalize(); var newState = new ChipState(_matrix, GetFoot()); if (!ChipStates.Exists(c => c.AreEqual(newState))) { ChipStates.Add(newState); newState.Print(); } } } }
public bool AreEqual(ChipState b) { for (int x = 0; x < Chip.MatrixSize; x++) { for (int y = 0; y < Chip.MatrixSize; y++) { if (this.Matrix[x, y] != b.Matrix[x, y]) { return(false); } } } return(true); }
public bool TryPut(ChipState chip, out ChipPlace chipPlace) { chipPlace = null; var footPos = chip.Foot; var xOffset = CurrentTestPosition.X - footPos.X; var yOffset = CurrentTestPosition.Y - footPos.Y; bool test = true; for (int x = 0; x < Chip.MatrixSize; x++) { for (int y = 0; y < Chip.MatrixSize; y++) { var posx = xOffset + x; var posy = yOffset + y; if (chip.Matrix[x, y] != 0 && (posx < 0 || posx >= XSize || posy < 0 || posy >= YSize || Matrix[xOffset + x, yOffset + y] != 0)) { test = false; break; } } } if (test) { chipPlace = new ChipPlace { ChipPosition = new Position { X = CurrentTestPosition.X, Y = CurrentTestPosition.Y }, Mark = chipMark }; for (int x = 0; x < Chip.MatrixSize; x++) { for (int y = 0; y < Chip.MatrixSize; y++) { if (chip.Matrix[x, y] != 0) { Matrix[xOffset + x, yOffset + y] = chipMark; } } } chipMark++; MoveToNextPosition(); } return(test); }