private MLAction runMoves(List <float> vectorObs, MLAction[] moves) { MLInput input = new MLInput(vectorObs.ToArray()); var currentMove = moves[moveIdx]; if (currentMove == MLAction.NOTHING && Time.time - nothingStartTime >= nothingDuration) { // Doing nothing ended return(runNextMove(moves, input)); } else if (didAction && MLActionFactory.IsPunch(currentMove) && input.GetMyMove() == MLAction.NOTHING) { // Punch ended return(runNextMove(moves, input)); } else if (didAction && MLActionFactory.IsDodge(currentMove) && input.GetMyMove() == MLAction.NOTHING) { // Dodge ended return(runNextMove(moves, input)); } if (!didAction && MLActionFactory.IsPunch(currentMove)) { didAction = input.IsPunchReady(); } else if (!didAction && MLActionFactory.IsDodge(currentMove)) { didAction = input.IsDodgeReady(); } return(moves[moveIdx]); }
public override float[] Decide(List <float> vectorObs, List <Texture2D> visualObs, float reward, bool done, List <float> memory) { if (!useOldVersion) { if (Mathf.Approximately(seqStartTime, 0)) { Reset(); } if (Time.time - seqStartTime > 15 && seqIdx == 0) { seqIdx = 1; moveIdx = 0; didAction = false; nothingStartTime = Time.time; } else if (Time.time - seqStartTime > 30 && seqIdx == 1) { seqIdx = 2; moveIdx = 0; didAction = false; nothingStartTime = Time.time; } MLAction nextMove = runMoves(vectorObs, moveSequences[seqIdx]); return(MLActionFactory.GetVectorAction(nextMove)); } else { if (done) { moveIdx = 0; return(NOTHING); } MLInput input = new MLInput(vectorObs.ToArray()); if (input.IsPunchReady() && input.IsDodgeReady()) // Can punch / dodge { float[] move = moves[moveIdx]; moveIdx = (moveIdx + 1) % moves.Length; return(move); } return(NOTHING); } }
private MLAction runNextMove(MLAction[] moves, MLInput input) { didAction = false; nothingStartTime = Time.time; moveIdx = (moveIdx + 1) % moves.Length; MLAction nextMove = moves[moveIdx]; if (MLActionFactory.IsPunch(nextMove)) { didAction = input.IsPunchReady(); } else if (MLActionFactory.IsDodge(nextMove)) { didAction = input.IsDodgeReady(); } return(nextMove); }
public float[] RepeatActions(List <float> vectorObs, List <MLAction> actions, bool shouldDodge) { MLInput input = new MLInput(vectorObs.ToArray()); // Sequence if (input.IsDodgeReady()) // Can punch / dodge { // Dodging if (shouldDodge && lastAction != input.GetOpponentAction() && input.GetOpponentAction() == MLAction.PUNCH_LEFT) { lastAction = input.GetOpponentAction(); actionIdx = 0; return(MLActionFactory.GetVectorAction(MLAction.DODGE_RIGHT)); } if (shouldDodge && lastAction != input.GetOpponentAction() && input.GetOpponentAction() == MLAction.PUNCH_RIGHT) { lastAction = input.GetOpponentAction(); actionIdx = 0; return(MLActionFactory.GetVectorAction(MLAction.DODGE_LEFT)); } lastAction = input.GetOpponentAction(); } if (input.IsPunchReady()) { int myComboState = input.GetMyComboState(); if (actions.Count == 2) { switch (myComboState) { case 0: return(MLActionFactory.GetVectorAction(actions[0])); case 1: return(MLActionFactory.GetVectorAction(actions[1])); case 2: return(MLActionFactory.GetVectorAction(actions[1])); default: return(MLActionFactory.GetVectorAction(MLAction.NOTHING)); } } if (actions.Count == 3) { switch (myComboState) { case 0: return(MLActionFactory.GetVectorAction(actions[0])); case 1: return(MLActionFactory.GetVectorAction(actions[1])); case 2: return(MLActionFactory.GetVectorAction(actions[1])); case 3: return(MLActionFactory.GetVectorAction(actions[2])); case 4: return(MLActionFactory.GetVectorAction(actions[2])); default: return(MLActionFactory.GetVectorAction(MLAction.NOTHING)); } } return(MLActionFactory.GetVectorAction(actions[0])); } return(MLActionFactory.GetVectorAction(MLAction.NOTHING)); }