generator - Recursive Python function for Chess -
i'm trying write algorithm finds fastest way checkmate computing possible games current position of pieces (only kings , rooks) , basing next move on shortest number of moves checkmate or stalemate.
i'm having issues understanding how utilize python generators this. my question right utilize of generators , yield keyword?
heres brief psuedocode
play(maxmoves, gameboard): while not checkmate , gamemoves less maxmoves: if whitesturn: legalmoves= legal white moves x in legalmoves: testboard=deepcopy of board testboard. makemove(x) movesittook=play_gen(10,testboard) if(movesittook less previous best)...this our new bestmove play_gen(maxmoves, gameboard): while gameboard not checkmate , gamemoves less maxmoves: if whitesturn: legalmoves= legal white moves somemove in legalmoves: testboard=deepcopy of board testboard. makemove(somemove) if(checkmate) yield gameboard.turncount
python generator yield chess
No comments:
Post a Comment