将许多变量从一个类中的函数传递到另一个类中的函数(Passing many variables from a function in one class to a function in anothe

编程入门 行业动态 更新时间:2024-10-24 18:19:09
将许多变量从一个类中的函数传递到另一个类中的函数(Passing many variables from a function in one class to a function in another class)

我正在使用位板创建一个国际象棋引擎,我有两个类: 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.

更多推荐

本文发布于:2023-08-05 19:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1438049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:函数   类中   变量   Passing   function

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!