/// <summary> /// Read action inputs from vectorAction /// Action space has size 2 /// vectorAction[0] = rotate /// vectorAction[1] = move /// </summary> /// <param name="vectorAction">The chosen actions</param> public override void OnActionReceived(float[] vectorAction) { int currentAction = Mathf.RoundToInt(vectorAction[0]); if (!MaskedActions.Contains(currentAction)) { // horizontal (x) position & rotation // 40 possible values int rotate = Mathf.RoundToInt(currentAction % TetrisSettings.NumRotations); int position = Mathf.FloorToInt(currentAction / TetrisSettings.NumRotations); tetrisGame.CreateBlock(position, TetrisSettings.Rotations[rotate]); } else { tetrisGame.GameOver(); } }
private bool CheckForGameOver() { foreach (Transform child in transform) { Vector3 localPos = controller.transform.InverseTransformPoint(child.transform.position); int roundedY = Mathf.RoundToInt(localPos.y); // block hasn't moved down so game over if (roundedY >= TetrisSettings.SpawnY) { Destroy(gameObject); controller.GameOver(); active = false; return(true); } } return(false); }