Exemplo n.º 1
0
        public GameUnit(Unit unit, UnitPosition unitPosition)
        {
            Unit = unit;
            UnitPosition = unitPosition;

            absolutePoints = new Lazy<Point[]>(() => Unit.Points.Select(p => p.Rotate(UnitPosition.RotationCount, Unit.PivotPoint).Move(Unit.PivotPoint, UnitPosition.PivotLocation)).ToArray());
            orderedPoints = new Lazy<Point[]>(() => GetAbsolutePoints().OrderBy(x => x.Col).ThenBy(x => x.Row).Concat(new[] { UnitPosition.PivotLocation }).ToArray());
            hashCode = new Lazy<int>(() => GetOrderedPoints().Select((x, i) => ((x.Row * 1) ^ (x.Col * 3571)) * i).Aggregate(0, (x, y) => x ^ y));
        }
Exemplo n.º 2
0
        private Profit GetScore(UnitPosition position, Game game)
        {
            var unit = game.Current.Unit;
            var points = new GameUnit(unit, position).GetAbsolutePoints();
            var board = game.Board.Clone();

            foreach (var point in points)
            {
                board.Fill(point);
            }

            var diverScore = 0;
            for (int i = 0; i < board.Height; i++)
            {
                for (int j = 0; j < board.Width; j++)
                {
                    if (board.Field[i][j] == CellState.Busy)
                    {
                        diverScore += i * i;
                    }
                }
            }

            var busyCount = 0;
            for (var i = 0; i < board.Height; i++)
            {
                if (board.Field[i].All(x => x == CellState.Busy))
                {
                    busyCount++;
                }
            }

            return new Profit
            {
                BusyRows = busyCount,
                DiverScore = diverScore,
                DensityScore = CalcDensity(board, points)
            };
        }