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 (done) { moveIdx = 0; return(NOTHING); } MLInput input = new MLInput(vectorObs.ToArray()); if (input.GetMyMove() == MLAction.NOTHING && input.IsDodgeReady()) // Can dodge { if (input.GetOpponentAction() == MLAction.PUNCH_LEFT) { int rand = Random.Range(0, 100); if (rand <= 30) { return(LEFT_DODGE); } else if (rand <= 50) { return(RIGHT_DODGE); } else { // Run the normal moves } } if (input.GetOpponentAction() == MLAction.PUNCH_RIGHT) { int rand = Random.Range(0, 100); if (rand <= 30) { return(RIGHT_DODGE); } else if (rand <= 50) { return(LEFT_DODGE); } else { // Run the normal moves } } } return(MLActionFactory.GetVectorAction(runMoves(vectorObs, moves))); }
public override float[] Decide(List <float> vectorObs, List <Texture2D> visualObs, float reward, bool done, List <float> memory) { MLInput input = new MLInput(vectorObs.ToArray()); MLAction currentMove = input.GetMyMove(); //if (MLActionFactory.IsDodge(currentMove)) //{ // return MLActionFactory.GetVectorAction(currentMove); //} if (currentMove != MLAction.NOTHING) { var maxMoveCount = MLActionFactory.IsDodge(currentMove) ? maxDodgeCount : maxPunchCount; if (moveCount < maxMoveCount) { moveCount++; return(MLActionFactory.GetVectorAction(currentMove)); } return(MLActionFactory.GetVectorAction(MLAction.NOTHING)); } else { moveCount = 0; } if (Input.GetKey(KeyCode.F)) { return(MLActionFactory.GetVectorAction(MLAction.PUNCH_LEFT)); } else if (Input.GetKey(KeyCode.J)) { return(MLActionFactory.GetVectorAction(MLAction.PUNCH_RIGHT)); } else if (Input.GetKey(KeyCode.D)) { return(MLActionFactory.GetVectorAction(MLAction.DODGE_LEFT)); } else if (Input.GetKey(KeyCode.K)) { return(MLActionFactory.GetVectorAction(MLAction.DODGE_RIGHT)); } return(MLActionFactory.GetVectorAction(MLAction.NOTHING)); }