如何生成骑士的所有动作?

如何生成骑士的所有动作?,第1张

如何生成骑士的所有动作?

好的,感谢Niall Byrne,我想到了这个:

from itertools import productdef knight_moves(position):    x, y = position    moves = list(product([x-1, x+1],[y-2, y+2])) + list(product([x-2,x+2],[y-1,y+1]))    moves = [(x,y) for x,y in moves if x >= 0 and y >= 0 and x < 8 and y < 8]    return moves


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5508475.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-13
下一篇2022-12-13

发表评论

登录后才能评论

评论列表(0条)

    保存