void Start() { print("new one " + explorechance); bfrstate = 100000; gotthem = false; hit = false; reward = -1000; Application.targetFrameRate = 100; transform.position = new Vector3(0, 0, 0); gameObject.GetComponent <Rigidbody2D>().velocity = new Vector3(0, 0, 0); states = new List <state>(); for (int i = 0; i <= 20; i++) { for (int j = 0; j <= 25; j++) { state s = new state(); s.x = i; s.y = -j; s.Start(); states.Add(s); } } if (savedata.got1) { states = savedata.t; } else { savedata.t = states; savedata.got1 = true; } for (int i = 0; i < states.Count; i++) { if (Mathf.Abs((int)transform.position.x) == states[i].x && (int)transform.position.y == states[i].y) { currentstate = i; } } float ex = Random.Range(0, 1.0f); if (ex >= explorechance) { float maxq = states[currentstate].action[0].qvalue; int maxiact = 0; print(states[currentstate].action.Count); for (int i = 0; i < states[currentstate].action.Count; i++) { if (states[currentstate].action[i].qvalue >= maxq) { maxq = states[currentstate].action[i].qvalue; maxiact = i; } } string take = states[currentstate].action[maxiact].act; if (take == "up") { gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 50); } else if (take == "down") { gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(0, -50); } else if (take == "left") { gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(-50, 0); } else if (take == "right") { gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(50, 0); } actiontaken = take; } else { int rani = Random.Range(0, 4); string take = states[currentstate].action[rani].act; if (take == "up") { gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(0, 50); } else if (take == "down") { gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(0, -50); } else if (take == "left") { gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(-50, 0); } else if (take == "right") { gameObject.GetComponent <Rigidbody2D>().velocity = new Vector2(50, 0); } actiontaken = take; } }