当我想到对象结构时,我认为我的方法是做两件事之一:
1)向'对象'提问
2)命令"对象"做某事
话虽如此,对我来说,询问"董事会"下一步最佳举措是没有意义的.董事会应该只是持有价值并告诉你它的状态.
我可能会有一个专门用于确定给定"情报"的最佳下一步行动的对象.我们称之为'move_brain'.然后你可以说,"嘿move_brain,鉴于这个董事会和这个级别的情报,下一个最好的举动是什么?"
您现在概述的董事会课程有很多职责:保持状态,允许用户移动,以及考虑如何移动下一步.那太重要了.
毕竟,我会这样说:鉴于这个程序不是很大,几乎任何解决方案都没问题.
祝你好运!
我定义了3个接口:
这是每个班级的简要概述:
游戏:
IP层:
您可以运行如下代码:
IPlayer meAsAPlayer = new UserPlayer(); //you'd have to implement this
//as an "empty" class that would let the user
//specify the actions
IPlayer AIPlayer = new AIPlayer(); //one AI class you'd have implemented
Game game = new Game(meAsAPlayer, AIPlayer);
game.start(); //this would run one game to the end
game.start(); //this would be the second game already
Run Code Online (Sandbox Code Playgroud)
这将是游戏类决定哪些游戏是正确的,哪些不会.如果玩家试图进行不正确的游戏,它会阻止它并再次调用该玩家的OnTurn()事件.
那或者不是定义IPlayer接口,你可以定义一个APlayer抽象类,它只能让你做出正确的动作.