void Start() { character = GetComponent <Character>(); cachedTrans = transform; display = new NeuralPixel[ViewResolution, ViewResolution]; networkInput = new float[InputCount]; }
/// <summary> /// Update the input for what this net can currently see /// </summary> void RenderVision() { StageController stage = GameMode.main.stage; Vector3 stageCentre = stage.transform.position; float stageSize = stage.currentSize + 0.25f; Vector3 forward = cachedTrans.forward; Vector3 right = cachedTrans.right; // Arena view for (int x = 0; x < ViewResolution; ++x) { for (int y = 0; y < ViewResolution; ++y) { display[x, y] = new NeuralPixel(); // Reset pixel Vector2 dir = new Vector2(x - ViewResolution / 2, y - ViewResolution / 2) * displayScale; Vector3 check = cachedTrans.position + forward * dir.y + right * dir.x; // Calculate if inside of circle float a = check.x - stageCentre.x; float b = check.z - stageCentre.z; if (a * a + b * b <= stageSize * stageSize) { display[x, y].containsStage = true; } } } // Display characters foreach (Character other in GameMode.main.characters) { if (other.IsDead) { continue; } // Draw character Vector2Int pos = WorldToRender(other.transform.position); if (pos.x >= 0 && pos.x < ViewResolution && pos.y >= 0 && pos.y < ViewResolution) { display[pos.x, pos.y].containsCharacter = true; } // Draw arrow if (other.currentProjectile != null) { pos = WorldToRender(other.currentProjectile.transform.position); if (pos.x >= 0 && pos.x < ViewResolution && pos.y >= 0 && pos.y < ViewResolution) { display[pos.x, pos.y].containsArrow = true; } } // Draw sheild if (other.currentShield != null && other.currentShield.IsActive) { pos = WorldToRender(other.currentShield.transform.position); if (pos.x >= 0 && pos.x < ViewResolution && pos.y >= 0 && pos.y < ViewResolution) { display[pos.x, pos.y].containsShield = true; } } } // Update inputs for (int x = 0; x < ViewResolution; ++x) { for (int y = 0; y < ViewResolution; ++y) { int arrowShieldIndex = x + y * ViewResolution; int characterStageIndex = ViewResolution * ViewResolution + x + y * ViewResolution; NeuralPixel pixel = display[x, y]; networkInput[arrowShieldIndex] = pixel.containsArrow ? 1.0f : pixel.containsShield ? -1.0f : 0.0f; networkInput[characterStageIndex] = pixel.containsCharacter ? 1.0f : pixel.containsStage ? -1.0f : 0.0f; } } }