public ValidPosition MakeTurn() { ValidPosition bestPosition = this; Predicate <Position> betterScore = p => p.Score > bestPosition.Score; for (int i = 0; i < 2 * COLUMN_COUNT - 1; ++i) { for (int j = 0; j < 2 * SHORT_COLUMN_LENGTH - 1; ++j) { var point = new RotationCenter(i, j); var position = PositionBuilder.Generate(this, point, true).MakeTurn().Build(); if (betterScore(position)) { bestPosition = position; } position = PositionBuilder.Generate(this, point, false).MakeTurn().Build(); if (betterScore(position)) { bestPosition = position; } } } return(bestPosition); }
public static PositionBuilder Generate(ValidPosition position, RotationCenter point, bool clockwise) { var shortColumns = position.ShortColumns; var longColumns = position.LongColumns; point.Rotate(clockwise, shortColumns, longColumns); return(new PositionBuilder(shortColumns, longColumns, position.Score)); }
protected List <RotationCenter>[] GetClusterCenters() { var clusterCenters = new List <RotationCenter> [MAX_NUMBER + 1]; for (int c = 0; c < MAX_NUMBER + 1; ++c) { clusterCenters[c] = new List <RotationCenter>(); } for (int i = 0; i < 2 * COLUMN_COUNT - 1; ++i) { for (int j = 0; j < 2 * SHORT_COLUMN_LENGTH - 1; ++j) { var point = new RotationCenter(i, j); int value; if (point.HasEqualCells(out value, shortColumns, longColumns)) { clusterCenters[value].Add(point); } } } return(clusterCenters); }