You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: reward.m
    path of file: ./repos/QlearningProject/Policy-I/matlab_code_simulation
    
    the code of the file until where you have to start completion: function [reward]=reward(action,s_type,current_state)


%% assign rewards to state vector
[Max,index_max]=max(current_state);
[Min,index_min]=min(current_state);

if action==4 %special action, emergency
    reward=0;

    
function [reward]=reward(action,s_type,current_state)


%% assign rewards to state vector
[Max,index_max]=max(current_state);
[Min,index_min]=min(current_state);

if action==4 %special action, emergency
    reward=0;
else
    %action= 1:forward,2=left,3=right
    if index_max==action %best reward
        switch s_type
            case 1
                reward=0;
            case 2
                reward=5;
        end