public void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { for (var i = 0; i < Masks.Length; i++) { actionMask.WriteMask(i, Masks[i]); } }
public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { // Mask the necessary actions if selected by the user. if (maskActions) { // Prevents the agent from picking an action that would make it collide with a wall var positionX = (int)transform.localPosition.x; var positionZ = (int)transform.localPosition.z; var maxPosition = (int)m_ResetParams.GetWithDefault("gridSize", 5f) - 1; if (positionX == 0) { actionMask.SetActionEnabled(0, k_Left, false); } if (positionX == maxPosition) { actionMask.SetActionEnabled(0, k_Right, false); } if (positionZ == 0) { actionMask.SetActionEnabled(0, k_Down, false); } if (positionZ == maxPosition) { actionMask.SetActionEnabled(0, k_Up, false); } } }
public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { // Mask the necessary actions if selected by the user. for (int i = 0; i < agents.Count; i++) { var positionX = (int)agents[i].Trans.localPosition.x; var positionZ = (int)agents[i].Trans.localPosition.z; var maxPosition = 9; if (positionX == -maxPosition) { actionMask.WriteMask(i, new[] { PlayAgent.k_Left }); } if (positionX == maxPosition) { actionMask.WriteMask(i, new[] { PlayAgent.k_Right }); } if (positionZ == -maxPosition) { actionMask.WriteMask(i, new[] { PlayAgent.k_Down }); } if (positionZ == maxPosition) { actionMask.WriteMask(i, new[] { PlayAgent.k_Up }); } } }
/// <inheritdoc/> public void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { using (TimerStack.Instance.Scoped("WriteDiscreteActionMask")) { actionMask.WriteMask(0, InvalidMoveIndices()); } }
public void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { foreach (var actionIndex in Mask) { actionMask.SetActionEnabled(Branch, actionIndex, false); } }
public void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { for (var i = 0; i < Masks.Length; i++) { foreach (var actionIndex in Masks[i]) { actionMask.SetActionEnabled(i, actionIndex, false); } } }
/// <inheritdoc/> public void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { var currentBoardSize = m_Board.GetCurrentBoardSize(); m_Board.CheckBoardSizes(m_MaxBoardSize); const int branch = 0; bool foundValidMove = false; using (TimerStack.Instance.Scoped("WriteDiscreteActionMask")) { var numMoves = m_Board.NumMoves(); var currentMove = Move.FromMoveIndex(0, m_MaxBoardSize); for (var i = 0; i < numMoves; i++) { // Check that the move is allowed for the current boardSize (e.g. it won't move a piece out of // bounds), and that it's allowed by the game itself. if (currentMove.InRangeForBoard(currentBoardSize) && m_Board.IsMoveValid(currentMove)) { foundValidMove = true; } else { actionMask.SetActionEnabled(branch, i, false); } currentMove.Next(m_MaxBoardSize); } if (!foundValidMove) { // If all the moves are invalid and we mask all the actions out, this will cause an assert // later on in IDiscreteActionMask. Instead, fire a callback to the user if they provided one, // (or log a warning if not) and leave the last action unmasked. This isn't great, but // an invalid move should be easier to handle than an exception.. if (m_Board.OnNoValidMovesAction != null) { m_Board.OnNoValidMovesAction(); } else { Debug.LogWarning( "No valid moves are available. The last action will be left unmasked, so " + "an invalid move will be passed to AbstractBoard.MakeMove()." ); } actionMask.SetActionEnabled(branch, numMoves - 1, true); } } }
/// <inheritdoc/> public void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { const int branch = 0; bool foundValidMove = false; using (TimerStack.Instance.Scoped("WriteDiscreteActionMask")) { var numMoves = m_Board.NumMoves(); var currentMove = Move.FromMoveIndex(0, m_Board.Rows, m_Board.Columns); for (var i = 0; i < numMoves; i++) { if (m_Board.IsMoveValid(currentMove)) { foundValidMove = true; } else { actionMask.SetActionEnabled(branch, i, false); } currentMove.Next(m_Board.Rows, m_Board.Columns); } if (!foundValidMove) { // If all the moves are invalid and we mask all the actions out, this will cause an assert // later on in IDiscreteActionMask. Instead, fire a callback to the user if they provided one, // (or log a warning if not) and leave the last action unmasked. This isn't great, but // an invalid move should be easier to handle than an exception.. if (m_Board.OnNoValidMovesAction != null) { m_Board.OnNoValidMovesAction(); } else { Debug.LogWarning( "No valid moves are available. The last action will be left unmasked, so " + "an invalid move will be passed to AbstractBoard.MakeMove()." ); } actionMask.SetActionEnabled(branch, numMoves - 1, true); } } }
/// <inheritdoc/> /// <summary> /// Stores valid actions, so that the agent can be penalized for /// invalid ones, in case <see cref="m_MaskActions"/> is set to false. /// </summary> public override void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { m_ValidActions.Clear(); m_ValidActions.Add(c_Stay); for (int action = 1; action < 5; action++) { bool isValid = m_MazeBuffer.TryRead(Maze.Wall, m_GridPosition + m_Directions[action], out float value) && value == 0; // no wall if (isValid) { m_ValidActions.Add(action); } else if (m_MaskActions) { actionMask.SetActionEnabled(0, action, false); } } }
public void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { actionMask.WriteMask(Branch, Mask); }
internal DiscreteActionMasker(IDiscreteActionMask actionMask) { m_Delegate = actionMask; }
/// <inheritdoc cref="IActionReceiver.WriteDiscreteActionMask"/> public void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { // TODO configure mask from editor UI? }
public void WriteDiscreteActionMask(IDiscreteActionMask actionMask) { }