博弈论框架、算法与博弈实现
gamegym的Python项目详细描述
健身房
一个博弈论框架,提供一组博弈、通用api和若干博弈论算法。
正在积极开发中,寻找创意和贡献者!
概述
算法:
- 结果抽样mccfr-nash均衡计算
- 准确的最佳响应和可利用性
- 近似最优响应和可利用性
- 稀疏sgd值学习(已知特征值为线性)
- 绘制策略开发图(请参见Matching Pennies、Rock-Paper-Scissors、Goofspiel(4)的绘图)
游戏:
- 一般矩阵游戏(普通形式游戏),石头剪刀,匹配硬币,囚徒困境,…
- goofspiel(gops)
- 一张扑克牌,骰子扑克牌
游戏界面
有关rust中api的探索,请参见GTCogs。
要实现游戏,您可以使用以下接口定义一个派生自gamegym.Game
的类:
classMyRockPaperScissor(PartialInformationGame):ACTIONS=("rock","paper","scissors")def__init__(self):# Set thenumber of players and all game actionssuper().__init__(2,self.ACTIONS)definitial_state(self)->StateInfo:# Return node information, here player 0 is active and has all actions.# Note that in this simple game we do not use any game state.returnStateInfo.new_player(state=None,player=0,actions=self.ACTIONS)defupdate_state(self,situation:Situation,action)->StateInfo:# Return the node information after playing `action` in `situation`.iflen(situation.history)==0:returnStateInfo.new_player(state=None,player=1,actions=self.ACTIONS)p1payoff=1.0# TODO: compute from `situation`, e.g. from `situation.history`returnStateInfo.new_terminal(state=None,payoff=(x,-x))# Create game instancegame=MyRockPaperScissor()# Initial situations1=game.start()# Play some actionss2=game.play(s1,"rock")s3=s2.play("paper")# alias for game.play(s2, "paper")# See game resultasserts3.is_terminal()asserts3.payoff==(-1.0,1.0)
可用的基类是PerfectInformationGame
和PartialInformationGame
。
(有专门的亚类ObservationSequenceGame
,SimultaneousGame
和
MatrixGame
-这将是一个更好的适合岩石剪纸)。
所有游戏中常见的主要辅助结构是包含信息的^ {< CD7>}
关于游戏节点本身,以及Situation
,其中还包含游戏历史,
累积收益、游戏本身等。
game state是游戏用来跟踪实际游戏状态的任何结构,例如所有人手中的牌、游戏板状态、地图……在部分信息游戏中,这通常对玩家不可见,任何observations都是通过observations=(p0_obs, p1_obs, public_obs)
传递到StateInfo
。