我正在使用位板创建一个国际象棋引擎,我有两个类: class Board和class Evaluation 。
Board类中有许多变量要传递给Evaluation类中的函数 。 该课程评估理事会的职位并返回一个数字。 我想将所有的位板传递给这个课程。 它们的数量大约为15,甚至可能会增加。
我将在Board类中创建Evaluation类的对象,而在Board类中,我将调用boardEvaluation函数。 我希望通过这个功能来传递这个功能。
一种方法是在我想要传递变量的函数中简单地接受15个参数。 但是,我不想使用这种方法,因为它听起来不太吸引人。
有没有其他方法可以将这么多变量从一个类传递到另一个类中的函数?
I am creating a chess engine using bitboards and I have two classes: class Board and class Evaluation.
There are many variables in the Board class that I want to pass to a function in the Evaluation class. This class evaluates the position of the Board and returns a number. I want to pass all my bitboards to this class. They are around 15 in number and may even increase.
I will be creating an object of the Evaluation class in the Board class and from the Board class I will be calling the boardEvaluation function. It is to this function that I want to pass these bitboards.
One way to do this is to simply accept 15 arguments in the function I want to pass the variables to. However, I would prefer not using this approach since it does not sound appealing.
Is there any other way to pass so many variables from one class to a function in another class?
最满意答案
创建另一个类BoardData并在Board和Evaluation使用它。 BoardData的职责是存储您的15个变量 - 并且可能会对它们提供一些基本操作。 通过这种方式,您的设计将被简化,而不会出现循环依赖性。
Create another class BoardData and use it in both Board and Evaluation. The responsibility of BoardData would be to store your 15 variables - and maybe provide some basic operations on them. In this way your design will be simplified without circural depependencies.
更多推荐
发布评论