function GameReducer(state ,action){
    if (state === undefined){
        // initial state
        return initialState;
    }
    let newState = {...state} // clone
    //TODO: action -> change the state
    switch(action.type){
        case "GUESS_CHANGED":
            newState.guess = action.value;
            break;
        case "PLAY":
            newState.tries++;
            if (newState.secret === newState.guess){
                newState.gameLevel++;
                newState.tries = 0;
                newState.moves = [];
                newState.secret = createSecret(newState.gameLevel);
                if (newState.gameLevel>10){
                    newState.statistics.wins++;
                }
            } else {
                if (newState.tries > 10){
                    newState.statistics.loses++;
                    newState.tries = 0;
                    newState.moves = [];
                    newState.secret = createSecret(newState.gameLevel);
                } else {
                    let evaluation = evaluateMove(newState.secret, newState.guess);
                    newState.moves.push(new Move(newState.guess, evaluation));
                }
            }
            break;
    }
    return newState;
}
// export default  function GameReducer(state = initialState,action){
export default  function GameReducer(state = initialState,action){
export default function GameReducer ( state = initialState action ) {
function GameReducer(state ,action){
    if (state === undefined){
        return initialState;
    }
    let newState = {...state} 
    switch(action.type){
        case "GUESS_CHANGED":
            newState.guess = action.value;
            break;
        case "PLAY":
            newState.tries++;
            if (newState.secret === newState.guess){
                newState.gameLevel++;
                newState.tries = 0;
                newState.moves = [];
                newState.secret = createSecret(newState.gameLevel);
                if (newState.gameLevel>10){
                    newState.statistics.wins++;
                }
            } else {
                if (newState.tries > 10){
                    newState.statistics.loses++;
                    newState.tries = 0;
                    newState.moves = [];
                    newState.secret = createSecret(newState.gameLevel);
                } else {
                    let evaluation = evaluateMove(newState.secret, newState.guess);
                    newState.moves.push(new Move(newState.guess, evaluation));
                }
            }
            break;
    }
    return newState;
}
function GameReducer ( state , action ) { if ( state === undefined ) { return initialState ; } let newState = { ... state } switch ( action . type ) { case "GUESS_CHANGED" : newState . guess = action . value ; break ; case "PLAY" : newState . tries ++ ; if ( newState . secret === newState . guess ) { newState . gameLevel ++ ; newState . tries = 0 ; newState . moves = [ ] ; newState . secret = createSecret ( newState . gameLevel ) ; if ( newState . gameLevel > 10 ) { newState . statistics . wins ++ ; } } else { if ( newState . tries > 10 ) { newState . statistics . loses ++ ; newState . tries = 0 ; newState . moves = [ ] ; newState . secret = createSecret ( newState . gameLevel ) ; } else { let evaluation = evaluateMove ( newState . secret , newState . guess ) ; newState . moves . push ( new Move ( newState . guess , evaluation ) ) ; } } break ; } return newState ; }
export default  function GameReducer(state = initialState,action){
export default function GameReducer ( state = initialState action ) {
// initial state // clone //TODO: action -> change the state