public RobotData SaveRobot(List <RobotPartRuntimeObject> robotParts)
    {
        RobotData CurrentRobot;

        CurrentRobot = new RobotData();

        if (robotParts != null)
        {
            CurrentRobot.robotDataEntries = new List <RobotDataEntry>();

            foreach (RobotPartRuntimeObject robotPartRuntimeObject in robotParts)
            {
                List <float>  floatPartSettings  = new List <float>();
                List <bool>   boolPartSettings   = new List <bool>();
                List <string> stringPartSettings = new List <string>();

                if (robotPartRuntimeObject.robotPart.robotPartType == RobotPartType.WheelPart)
                {
                    boolPartSettings.Add(robotPartRuntimeObject.robotPartGameObject.GetComponent <SimpleWheelController>().GetActivateMotor());
                    boolPartSettings.Add(robotPartRuntimeObject.robotPartGameObject.GetComponent <SimpleWheelController>().GetActivateSteering());
                    boolPartSettings.Add(robotPartRuntimeObject.robotPartGameObject.GetComponent <SimpleWheelController>().GetReverseSpinDirection());
                }
                CurrentRobot.robotDataEntries.Add(new RobotDataEntry(robotPartRuntimeObject.parentIndex, robotPartRuntimeObject.robotPart.robotPartIdentifier, robotPartRuntimeObject.robotPartGameObject.transform.localPosition, robotPartRuntimeObject.robotPartGameObject.transform.localRotation, new RobotDataEntrySettings(floatPartSettings, boolPartSettings, stringPartSettings)));
            }
        }
        else
        {
            CurrentRobot = null;
        }

        return(CurrentRobot);
    }
Exemplo n.º 2
0
        /// <summary>
        /// Method the updates the enemy dictionary based on new scan data for a scanned robot.
        /// </summary>
        /// <param name="scannedRobotEvent">The scanned robot event containing data about the scanned robot.</param>
        private void UpdateEnemyDictionary(ScannedRobotEvent scannedRobotEvent)
        {
            var name = scannedRobotEvent.Name;

            // Check if data entry exists for the scanned robot
            if (enemyDictionary.ContainsKey(name))
            {
                // Data entry exists => Update the current entry with new scanned data
                RobotData scannedRobot = enemyDictionary[name];
                scannedRobot.Update(scannedRobotEvent, this);
            }
            else
            {
                // No data entry exists => Create a new data entry for the scanned robot
                RobotData scannedRobot = new RobotData(scannedRobotEvent, this);
                // Put the new data entry into the enemy dictionary
                enemyDictionary.Add(name, scannedRobot);
            }
            // Change the access order for the robot name, so the name is moved to, or added as the last entry
            if (accessedEnemyList.Contains(name))
            {
                accessedEnemyList.Remove(name);
            }
            accessedEnemyList.Add(name);
        }
Exemplo n.º 3
0
    public void SaveJson()
    {
        //Name = "robot1";
        Robot = GameObject.Find("Robot");
        RobotData robot = new RobotData();

        robot.RobotName = Name;
        robot.version   = "1";
        robot.CraftDate = DateTime.Now;

        Transform objList = Robot.GetComponentInChildren <Transform> ();

        robot.Objs = new GOData[500];

        int i = 0;

        foreach (Transform child in objList)
        {
            Data script = child.gameObject.GetComponent <Data>();
            robot.Objs[i].name          = script.Name;
            robot.Objs[i].LocalPosition = RoundVector3(child.localPosition);
            robot.Objs[i].rotation      = RoundQuaternion(child.rotation);

            i++;
        }

        string jsonstr = JsonUtility.ToJson(robot);

        savePlayerData(jsonstr);

        StartCoroutine("ShotPNG");
    }
Exemplo n.º 4
0
    public void TestRobotData()
    {
        RobotData rd = new RobotData();

        rd = RobotData.LoadFromFile(@"/Users/ritcma2020/Desktop/test.xml");
        RobotData.CreateRobot(rd, Vector3.up * 6, Vector3.zero);
    }
