移动角色并将移动应用到棋盘上
大家好,我之前问过一个关于如何创建的问题一个用Python编写的棋盘游戏的二维网格,现在在制作这个棋盘游戏时遇到了另一个问题。
我想做的是移动棋盘上的棋子(数字或字母),并将该移动应用到棋盘上,以便下次轮到同一个玩家时。 基本上,
1 . . . .
2 . . . .
3 . . . .
4 . . . .
. a b c d
Letters' turn: an
1 . . . .
2 . . . .
3 . . . .
4 a . . .
. . b c d
Numbers' turn: 1e
. 1 . . .
2 . . . .
3 . . . .
4 a . . .
. . b c d
Letters' turn: an
. 1 . . .
2 . . . .
3 a . . .
4 . . . .
. . b c d
你明白了......
我有棋盘,但是,我不知道如何移动棋子并将它们保持在适当的位置,以便它们可以在下一轮继续移动。
我有职能:
def doMove(currentPlayer, board):
def isValidMove(board, move):
and def applyMove(board, move):
您能提供的任何建议都会很棒!
Hey everyone, I previously asked a question on how to create a 2-D grid for a board game in Python and have now encountered another problem with making this board game.
What i'm trying to do is move pieces (numbers or letters) on my board and apply that move to the board for when it's that same players turn next.
Basically,
1 . . . .
2 . . . .
3 . . . .
4 . . . .
. a b c d
Letters' turn: an
1 . . . .
2 . . . .
3 . . . .
4 a . . .
. . b c d
Numbers' turn: 1e
. 1 . . .
2 . . . .
3 . . . .
4 a . . .
. . b c d
Letters' turn: an
. 1 . . .
2 . . . .
3 a . . .
4 . . . .
. . b c d
You get the idea...
I have the board but, I can't figure out how to move the pieces and keep them in place so they can continue their move on the next turn.
I have functions:
def doMove(currentPlayer, board):
def isValidMove(board, move):
and def applyMove(board, move):
Any advice you could lend would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信你缺少 python 中类的一个关键特性:内部状态。这是一个简单的示例:
请注意,如果我创建一个新的计数器,我可以多次调用 addToInternalCount,并且内部计数数据在调用之间保持不变。另请注意,就状态而言,类没有什么特别之处。函数外部的任何变量都可能已更新,并且该值将在调用期间保持不变。
InternalCount 有什么特别之处吗?并不真地。这可以很容易地表示 x 轴上的位置。请尝试一下。
I believe you are missing a key feature of classes in python: internal state. Here's a simple example:
Note that if I create a new Counter, I can call addToInternalCount many times and the internalCount data persists across calls. Also note that there is nothing special about a class as far as state goes. Any variable external to the function could have been updated and the value would have persisted across calls.
Is there anything special about internalCount? Not really. That could just as easily represent the position on the x-axis. Please have a go at it.