public void PreprocessMain(ReplayGamestate gamestate, MapMetaData mapmeta, EncounterDetectionData nedData)
 {
     //foreach (var round in gamestate.match.rounds)
     //    foreach (var tick in round.ticks)
     //        foreach (var tevent in tick.tickevents)
     //            HashGridcells(tevent);
 }
        /// <summary>
        /// Initializes the generator or resets it if a demo was parser before
        /// </summary>
        public void InitializeGenerator()
        {
            Match        = new Match();
            CurrentRound = new Round();
            CurrentTick  = new Tick();
            GameState    = new ReplayGamestate();

            alreadytracked = new List <Player>();

            hasMatchStarted = false;
            hasRoundStarted = false;
            hasFreeezEnded  = false;

            positioninterval = ptask.PositionUpdateInterval;

            tick_id  = 0;
            round_id = 0;

            tickcount = 0;

            InitWatch();

            //Init lists
            Match.Rounds           = new List <Round>();
            CurrentRound.ticks     = new List <Tick>();
            CurrentTick.tickevents = new List <Event>();
        }
 public void CleanUp()
 {
     GetJSONParser().StopParser();
     ptask     = null;
     GameState = null;
     GC.Collect();
     GC.WaitForPendingFinalizers();
 }
Example #4
0
        /// <summary>
        /// Dumps gamestate in a string
        /// </summary>
        /// <param name="gs"></param>
        /// <param name="prettyjson"></param>
        public string DumpJSONString(ReplayGamestate gs, bool prettyjson)
        {
            Formatting f = Formatting.None;

            if (prettyjson)
            {
                f = Formatting.Indented;
            }
            return(JsonConvert.SerializeObject(gs, f));
        }
Example #5
0
        /// <summary>
        /// Dumps the Gamestate in prettyjson or as one-liner(default)
        /// </summary>
        /// <param name="gs"></param>
        /// <param name="prettyjson"></param>
        public void DumpJSONFile(ReplayGamestate gs, bool prettyjson)
        {
            Formatting f = Formatting.None;

            if (prettyjson)
            {
                f = Formatting.Indented;
            }

            outputStream.Write(JsonConvert.SerializeObject(gs, settings));
        }
Example #6
0
        public void PreprocessData(ReplayGamestate gamestate, MapMetaData mapmeta, EncounterDetectionData edData)
        {
            // Load and create standard data
            base.PreprocessMain(gamestate, mapmeta, edData);

            // Custom preprocessing for your game

            #region Collect positions for preprocessing and build hashtables of events

            var           positions      = new HashSet <Point3D>();
            List <double> hurt_ranges    = new List <double>();
            List <double> support_ranges = new List <double>();

            foreach (var round in gamestate.Match.Rounds)
            {
                foreach (var tick in round.ticks)
                {
                    foreach (var gevent in tick.getTickevents())
                    {
                        switch (gevent.GameeventType) //Build hashtables with events we need later
                        {
                        case "player_hurt":
                            PlayerHurt ph = (PlayerHurt)gevent;
                            // Remove Z-Coordinate because we later get keys from clusters with points in 2D space -> hashtable needs keys with 2d data
                            edData.Hit_hashtable[ph.Actor.Position.ResetZ()] = ph.Victim.Position.ResetZ();
                            hurt_ranges.Add(DistanceFunctions.GetEuclidDistance3D(ph.Actor.Position, ph.Victim.Position));
                            continue;

                        case "player_killed":
                            PlayerKilled pk = (PlayerKilled)gevent;
                            edData.Hit_hashtable[pk.Actor.Position.ResetZ()] = pk.Victim.Position.ResetZ();
                            hurt_ranges.Add(DistanceFunctions.GetEuclidDistance3D(pk.Actor.Position, pk.Victim.Position));

                            if (pk.Assister != null)
                            {
                                edData.DirectAssist_hashtable[pk.Actor.Position.ResetZ()] = pk.Assister.Position.ResetZ();
                                support_ranges.Add(DistanceFunctions.GetEuclidDistance3D(pk.Actor.Position, pk.Assister.Position));
                            }
                            continue;
                        }

                        foreach (var player in gevent.getPlayers())
                        {
                            var vz = player.Velocity.VZ;
                            if (vz == 0) //If player is standing thus not experiencing an acceleration on z-achsis -> TRACK POSITION
                            {
                                positions.Add(player.Position);
                            }
                            else
                            {
                                positions.Add(player.Position.ChangeZ(-Player.CSGO_PLAYERMODELL_JUMPHEIGHT)); // Player jumped -> Z-Value is false -> correct with jumpheight
                            }
                        }
                    }
                }
            }
            #endregion

            Console.WriteLine("\nRegistered Positions for Sightgraph: " + positions.Count);
            Console.WriteLine("\nRegistered Hits: " + edData.Hit_hashtable.Count);

            // Generate Map with a constructor
            edData.Map = SimpleMapConstructor.CreateMap(mapmeta, positions.ToList());

            if (support_ranges.Count != 0)
            {
                edData.ATTACKRANGE_AVERAGE = hurt_ranges.Average();
            }
            if (support_ranges.Count != 0)
            {
                edData.SUPPORTRANGE_AVERAGE = support_ranges.Average();
            }

            // Generate Hurteventclusters
            // Keys of the hashtable are attacker positions, ordering defines a function on how to order the data before performing LEADER
            Func <Point3DDataPoint[], Point3DDataPoint[]> ordering = ops => ops.OrderBy(p => p.clusterPoint.X).ThenBy(p => p.clusterPoint.Y).ToArray();
            var playerhurtattackerpositions = edData.Hit_hashtable.Keys.Cast <Point3D>();
            var wrappedphpositions          = new List <Point3DDataPoint>(); // Wrapp Point3D to execute Clustering
            playerhurtattackerpositions.ToList().ForEach(p => wrappedphpositions.Add(new Point3DDataPoint(p)));

            var leader           = new LEADER <Point3DDataPoint>((float)edData.ATTACKRANGE_AVERAGE, wrappedphpositions.ToArray(), ordering);
            var attackerclusters = new List <PlayerHurtCluster>();

            foreach (var cluster in leader.CreateClusters())
            {
                var extractedpos = new List <Point3D>();
                cluster.ClusterData.ForEach(data => extractedpos.Add(data.clusterPoint));
                var attackcluster = new PlayerHurtCluster(extractedpos.ToArray());
                attackcluster.CalculateClusterRanges(edData.Hit_hashtable);
                attackerclusters.Add(attackcluster);
            }
            edData.Clusters_PlayerHurt = attackerclusters.ToArray();
        }
 public void PreprocessData(ReplayGamestate gamestate, MapMetaData map, EncounterDetectionData edData)
 {
     throw new NotImplementedException();
 }