Exemplo n.º 5
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Get inputs.
            string inputRobotName       = "";
            Mesh   inputEndeffectorMesh = new Mesh();
            int    inputRobotID         = 0;
            Plane  inputPlane           = this.defaultPlane;

            if (!DA.GetData(0, ref inputRobotName))
            {
                RobotOptionList();
            }
            DA.GetData(1, ref inputEndeffectorMesh);
            DA.GetData(2, ref inputRobotID);
            DA.GetData(3, ref inputPlane);
            //////////////////////////////////////////////////////
            // Process data.
            inputEndeffectorMesh.Weld(Math.PI);
            EndeffectorData endEffector = new EndeffectorData(MeshUtilities.EncodeMesh(inputEndeffectorMesh));
            RobotData       robot       = new RobotData(inputRobotID, inputRobotName, endEffector, EncodeUtilities.EncodePlane(inputPlane));

            UniversalDebug("Robot Object Created.");
            //////////////////////////////////////////////////////
            // Output.
            DA.SetData(0, robot);
                        #if DEBUG
            DA.SetData(1, this.debugMessages[this.debugMessages.Count - 1]);
                        #endif
        }
Exemplo n.º 6
0
        /// <summary>
        /// Method that updates the direction of the radar based on new scan data for a scanned robot.
        /// </summary>
        /// <param name="scannedRobotEvent">The scanned robot event containing data about the scanned robot.</param>
        private void UpdateScanDirection(ScannedRobotEvent scannedRobotEvent)
        {
            // Gets the name of the scanned robot
            var scannedRobotName = scannedRobotEvent.Name;

            // Change the scanning direction if and only if we have no record for the oldest scanned
            // robot or the scanned robot IS the oldest scanned robot (based on the name) AND the enemy
            // dictionary contains scanned data entries for ALL robots (the size of the enemy dictionary is equal to
            // the number of opponent robots found by calling the getOthers() method).
            if ((oldestScanned == null || scannedRobotName.Equals(oldestScanned.name)) && accessedEnemyList.Count == Others)
            {
                // Get the oldest scanned robot data from our LinkedHashMap, where the first value
                // contains the oldest accessed entry, which is the robot we need to get.
                string    oldestScannedName  = accessedEnemyList[0];
                RobotData oldestScannedRobot = enemyDictionary[oldestScannedName];

                // Get the recent scanned position (x,y) of the oldest scanned robot
                double x = oldestScannedRobot.scannedX;
                double y = oldestScannedRobot.scannedY;

                // Get the heading of our robot
                double ourHeading = RadarHeadingRadians;

                // Calculate the bearing to the oldest scanned robot.
                // The bearing is the delta angle between the heading of our robot and the other robot,
                // which can be a positive or negative angle.
                double bearing = BearingTo(ourHeading, x, y);

                // Update the scan direction based on the bearing.
                // If the bearing is positive, the radar will be moved to the right.
                // If the bearing is negative, the radar will be moved to the left.
                scanDir = bearing;
            }
        }
        public RobotData AcmeSeek(RobotData data, Func <int> getDistence)
        {
            // Get distance from the sensor.
            // Distance is wrapped to "IoMonad" and passed as a parameter
            // This way Seek is a pure function (Haskell way pure as IO is "outsourced")
            var newDistance = getDistence();

            // Non pure: var newDistance = new Random().Next(0, 100);

            Trace.WriteLine($"ACME seek: {newDistance}");

            var newSpeed    = newDistance > 10 ? 100 : 0;
            var newIsActive = newDistance != 0 ? true : false;

            // TODO: Evade etc.

            return(new RobotData
            {
                Speed = newSpeed,
                Direction = data.Direction,
                CurrentLocation = data.CurrentLocation,
                DistanceToObstacle = newDistance,
                IsActive = newIsActive
            });
        }
