Beispiel #1
0
        private static CamelPositions ConvertGameStateToCamelPosition(GameState gameState)
        {
            var pos = new CamelPositions()
            {
            };

            pos.Location = gameState.Camels.OrderBy(x => (int)x.CamelColor).Select(x => x.Location).ToArray();
            pos.Height   = gameState.Camels.OrderBy(x => (int)x.CamelColor).Select(x => x.Height).ToArray();
            pos.Money    = new int[16];
            return(pos);
        }
Beispiel #2
0
        private static List <Camel> ConvertCamelPositionToCamels(CamelPositions positions)
        {
            var camels = GetAllCamelColors().Select(x => new Camel()
            {
                CamelColor = x
            }).ToList();

            for (var i = 0; i < positions.Location.Length; i++)
            {
                camels[i].Location = positions.Location[i];
                camels[i].Height   = positions.Height[i];
            }

            return(camels);
        }
Beispiel #3
0
        private static List <CamelPositions> GetAllPossibleCamelPositions(CamelPositions initialPosition, CamelColor[] colors, int[] traps, int depth, bool includeAll)
        {
            var positions = new List <CamelPositions>();

            if (initialPosition.Location.Any(x => x > 15))
            {
                positions.Add(initialPosition);
                return(positions);
            }

            foreach (var dice in colors)
            {
                for (var i = 1; i <= 3; i++)
                {
                    var pos = FastCamelMove(initialPosition, (int)dice, i, traps);

                    if (colors.Length == 1 || pos.Location.Any(x => x > 15))
                    {
                        positions.Add(pos);
                        continue;
                    }

                    if (includeAll || depth == 0)
                    {
                        positions.Add(pos);
                    }

                    if (depth > 0)
                    {
                        var remaining = colors.Where(x => x != dice).ToArray();
                        var other     = GetAllPossibleCamelPositions(pos, remaining, traps, depth - 1, includeAll);
                        positions.AddRange(other);
                    }
                }
            }

            return(positions);
        }
Beispiel #4
0
        private static CamelPositions FastCamelMove(CamelPositions initialPosition, int dice, int value, int[] traps)
        {
            var pos = new CamelPositions()
            {
                Location = initialPosition.Location.ToArray(),
                Height   = initialPosition.Height.ToArray(),
                Money    = initialPosition.Money.ToArray()
            };

            var from       = pos.Location[dice];
            var fromHeight = pos.Height[dice];
            var toSpace    = from + value;
            var move       = 1;

            if (traps[toSpace] != 0)
            {
                pos.Money[toSpace]++;
                if (traps[toSpace] < 1)
                {
                    move = -1;
                }
                toSpace += move;
            }

            var n = 0;
            var m = 0;

            for (var i = 0; i < 5; i++)
            {
                if (pos.Location[i] == from && pos.Height[i] >= fromHeight)
                {
                    n++;
                }
            }

            for (var x = from + 1; x < toSpace; x++)
            {
                for (var i = 0; i < 5; i++)
                {
                    if (pos.Location[i] == x)
                    {
                        pos.Height[i] -= n;
                        m++;
                    }
                }
            }

            if (move == 1)
            {
                for (var i = 0; i < 5; i++)
                {
                    if (pos.Location[i] == toSpace)
                    {
                        pos.Height[i] -= n;
                        m++;
                    }
                }
            }

            for (var i = 0; i < 5; i++)
            {
                if (pos.Location[i] == from && pos.Height[i] >= fromHeight)
                {
                    pos.Location[i] = toSpace;
                    pos.Height[i]  += m;
                }
            }

            return(pos);
        }