Implement cache to avoid recalculating moves