Exemplo n.º 8
0
    public static void CreateRobot(RobotData rd, Vector3 position, Vector3 rotation)
    {
        isLoading = true;
        foreach (Block block in Block.magicListOfAllBlocks)
        {
            if (block.attached == true && block.GetType() != typeof(Core))
            {
                MonoBehaviour.Destroy(block.gameObject);
            }
        }
        Core.core.transform.position = position;
        Core.core.transform.rotation = Quaternion.Euler(rotation);
        Core.core.GetComponent <Rigidbody> ().velocity        = Vector3.zero;
        Core.core.GetComponent <Rigidbody> ().angularVelocity = Vector3.zero;

        foreach (BlockData blockData in rd.blocks)
        {
            if (blockData.type != "Core")
            {
                GameObject blockObject = MonoBehaviour.Instantiate((GameObject)Resources.Load(blockData.type));
                blockObject.transform.parent        = Core.core.transform;
                blockObject.transform.localPosition =
                    new Vector3(Mathf.Round(blockData.position.x), Mathf.Round(blockData.position.y), Mathf.Round(blockData.position.z));
                blockObject.layer = 8;
                blockObject.GetComponent <BoxCollider> ().enabled = true;
                Block block = blockObject.GetComponent <Block> ();
                block.desiredRotation = blockData.rotation;
                //block.attached = true;
                block.Attach(new Vector3(Mathf.Round(blockData.position.x), Mathf.Round(blockData.position.y), Mathf.Round(blockData.position.z)));

                foreach (State state in blockData.states)
                {
                    if (KeyState.isKeyState(state))
                    {
                        KeyState ks  = block.getState(state.stateName) as KeyState;
                        KeyState dks = KeyState.getKeyState(state);
                        ks.inputKey = dks.inputKey;
                        ks.isActive = dks.isActive;
                        if (dks.isActive)
                        {
                            ks.stateActivated.Invoke();
                        }
                        ks.isToggleMode = dks.isToggleMode;
                    }
                    else if (!KeyState.isKeyState(state))
                    {
                        State s = block.getState(state.stateName);
                        s.isActive = state.isActive;
                        if (state.isActive)
                        {
                            s.stateActivated.Invoke();
                        }
                    }
                }
            }
        }

        //isLoading = false;
    }
Exemplo n.º 9
0
 public static void Save(string filepath, RobotData rd)
 {
     using (FileStream fs = new FileStream(filepath, FileMode.Create)) {
         rd.blocks = BlockData.PrepareBlockData();
         XmlSerializer xml = new XmlSerializer(typeof(RobotData));
         xml.Serialize(fs, rd);
     }
 }
Exemplo n.º 10
0
    public void saveRobot(RobotData r)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(savePath + r.botName + savExt);

        bf.Serialize(file, r);
        file.Close();
    }
Exemplo n.º 11
0
    public static void Walk(RobotData thisRobot)
    {
        //robot hoda prema selectionu, prvo odredi smjer kretanja i dodaj speed
        float movDirection = thisRobot.selection.transform.position.x - thisRobot.myTransform.position.x;

        movDirection = movDirection / Mathf.Abs(movDirection);
        thisRobot.myRigidbody.AddForce(new Vector2(movDirection, 0) * thisRobot.speed);
        thisRobot.myAnimator.SetBool("Walk", true);
    }
Exemplo n.º 12
0
        private void load_nearby_area_msg(Robot robot, List <Robot> robots)
        {
            int areaId = robot.m_mapComponent.m_areaId;

            int[,] offset = new int[, ]
            {
                { -1, -1 },
                { 0, -1 },
                { 1, -1 },
                { -1, 0 },
                { 1, 0 },
                { -1, 1 },
                { 0, 1 },
                { 1, 1 }
            };
            int y = areaId / (int)m_areaAcount;
            int x = areaId % (int)m_areaAcount;
            //发送robot周围区域的所有robots的位置信息
            NetworkMsg robotDataMsg = new NetworkMsg();

            robotDataMsg.MsgType = Type.RobotsData;
            for (int i = 0; i < 8; i++)
            {
                int nearbyX = x + offset[i, 0];
                int nearbyY = y + offset[i, 1];

                if (nearbyX < 0 || nearbyX >= m_areaAcount || nearbyY < 0 || nearbyY >= m_areaAcount)
                {
                    continue;
                }

                int        nearbyAreaId     = nearbyX + (int)m_areaAcount * nearbyY;
                Area       nearbyArea       = m_areasMap[nearbyAreaId];
                List <int> nearbyRobotsList = nearbyArea.get_robotsIdList();
                for (int k = 0; k < nearbyRobotsList.Count; k++)
                {
                    int nearbyRobotId = nearbyRobotsList[k];

                    RobotData nearbyRobotData = new RobotData();
                    nearbyRobotData.ClientInfo = new ClientInfo();
                    nearbyRobotData.Position   = new Position();
                    nearbyRobotData.ClientInfo.RobotSocketId = nearbyRobotId;
                    nearbyRobotData.Position = robots[nearbyRobotId].m_mapComponent.m_pos;
                    robotDataMsg.RobotData.Add(nearbyRobotData);
                }
            }
            //发送robot自己的位置信息
            RobotData robotData = new RobotData();

            robotData.ClientInfo = new ClientInfo();
            robotData.Position   = new Position();
            robotData.ClientInfo.RobotSocketId = robot.m_socketId;
            robotData.Position = robot.m_mapComponent.m_pos;
            robotDataMsg.RobotData.Add(robotData);
            robot.m_clientSocket.dump_send_queue(robotDataMsg);
        }
