Beispiel #1
0
        public void BuildVirtualPlayers()
        {
            Console.Error.Write("BuildVirtualMaps");
            int playerId = 10;
            var yNumber  = 0;

            Map.Maze2D.ForEach(row =>
            {
                var xNumber = 0;
                row.ForEach(c =>
                {
                    var isEmpty = c.CellType == CellType.Empty;
                    if (isEmpty)
                    {
                        var _enemy = new Player {
                            PlayerId = playerId, CurrentPosition = new Position {
                                X = xNumber, Y = yNumber
                            }, PlayerType = PlayerType.Virtual
                        };
                        var _me = new Player {
                            PlayerId = playerId, CurrentPosition = new Position {
                                X = xNumber, Y = yNumber
                            }, PlayerType = PlayerType.Virtual
                        };

                        EnemyVirtualPlayers.Add(_enemy);
                        MeVirtualPlayers.Add(_me);
                        playerId++;
                    }
                    xNumber++;
                });
                yNumber++;
            });
            Console.Error.WriteLine($" -> Done with: {EnemyVirtualPlayers.Count}");
        }
Beispiel #2
0
        private void UseSilence(Instruction instruction)
        {
            // Utilisation du silence en défensif
            var virtualMeInGame = MeVirtualPlayers.Count(x => x.StillInGame);

            if (virtualMeInGame < 10)
            {
                var d = new List <Direction> {
                    Direction.Est, Direction.West, Direction.None, Direction.South
                };

                var choices = new Dictionary <Direction, List <int> > {
                    { Direction.Est, Enumerable.Range(1, 4).ToList() },
                    { Direction.North, Enumerable.Range(1, 4).ToList() },
                    { Direction.West, Enumerable.Range(1, 4).ToList() },
                    { Direction.South, Enumerable.Range(1, 4).ToList() }
                };

                var result = new Dictionary <Direction, int>
                {
                    { Direction.Est, 0 },
                    { Direction.West, 0 },
                    { Direction.North, 0 },
                    { Direction.South, 0 }
                };

                int xOffset = 0;
                int yOffset = 0;

                foreach (var _d in choices)
                {
                    xOffset = _d.Key.GetOffset(OffsetType.XOffset);
                    yOffset = _d.Key.GetOffset(OffsetType.YOffset);

                    foreach (var distance in _d.Value)
                    {
                        var isValid = Me.CurrentPosition.IsValidPosition(Map, yOffset * distance, xOffset * distance, true);
                        if (isValid)
                        {
                            result[_d.Key] = distance;
                        }
                        else
                        {
                            break;
                        }
                    }
                    ;
                }

                var max = result.ToList().OrderByDescending(x => x.Value).First();

                xOffset = max.Key.GetOffset(OffsetType.XOffset);
                yOffset = max.Key.GetOffset(OffsetType.YOffset);
                Console.Error.Write("UseSilence setting visited: [");
                for (int i = 1; i <= max.Value; i++)
                {
                    Console.Error.Write($" {Map[Me.CurrentPosition.X + xOffset * i, Me.CurrentPosition.Y + yOffset * i].Position},");
                    Map[Me.CurrentPosition.X + xOffset * i, Me.CurrentPosition.Y + yOffset * i].Visited = true;
                }
                Console.Error.WriteLine("] => done!");

                instruction.Commands.Add(new Silence {
                    Direction = max.Key, Distance = max.Value
                });
                ResetVirtualPlayer(PlayerType.Me);
            }
        }