Get enemy's possible moves in chess to a 2D array
I have three arrays,
chess = [["c","d","e","f","g","e","d","c"],
["b","b","b","b","b","b","b","b"],
["a","a","a","a","a","a","a","a"],
["a","a","a","a","a","a","a","a"],
["a","a","a","a","a","a","a","a"],
["a","a","a","a","a","a","a","a"],
["h","h","h","h","h","h","h","h"],
["i","j","k","l","m","k","j","i"]]
that stores the positions of the pieces, ('a' is empty, 'b' is a black pawn etc.) and two other 8x8 arrays filled with False named whiteMoves and blackMoves. What I want is a function
def getEnemyMoves():
global chess, whiteMoves, blackMoves
doSomethingToWhiteMoves()
doSomethingToBlackMoves()
that does for example these:
I have tried many different ways to do this, but they were very complex and none of them worked fully. This is the only thing to do before my chess game is finished.
Iterate over the pieces on the board. For each piece, narrow down the destination squares according to the move rules for that piece:
For each such candidate move, test whether additional constraints prevent that candidate move:
If you combine these two passes into a single one, you save some CPU cycles:
These things are complex. Eg before finally deciding on a move, you have to test whether the king is in check.
链接地址: http://www.djcxy.com/p/84668.html上一篇: 国际象棋决赛:国王和白嘴鸦vs国王在蟒蛇
下一篇: 在国际象棋中获得敌人可能的移动到2D阵列