Exemplo n.º 13
0
        private void SavePho2butt_Click(object sender, EventArgs e)
        {
            if (camera3.IsCameraOpen())
            {
                camera3.StopCamera();
                //EnbToolBtn(true);
                McamStatusLbl.Text      = "Idle...";
                McamStatusLbl.BackColor = Color.Orange;
            }

            for (int c = 0; c < 3; c++)
            {
                if (c == 1)
                {
                    camera3.SetExposure(Para.RobotExposeTime + Convert.ToInt32((Convert.ToDouble(Para.RobotExposeTime) * 0.5)));
                }
                if (c == 2)
                {
                    camera3.SetExposure(Para.RobotExposeTime + Convert.ToInt32((Convert.ToDouble(Para.RobotExposeTime) * 1)));
                }

                bool GrabPass = false;
                for (int j = 0; j < 3; j++)
                {
                    if (camera3.Grab())
                    {
                        GrabPass = true;
                        break;
                    }
                    Application.DoEvents();
                }
                if (!GrabPass)
                {
                    return;
                }
                RobotData RDate = hWndCtrl3.RobotInspect(camera3.myImage, RobotClassPath + "\\Mod2");
                if (RDate.Found)
                {
                    HTuple hv_ReTuple = new HTuple();
                    HOperatorSet.ReadTuple(Para.RobotCurrentClass + "\\Mod2" + "\\BiaoDing2.tup", out hv_ReTuple);

                    HTuple xx, yy;
                    HOperatorSet.AffineTransPoint2d(hv_ReTuple, RDate.CenterX, RDate.CenterY, out xx, out yy);

                    hWndCtrl3.RobotMod[1].CenterX     = xx;
                    hWndCtrl3.RobotMod[1].CenterY     = yy;
                    hWndCtrl3.RobotMod[1].CenterAngle = RDate.CenterAngle;

                    hWndCtrl3.Save(mchSettingsFilePath);

                    MessageBox.Show("Photo2 Pos Save OK");
                    return;
                }
            }
            MessageBox.Show("Photo2 Pos Save Error");
        }
