protected bool TryWin(Place N) { bool flag = false; int l = N.Lines.Length; int i = 0; while (i < l && flag == false) { flag = Rows[N.Lines[i]].IsWon(); if (flag == true) { WinningRow = Rows[N.Lines[i]].ConvertRowToInt(); } i++; } return flag; }
private Comb[] Rows; //Все возможные линейные комбинации точек #endregion Fields #region Constructors public Game() { // started = true; finished = false; Pl1 = new Player(1); Pl2 = new Player(2); Cube = new Place[4, 4, 4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { int num = (i + 1) * 100 + (j + 1) * 10 + (k + 1); Cube[i, j, k] = new Place(num); if (j == 0) { Cube[i, j, k].SetAvailable(); } } } } //==============инициализация рядов===================== Rows = new Comb[76]; //--------------XY.Init--------------------------------- int rownum = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { Rows[rownum] = new Comb(); for (int k = 0; k < 4; k++) { Rows[rownum].Row[k] = (i + 1) * 100 + (j + 1) * 10 + (k + 1); Cube[i, j, k].WriteLine(rownum); } rownum++; } } //--------------XZ.Init--------------------------------- for (int i = 0; i < 4; i++) { for (int k = 0; k < 4; k++) { Rows[rownum] = new Comb(); for (int j = 0; j < 4; j++) { Rows[rownum].Row[j] = (i + 1) * 100 + (j + 1) * 10 + (k + 1); Cube[i, j, k].WriteLine(rownum); } rownum++; } } //--------------YZ.Init--------------------------------- for (int j = 0; j < 4; j++) { for (int k = 0; k < 4; k++) { Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (i + 1) * 100 + (j + 1) * 10 + (k + 1); Cube[i, j, k].WriteLine(rownum); } rownum++; } } //-------------XZ.diagonal.Init------------------------- for (int j = 0; j < 4; j++) { Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (i + 1) * 100 + (j + 1) * 10 + (i + 1); Cube[i, j, i].WriteLine(rownum); } rownum++; } for (int j = 0; j < 4; j++) { Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (i + 1) * 100 + (j + 1) * 10 + (3 - i + 1); Cube[i, j, 3 - i].WriteLine(rownum); } rownum++; } //-------------XY.diagonal.Init------------------------- for (int j = 0; j < 4; j++) { Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (i + 1) * 100 + (i + 1) * 10 + (j + 1); Cube[i, i, j].WriteLine(rownum); } rownum++; } for (int j = 0; j < 4; j++) { Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (i + 1) * 100 + (3 - i + 1) * 10 + (j + 1); Cube[i, 3 - i, j].WriteLine(rownum); } rownum++; } //-------------YZ.diagonal.Init------------------------- for (int j = 0; j < 4; j++) { Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (j + 1) * 100 + (i + 1) * 10 + (i + 1); Cube[j, i, i].WriteLine(rownum); } rownum++; } for (int j = 0; j < 4; j++) { Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (j + 1) * 100 + (3 - i + 1) * 10 + (i + 1); Cube[j, 3 - i, i].WriteLine(rownum); } rownum++; } //-------------XYZ.diagonal.Init------------------------- Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (i + 1) * 100 + (i + 1) * 10 + (i + 1); Cube[i, i, i].WriteLine(rownum); } rownum++; Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (3 - i + 1) * 100 + (i + 1) * 10 + (i + 1); Cube[3 - i, i, i].WriteLine(rownum); } rownum++; Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (i + 1) * 100 + (3 - i + 1) * 10 + (i + 1); Cube[i, 3 - i, i].WriteLine(rownum); } rownum++; Rows[rownum] = new Comb(); for (int i = 0; i < 4; i++) { Rows[rownum].Row[i] = (i + 1) * 100 + (i + 1) * 10 + (3 - i + 1); Cube[i, i, 3 - i].WriteLine(rownum); } //==========конец инициализации=========================== Pl1.Turn = true; }