function compress(p: player): set {_cache::*} to {compress::cached_compressable::%uuid of {_p}%::*} set {_poss::*} to get_possible_compressions({_p}) {_cache::*} is not set: set_compressable_cache({_p}, {_poss::*}) size of {_cache::*} > size of {_poss::*}: set_compressable_cache({_p}, {_poss::*}) loop {compress::cached_compressable::%uuid of {_p}%::*}: {compress::current_compressing_cost::%uuid of {_p}%} is not set: set {compress::current_compressing_cost::%uuid of {_p}%} to the first element of get_costs(loop-value) where [{_p} has input] set {_cost} to {compress::current_compressing_cost::%uuid of {_p}%} while {_p} has {_cost}: add 1 to {_b} add {compress::items::%loop-value%::compressed} to inventory of {_p} remove {_cost} from inventory of {_p} broadcast {_b} delete {compress::current_compressing_cost::%uuid of {_p}%} size of get_costs(loop-value) where [{_p} has input] < 1: delete {compress::cached_compressable::%uuid of {_p}%::%loop-index%} set {_poss::*} to get_possible_compressions({_p}) size of {_poss::*} > 0: size of {compress::cached_compressable::%uuid of {_p}%::*} > size of {_poss::*}: set_compressable_cache({_p}, {_poss::*}) compress({_p})