Exemplo n.º 14
0
    void Start()
    {
        spaces = new GameObject[size_x, size_y];

        string parentTag = this.tag;

        // Sets up multidimensional array of grid tiles and sets their world position.
        for (int i = 0; i < size_y; i++)
        {
            for (int j = 0; j < size_x; j++)
            {
                int floor_rand = Random.Range(0, 150);
                if (floor_rand <= 120 || i == 0 || i == 1)
                {
                    spaces[j, i] = Instantiate(floor_prefab, new Vector3(j, 0, i), Quaternion.identity);
                }
                else if (floor_rand > 120 && floor_rand <= 130)
                {
                    spaces[j, i] = Instantiate(spin_floor_prefab, new Vector3(j, 0, i), Quaternion.identity);
                }
                else if (floor_rand > 130 && floor_rand <= 140)
                {
                    spaces[j, i] = Instantiate(fall_floor_prefab, new Vector3(j, 0, i), Quaternion.identity);
                }
                else if (floor_rand > 140)
                {
                    spaces[j, i] = Instantiate(teleport_floor_prefab, new Vector3(j, 0, i), Quaternion.identity);
                }
                spaces[j, i].transform.parent = this.transform;
                spaces[j, i].name             = "Space " + i.ToString() + "," + j.ToString();
                spaces[j, i].gameObject.tag   = parentTag;
                Rigidbody rb = spaces[j, i].gameObject.AddComponent <Rigidbody>();
                rb.useGravity  = false;
                rb.isKinematic = true;
            }
            //  gameObject.tag = "Spaces";
        }

        // Spawns robots in the centre of the first row of grid tiles.
        robots = new GameObject[num_robots];
        for (int i = 0; i < num_robots; i++)
        {
            int spawn_pos = ((size_x / 2) - (num_robots / 2)) + i;
            robots[i]                  = Instantiate(robot_prefab, new Vector3(spaces[spawn_pos, 0].transform.position.x, 0.5f, spaces[spawn_pos, 0].transform.position.z), Quaternion.identity);
            robots[i].name             = "Player " + (i + 1).ToString();
            robots[i].transform.parent = spaces[spawn_pos, 0].transform;
            RobotData data_scr = robots[i].GetComponent <RobotData>();
            data_scr.SetPlayerNum(i);
            RobotMovement move_scr = robots[i].GetComponent <RobotMovement>();
            move_scr.x_pos = spawn_pos;
        }

        rob_mov  = robots[0].GetComponent <RobotMovement>();
        rob_mov2 = robots[1].GetComponent <RobotMovement>();
    }
Exemplo n.º 15
0
 public static void Box_Store(RobotData thisRobot)
 {
     //robot sprema selectirani box u container:
     //uništi box
     Object.Destroy(thisRobot.myTransform.Find("positionBox").GetChild(0).gameObject);
     //stopiraj robota i postavi mu parametre
     thisRobot.myRigidbody.velocity = Vector2.zero;
     thisRobot.myAnimator.SetBool("Walk", false);
     thisRobot.SetHasBox(false);
     thisRobot.selection = null;
 }
    public List <RobotPartRuntimeObject> LoadFromScriptableObject(RobotDataSO robotDataSO, GameObject robotBodyGameObject)
    {
        List <RobotPartRuntimeObject> robotParts = new List <RobotPartRuntimeObject>();

        RobotData robotData = robotDataSO.GetRobotData();

        if (robotData != null)
        {
            robotParts = LoadRobot(robotData, robotBodyGameObject);
        }

        return(robotParts);
    }
Exemplo n.º 17
0
        public virtual RobotData getRobotData(TimePoint timePoint)
        {
            int i = Arrays.binarySearch(timePoints, timePoint);

            if (i < 0)
            {
                return(RobotData.createEmptyData(name));
            }
            else
            {
                return(createDataUpToTimePoint(i));
            }
        }
Exemplo n.º 18
0
 public virtual Prediction executeRobot(RobotData robotData, Robot robot)
 {
     prepare(robotData, robot);
     robotInstructionLimit = robot.Length * instructionLimitMultiplier;
     try
     {
         return(executeRobotMain());
     }
     catch (System.Exception ex) when(ex is NotEnoughDataException || ex is TooManyInstructionsExecuted || ex is ArithmeticException)
     {
         return(Prediction.OUT);
     }
 }
Exemplo n.º 19
0
 private void prepare(RobotData robotData, Robot robot)
 {
     this.robot               = robot;
     this.data                = robotData;
     dataColumns              = data.Columns;
     finished                 = false;
     instructionList          = null;
     terminateInstructionList = false;
     changeInstructionPointer = 0;
     totalInstructionExecuted = 0;
     dataMaximumOffset        = robot.MaximumDataOffset;
     ignoreColumns            = robot.IgnoreColumns;
     zeroOutRegisters();
 }
 private void Setup()
 {
     if (!Data)
     {
         return;
     }
     InstanceData = Instantiate(Data);
     ID           = InstanceData.Unique_ID;
     strength     = InstanceData.Strength;
     upgrade      = InstanceData.Upgrade;
     for (int i = 0; i < Data.Ability_Array.Length; i++)
     {
         Abilities [i % 3, i / 3] = InstanceData.Ability_Array [i];
     }
 }
Exemplo n.º 21
0
    public void setup()
    {
        robot = GameObject.Find("Robot") as GameObject;

        if (!robot)
        {
            Debug.LogError("Couldn't find robot in setup for RobotEditor");
            gameObject.SetActive(false);
            return;
        }
        r  = robot.GetComponent <Robot> ();
        rd = r.rd;

        populatePages();
    }
Exemplo n.º 22
0
 public static Transform GetSelectionContainer(RobotData thisRobot)
 {
     //hardcode-ano traženje ispravnog containera za selectani box - moglo bi ići napredno traženje ali nije bitno za ove dvije vrste box-ova
     if (thisRobot.myTransform.Find("positionBox").GetChild(0).name == "Box_Red")
     {
         return(GameObject.Find("Container_Red").transform);
     }
     else if (thisRobot.myTransform.Find("positionBox").GetChild(0).name == "Box_Blue")
     {
         return(GameObject.Find("Container_Blue").transform);
     }
     //ako je robot primio neispravni objekt
     Debug.Log("There is no container for selected object");
     return(null);
 }
Exemplo n.º 23
0
        public RobotData AcmeDrive(RobotData data)
        {
            var newlocation = data.CurrentLocation + data.Speed * data.Direction;

            Trace.WriteLine($"ACME drive: {newlocation}");

            return(new RobotData
            {
                Speed = data.Speed,
                Direction = data.Direction,
                CurrentLocation = newlocation,
                DistanceToObstacle = data.DistanceToObstacle,
                IsActive = data.IsActive
            });
        }
Exemplo n.º 24
0
 //------------------------------------------------
 //r save
 //------------------------------------------------
 public RobotData newRobot(string newRobot)
 {
     if (!File.Exists(savePath + newRobot + savExt))
     {
         Debug.Log("Creating new Robot: " + newRobot);
         RobotData r = new RobotData();
         r.botName = newRobot;
         saveRobot(r);
         return(r);
     }
     else
     {
         Debug.Log("A robot with this name already exists");
         return(null);
     }
 }
Exemplo n.º 25
0
    public static void Box_Pickup(RobotData thisRobot)
    {
        //robot uzima selectirani box na sebe:
        //isključi od sada nepotrebne kompnente boxa i ispravno postavi box gameobjekt
        Object.Destroy(thisRobot.selection.GetComponent <BoxCollider2D>());
        Object.Destroy(thisRobot.selection.GetComponent <Rigidbody2D>());
        Transform positionBox = thisRobot.myTransform.Find("positionBox");

        thisRobot.selection.SetParent(positionBox);
        thisRobot.selection.position = new Vector3(positionBox.position.x, positionBox.position.y, -1.1f);
        //stopiraj robota i postavi mu parametre
        thisRobot.myRigidbody.velocity = Vector2.zero;
        thisRobot.myAnimator.SetBool("Walk", false);
        thisRobot.SetHasBox(true);
        thisRobot.selection = null;
    }
    public void SaveFile(string path, List <RobotPartRuntimeObject> robotParts)
    {
        RobotData robotData = SaveRobot(robotParts);

        if (robotData != null)
        {
            if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
            {
                robotData.SaveRobotDataBinaryToFile(path);
            }
            else
            {
                robotData.SaveRobotDataJsonToPlayerPrefs(path);
                UpdatePlayerPrefsRobotList(path);
            }
            //robotData.SaveRobotDataJsonToPlayerPrefs("PlayerPrefs.robot");
        }
    }
