Can I dynamically convert an instance of one class to another?

前端 未结 4 797
灰色年华
灰色年华 2020-12-03 07:37

I have a class that describe chess pieces. I make for all type piece in the Board a class for example Pawn, Queen, keen, etc... I have a trouble in Pawn class I want to conv

4条回答
  •  醉酒成梦
    2020-12-03 07:40

    One solution could be to let Pawn, via e.g. on Pawn.promote_to('Q'), return a Queen such that piece = piece.update() would be sensible in any case.

提交回复
热议问题