Exemplo n.º 1
0
        public int ScoreBoard(ulong board)
        {
            int score = 0;

            for (int i = 0; i < 16; i++)
            {
                int value = BitShifter.GetNibbleFromIndex(i, board);
                if (value > 1)
                {
                    score += (value) * (1 << value);
                }
            }
            int mono        = 0;
            int cornerTiles = 0;

            for (int i = 0; i < 16; i++)
            {
                var edges = GetEdgesFromId(i).ToArray();
                if (edges.Length == 2)
                {
                    cornerTiles += BitShifter.GetNibbleFromIndex(i, board);
                }
                foreach (var e in edges)
                {
                    mono += Math.Abs(BitShifter.GetNibbleFromIndex(i, board) - BitShifter.GetNibbleFromIndex(e, board));
                }
            }
            int spaces = BitShifter.CountSpaces(board);
            var result = (int)(score * ScoreW - mono * MonoW + cornerTiles * CornerW + spaces * SpaceW);

            return(result > 0 ? result : 0);
        }