Exemplo n.º 27
0
        HTuple BR = new HTuple();        //通道2的图像Row坐标


        private bool BiaoDingCamera(HTuple Colunm, HTuple Row, HTuple R, int xi, string strpath)
        {
            for (int c = 0; c < 3; c++)
            {
                if (c == 0)
                {
                    camera3.SetExposure(Para.RobotExposeTime);
                }
                if (c == 1)
                {
                    camera3.SetExposure(Para.RobotExposeTime + Convert.ToInt32((Convert.ToDouble(Para.RobotExposeTime) * 0.2)));
                }
                if (c == 2)
                {
                    camera3.SetExposure(Para.RobotExposeTime - Convert.ToInt32((Convert.ToDouble(Para.RobotExposeTime) * 0.2)));
                }

                bool GrabPass = false;
                for (int j = 0; j < 3; j++)
                {
                    if (camera3.Grab())
                    {
                        GrabPass = true;
                        break;
                    }
                    Application.DoEvents();
                }
                if (!GrabPass)
                {
                    return(false);
                }
                RobotData RDate = hWndCtrl3.RobotInspect(camera3.myImage, strpath);
                if (RDate.Found)
                {
                    Colunm[xi] = RDate.CenterX;
                    Row[xi]    = RDate.CenterY;
                    R[xi]      = RDate.CenterAngle;
                    return(true);
                }
            }
            Colunm = 0;
            Row    = 0;
            return(false);
        }
Exemplo n.º 28
0
        /// <summary>
        /// This method is called by the game when another robot dies.
        /// </summary>
        /// <param name="robotDeathEvent">The robot death event containing data about the robot that died.</param>
        public override void OnRobotDeath(RobotDeathEvent robotDeathEvent)
        {
            // Gets the name of the robot that died
            var deadRobotName = robotDeathEvent.Name;

            // Remove the robot data for the robot that died from the enemy dictionary and access list
            enemyDictionary.Remove(deadRobotName);
            accessedEnemyList.Remove(deadRobotName);

            // Remove the data entry for the oldest scanned robot, if we have such an entry
            if (oldestScanned != null && oldestScanned.name.Equals(deadRobotName))
            {
                oldestScanned = null;
            }
            if (target != null && target.name.Equals(deadRobotName))
            {
                target = null;
            }
        }
