Exemplo n.º 1
0
        public bool IsAvailable(ThreeJugsState state)
        {
            switch (action1)
            {
            case Action.empty_into:
                if (state.state[source] > 0 && ThreeJugsState.Containers[target] >= state.state[target] + state.state[source])
                {
                    return(true);
                }
                return(false);

            case Action.fill_from:
                if (ThreeJugsState.Containers[source] > state.state[source] && state.state[target] > 0)
                {
                    return(true);
                }
                return(false);

            default:
                return(false);
            }
        }
Exemplo n.º 2
0
        public ThreeJugsState resultState(ThreeJugsState current_state)
        {
            ThreeJugsState new_state = new ThreeJugsState(current_state.state);

            switch (action1)
            {
            case Action.empty_into:
                new_state.from_action    = this;
                new_state.state[target] += current_state.state[source];
                new_state.state[source]  = 0;
                return(new_state);

            case Action.fill_from:
                new_state.from_action   = this;
                new_state.state[source] = Math.Min(current_state.state[source] + current_state.state[target], ThreeJugsState.Containers[source]);
                new_state.state[target] = current_state.state[source] + current_state.state[target] > ThreeJugsState.Containers[source] ?
                                          current_state.state[source] + current_state.state[target] - ThreeJugsState.Containers[source] : 0;
                return(new_state);

            default:
                return(null);
            }
        }