Logic Distillation: Learning from Code Function by Function for Planning and Decision-making