Exemplo n.º 29
0
        private RobotData createDataUpToTimePoint(int i)
        {
            IList <double []> list = new List <double []>();

            foreach (double[] original in values)
            {
                double[] copy = copyReverseArray(original, i);
                list.Add(copy);
            }
            try
            {
                double?futureChange = calculateFutureChange(timePoints[i]);
                return(RobotData.createData(list, name, futureChange.Value));
            }
            catch (NoDataForTimePointException)
            {
                return(RobotData.createEmptyData(name));
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Updates which enemy robot from the enemy dictionary that should be our current target.
        /// </summary>
        private void UpdateTarget()
        {
            // Set target to null, meaning that we have no target robot yet
            target = null;

            // Create a list over possible target robots that is a copy of robot data from the enemy dictionary
            List <RobotData> targets = new List <RobotData>(enemyDictionary.Values);

            // Run thru all the possible target robots and remove those that are outside the attack
            // range for this border sentry robot as our robot cannot do harm to robots outside its
            // range.
            for (int i = targets.Count - 1; i >= 0; i--) // avoids error "Collection was modified"
            {
                RobotData robot = targets[i];
                if (IsOutsideAttackRange(robot.targetX, robot.targetY))
                {
                    targets.Remove(robot);
                }
            }

            // Set the target robot to be the one among all possible target robots that is closest to
            // our robot.
            double minDist = Double.PositiveInfinity;

            foreach (RobotData robot in targets)
            {
                double dist = DistanceTo(robot.targetX, robot.targetY);
                if (dist < minDist)
                {
                    minDist = dist;
                    target  = robot;
                }
            }

            // If we still haven't got a target robot, then take the first one from our list of target
            // robots if the list is not empty.
            if (target == null && targets.Count > 0)
            {
                target = targets[0];
            }
        }
Exemplo n.º 31
0
        /// <summary>
        /// Updates which enemy robot from the enemy dictionary that should be our current target.
        /// </summary> 
        private void UpdateTarget()
        {
            // Set target to null, meaning that we have no target robot yet
            target = null;

            // Create a list over possible target robots that is a copy of robot data from the enemy dictionary
            List<RobotData> targets = new List<RobotData>(enemyDictionary.Values);

            // Run thru all the possible target robots and remove those that are outside the attack
            // range for this border sentry robot as our robot cannot do harm to robots outside its
            // range.
            for (int i = targets.Count - 1; i >= 0; i--) // avoids error "Collection was modified"
            {
                RobotData robot = targets[i];
                if (IsOutsideAttackRange(robot.targetX, robot.targetY))
                {
                    targets.Remove(robot);
                }
            }

            // Set the target robot to be the one among all possible target robots that is closest to
            // our robot.
            double minDist = Double.PositiveInfinity;
            foreach (RobotData robot in targets)
            {
                double dist = DistanceTo(robot.targetX, robot.targetY);
                if (dist < minDist)
                {
                    minDist = dist;
                    target = robot;
                }
            }

            // If we still haven't got a target robot, then take the first one from our list of target
            // robots if the list is not empty.
            if (target == null && targets.Count > 0)
            {
                target = targets[0];
            }
        }
Exemplo n.º 32
0
        /// <summary>
        /// Method the updates the enemy dictionary based on new scan data for a scanned robot.
        /// </summary> 
        /// <param name="scannedRobotEvent">The scanned robot event containing data about the scanned robot.</param>
        private void UpdateEnemyDictionary(ScannedRobotEvent scannedRobotEvent)
        {
            var name = scannedRobotEvent.Name;

            // Check if data entry exists for the scanned robot
            if (enemyDictionary.ContainsKey(name))
            {
                // Data entry exists => Update the current entry with new scanned data
                RobotData scannedRobot = enemyDictionary[name];
                scannedRobot.Update(scannedRobotEvent, this);
            }
            else
            {
                // No data entry exists => Create a new data entry for the scanned robot
                RobotData scannedRobot = new RobotData(scannedRobotEvent, this);
                // Put the new data entry into the enemy dictionary
                enemyDictionary.Add(name, scannedRobot);
            }
            // Change the access order for the robot name, so the name is moved to, or added as the last entry
            if (accessedEnemyList.Contains(name))
            {
                accessedEnemyList.Remove(name);
            }
            accessedEnemyList.Add(name);
        }
Exemplo n.º 33
0
        /// <summary>
        /// This method is called by the game when another robot dies.
        /// </summary> 
        /// <param name="robotDeathEvent">The robot death event containing data about the robot that died.</param>
        public override void OnRobotDeath(RobotDeathEvent robotDeathEvent)
        {
            // Gets the name of the robot that died
            var deadRobotName = robotDeathEvent.Name;

            // Remove the robot data for the robot that died from the enemy dictionary and access list
            enemyDictionary.Remove(deadRobotName);
            accessedEnemyList.Remove(deadRobotName);

            // Remove the data entry for the oldest scanned robot, if we have such an entry
            if (oldestScanned != null && oldestScanned.name.Equals(deadRobotName))
            {
                oldestScanned = null;
            }
            if (target != null && target.name.Equals(deadRobotName))
            {
                target = null;
            }
        }
Exemplo n.º 34
0
        public FrameData(string text)
        {
            string[] data = text.Split('|');

            string[] robotText = data[0].Split('*');
            string[] bulletText = data[1].Split ('*');
            string[] hitText = data[2].Split('*');
            string[] arsenalText = data[3].Split('*');

            robotData = new RobotData[robotText.Length];
            for(int i = 0; i<robotText.Length; i++)
            {
                robotData[i] = new RobotData(robotText[i]);
            }

            if(bulletText[0] != "")
            {
                bulletData = new BulletData[bulletText.Length];
                for(int i = 0; i<bulletText.Length; i++)
                {
                    bulletData[i] = new BulletData(bulletText[i]);
                }
            }
            else
            {
                bulletData = null;
            }

            if(hitText[0] != "")
            {
                hitData = new HitData[hitText.Length];
                for(int i = 0; i<hitText.Length; i++)
                {
                    hitData[i] = new HitData(hitText[i]);
                }
            }
            else
            {
                hitData = null;
            }

            if(arsenalText[0] != "")
            {
                arsenalRespawnTime = new int[arsenalText.Length];
                for(int i = 0; i<arsenalText.Length; i++)
                {
                    arsenalRespawnTime[i] = Convert.ToInt32(arsenalText[i]);
                }
            }
            else
            {
                arsenalRespawnTime = null;
            }
        }
Exemplo n.º 35
0
    RobotData CreateRobotDataFromPlayerPrefs()
    {
        RobotData robotData = new RobotData();

        return robotData;
    }