【发布时间】:2009-11-18 22:40:51
【问题描述】:
我目前正在为我的数据结构课程做的作业的目标是创建一个带有人工智能的量子井字游戏,以赢得胜利。
目前,我很难找到最有效的方式来表示状态。
当前结构概述:
抽象游戏
- 拥有并管理 AbstractPlayer(game.nextPlayer() 通过 int ID 返回下一个玩家)
- 在游戏开始时拥有并初始化 AbstractBoard
- 有一个 GameTree(如果在初始化中调用完成,否则不完整)
抽象板
- 具有状态、维度和父游戏
- 是 Player 和 State 之间的中介,(将 State 从行集合转换为 Point 表示
- 是 StateConsumer
抽象播放器
- 是国家生产者
- 有一个具体的评估策略来评估当前的董事会
StateTransveralPool
- 预计算“三态”的可能横向。
- 将它们存储在 HashMap 中,其中 Set 包含给定“3-state”的 nextStates
状态
- 包含 3 组 - 一组 X-Move、O-Move 和棋盘
- 集合中的每个整数都是一个行。这些整数值可用于从 StateTransversalPool 中获取下一个行状态
SO,原理是 每行可以用二进制数 000-111 表示,其中 0 表示开放空间,1 表示封闭空间。
所以,对于一个不完整的 TTT 板:
From the Set<Integer> board perspective:
X_X R1 might be: 101
OO_ R2 might be: 110
X_X R3 might be: 101, where 1 is an open space, and 0 is a closed space
From the Set<Integer> xMoves perspective:
X_X R1 might be: 101
OO_ R2 might be: 000
X_X R3 might be: 101, where 1 is an X and 0 is not
From the Set<Integer> oMoves perspective:
X_X R1 might be: 000
OO_ R2 might be: 110
X_X R3 might be: 000, where 1 is an O and 0 is not
然后我们看到 x{R1,R2,R3} & o{R1,R2,R3} => board{R1,R2,R3}
问题是快速为 GameTree 生成下一个状态。如果我有棋盘{R1,R2,R3} 的玩家 Max (x),那么获取 R1、R2 和 R3 的下一个行状态很简单..
Set<Integer> R1nextStates = StateTransversalPool.get(R1);
问题是我必须将这些状态中的每一个与 R1 和 R2 结合起来。
除了 Set 之外,还有更好的数据结构可以使用吗?一般来说,有没有更有效的方法?我还发现 PointState 调解很麻烦。我可以在那里尝试另一种方法吗?
谢谢!
这是我的 ConcretePlayer 类的代码。它可能有助于解释玩家如何使用 StateProducer(可能需要成为 StateFactory 或 StateBuilder)通过移动产生新状态。
public class ConcretePlayerGeneric extends AbstractPlayer {
@Override
public BinaryState makeMove() {
// Given a move and the current state, produce a new state
Point playerMove = super.strategy.evaluate(this);
BinaryState currentState = super.getInGame().getBoard().getState();
return StateProducer.getState(this, playerMove, currentState);
}
}
编辑:我从普通 TTT 开始,然后转向 Quantum TTT。给定框架,它应该像创建几个新的 Concrete 类并调整一些东西一样简单。
【问题讨论】:
-
您的示例板表示似乎错误。
-
怎么样?对于 Set
板,0 表示没有玩家移动到那里。对于 Set xMoves,0 意味着 X 没有移动到那里。对于 Set oMoves,0 表示 O 没有移动到那里。 -
好吧,除了O只有两步之外..哈哈
-
编辑:修复了在同一个地方多次移动的问题(我认为)
标签: java design-patterns optimization