简体   繁体   English

Haskell纸牌游戏中的不同策略

[英]Different Strategies in a card game in Haskell

I am coding different AIs for this card game (called Algo or Coda) with the goal of making them playing against each other. 我正在为此纸牌游戏(称为Algo或Coda)编写不同的AI,目的是使它们彼此对战。 Because of my lack of experience in Haskell I hardwired the different strategies to the code and I have currently 3 versions of the same game but with different combination of AI's. 由于缺乏对Haskell的经验,我将不同的策略硬性地结合到了代码上,并且我目前拥有同一游戏的3个版本,但AI的组合有所不同。 Let me give one example. 让我举一个例子。

Briefly the game consists in guessing the opponent's cards, during one round a player is faced with two to three moments of choice: 简而言之,游戏包括猜测对手的牌,在一个回合中,玩家面对两到三个选择的时刻:

  1. Choose which Card to announce as a guess; 选择要宣布的卡作为猜测;
  2. If the guess was correct choose to keep guessing or finish his/her turn; 如果猜测是正确的,请选择继续猜测或结束轮到他/她;
  3. When hearing an opponent's guess choose which information stract from that. 当听到对手的猜测时,从中选择哪个信息摘要。

Suppose a1, b1 and c1 are possible actions for moment 1. Similarly a2, b2 and c2 are for moment 2 and a3, b3 and c3 are for moment 3. 假设a1,b1和c1是时刻1的可能动作。类似地,a2,b2和c2是时刻2的,而a3,b3和c3是时刻3的。

Within all my files I have a file for the AI with the strategy a1, b1, c1 playing against the Ai with strategy a2, b2, c2. 在我所有的文件中,我都有一个AI文件,其策略为a1,b1,c1,与AI的策略为a2,b2,c2。 And two other files with different strategies. 和另外两个具有不同策略的文件。

However what I would like to have is a module called 'Game' with a function that receives the kinds of players and runs the game applying the strategies that each player has for each choice moment. 但是,我想拥有一个名为“游戏”的模块,该模块具有接收各种玩家并根据每个玩家在每个选择时刻所拥有的策略来运行游戏的功能。

One idea I have in mind to solve this problem is to define the data type: 解决这个问题的一个主意是定义数据类型:

data Player = Player {moment1::StateOfTheGame -> Guess, 
                      moment2::StateOfTheGame -> Bool, 
                      moment3::Guess -> EpistemicState}

But them I do not know how to define the functions moment1, moment2 and moment3. 但是他们我不知道如何定义功能moment1,moment2和moment3。

Another idea that I had was to define strategies to be a class and write the instances of each strategy for the data type Player. 我的另一个想法是将策略定义为一个类,并为数据类型Player编写每个策略的实例。 But again I am not sure how to spell out this idea. 但是我不确定如何阐明这个想法。

How can I have a single module called 'Game' with a function that receives the kinds of players and runs the game applying the strategies that each player has for each choice moment? 我如何拥有一个名为“游戏”的模块,该模块具有接收各类玩家并应用每个玩家在每个选择时刻所具有的策略来运行游戏的功能?

Make a module for each strategy. 为每种策略制作一个模块。 Export the functions you need to implement player from the module. 从模块中导出实现播放器所需的功能。 In your main program create a player and pass in the functions you have exported to the player's constructor. 在您的主程序中,创建一个播放器并将传入的功能传递给播放器的构造函数。 The rest of your program works with players so it doesn't even matter what you name your functions they will be accessed through the player "interface". 程序的其余部分可与播放器一起使用,因此,无论您给函数起什么名字,都可以通过播放器的“界面”访问它们。 It ought to be a fairly straight forward application of higher order functions. 它应该是高阶函数的相当直接的应用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM