示例#1
0
        public static void Precalculate(long diamonds)
        {
            NumPoss[1] = 1;
            AllPos.Add(1, new Dictionary <BoardPos, double>());
            BoardPos pos = new BoardPos();

            pos.AddDiamond(0, 0);
            AllPos[1].Add(pos, 1);

            for (long diamond = 2; diamond <= diamonds; diamond++)
            {
                AllPos.Add(diamond, new Dictionary <BoardPos, double>());
                foreach (var oldPos in AllPos[diamond - 1])
                {
                    var newPositions = GetNewPositions(oldPos);
                    foreach (var newPos in newPositions)
                    {
                        if (!AllPos[diamond].ContainsKey(newPos))
                        {
                            AllPos[diamond][newPos] = 0;
                        }
                        AllPos[diamond][newPos] += oldPos.Value / (double)newPositions.Count;
                    }
                }
            }
        }
示例#2
0
        public static HashSet <BoardPos> GetNewPositions(Pos diamondPos, BoardPos oldPos)
        {
            HashSet <BoardPos> positions = new HashSet <BoardPos>();

            if (diamondPos.Y == 0)
            {
                var newPos = new BoardPos(oldPos);
                newPos.Diamonds.Add(diamondPos);
                positions.Add(newPos);
            }
            else
            {
                Pos  possiblePos;
                bool blockedBoth = true;
                possiblePos = new Pos(diamondPos.X - 1, diamondPos.Y - 1);
                if (!oldPos.Diamonds.Contains(possiblePos))
                {
                    blockedBoth = false;
                    positions.UnionWith(GetNewPositions(possiblePos, oldPos));
                }
                possiblePos = new Pos(diamondPos.X + 1, diamondPos.Y - 1);
                if (!oldPos.Diamonds.Contains(possiblePos))
                {
                    positions.UnionWith(GetNewPositions(possiblePos, oldPos));
                    blockedBoth = false;
                }
                if (blockedBoth)
                {
                    var newPos = new BoardPos(oldPos);
                    newPos.Diamonds.Add(diamondPos);
                    positions.Add(newPos);
                }
            }

            return(positions);
        }
示例#3
0
 public BoardPos(BoardPos other)
 {
     Diamonds = new HashSet <Pos>(other.Diamonds);
 }
示例#4
0
        public static HashSet <BoardPos> GetNewPositions(KeyValuePair <BoardPos, double> oldPos)
        {
            BoardPos pos = new BoardPos(oldPos.Key);

            return(GetNewPositions(new Pos(0, pos.Diamonds.Where(x => x.X == 0).Max(x => x.Y) + 2), pos));
        }