-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No Checkmate detection on pawn promotion #8
Comments
An easy fix would be to add # pawn promotion
if move.isPawnPromotion: # auto promotion to queen
# promotedPiece = input("Promote to Q, R, B or N:")
self.board[move.endRC] = move.pieceMoved[0] + "R" # promotedPiece
#+++new+++
#change player
self.whiteToMove = not self.whiteToMove
#check for valid moves
self.getValidMoves() @Skyfighter64 Maybe you can test it in your descripted environment ? After that it should update the |
@Skyfighter64 I can't reproduce this behaviour. I checked with the position you posted (except the pawn was one row farther back, i.e. on e4, and the King on a6, one row farther to the right) and tracked
Here, I, as the white human player, I played e4, then black played the only move Kb6, I player e6=R#. Also, the output is semantically identical when agent2 is Human and agent1 the AI. The AI played the exact same moves. So as you can see, it understands that it is in checkmate ( |
I just realized that I used an old engine version. Will try to replicate with the newest version later. |
Retested with the most current engine with no modifications, the problem seems to persist: Results:
Code:Here is the code I used for testing: from ChessEngine import *
if __name__ == '__main__':
print('\n>-- Start Testing --<\n')
# create a new testing state
testState = GameState()
# set the color of this player
testState.whiteToMove = True
#testAgent.isWhite = testState.whiteToMove
#intialize the board with the test state
testState.board = ['--', 'bK', '--', '--', '--', '--',
'--', '--', '--', 'wR', 'wp', '--',
'--', '--', '--', '--', '--', '--',
'--', '--', '--', '--', '--', '--',
'--', '--', '--', '--', '--', '--',
'--', '--', 'wK', '--', '--', '--']
# print out the current state
print('Board:\n%s' %(str(testState)))
print("Valid moves: " + str([str(i) for i in testState.getValidMoves()]))
# select the 'e6' move and execute it
for i in testState.getValidMoves():
if str(i) == 'e6':
testState.makeMove(i)
print("Made move: \'%s\'\n" % (str(i)))
break
# print out the current board
print('Board:\n%s' %(str(testState)))
# check if the current game state is a checkmate
# this should evaluate to True
print("Checkmate? " + str(testState.checkMate))
print('\n>-- Testing Complete --<\n')
Execute:Save in a file ('testMain.py')
|
I just quickly threw together a game testing environment: Testing environmenttestMain.py:import ChessMain
from ChessEngine import *
import sys
import argparse
def ParseArgs():
parser = argparse.ArgumentParser()
parser.add_argument('--agent1', type=str, required=True,
help='Either path to the .py file containing your agent or "MrRandom".')
parser.add_argument('--agent2', type=str, required=True,
help='See --agent_one.')
parser.add_argument('--output_file', type=str, default=None,
help='File to save results to. If not given, all output will be printed to terminal only.'
'This file will be overwritten, if it exists.')
parser.add_argument('--verbose', default=False, action='store_true',
help='Whether the output file only contains the final result or all moves.')
parser.add_argument('--use_gui', default=False, action='store_true',
help='Whether the output file only contains the final result or all moves.')
parser.add_argument('--num_games', type=int, default=1,
help='How many games you want to play with this settings and agents.'
'Agents do NOT switch sides after each game.')
parser.add_argument('--time_control', type=int, default=20,
help='How many seconds per move each player has.')
parser.add_argument('--evaluation', default=False, action='store_true',
help="Sets graphics driver to 'dummy', so that this runs on a server without optical output.")
return parser.parse_args()
if __name__ == '__main__':
# modfy arguments to start a game
sys.argv = 'testMain.py --agent1 Human --agent2 Agent1 --output_file out.txt --verbose --num_games 1 --time_control 20 --use_gui'.split(' ')
testBoard = ['--', 'bK', '--', '--', '--', '--',
'--', '--', '--', '--', 'wR', 'wp',
'--', '--', '--', '--', '--', '--',
'--', '--', '--', '--', '--', '--',
'--', '--', '--', '--', '--', '--',
'--', '--', 'wK', '--', '--', '--']
# create a new game state for testing
GameState.board = testBoard
print(GameState.board)
# start the actual game
ChessMain.main(ParseArgs())
print('\n>-- Testing Complete --<\n')
Changes in ChessMain.py:Change game_state = ChessEngine.GameState()
valid_moves = game_state.getValidMoves() To: game_state = ChessEngine.GameState()
# changes for testing
if hasattr(ChessEngine.GameState, 'board'):
game_state.board = ChessEngine.GameState.board
# end changes
valid_moves = game_state.getValidMoves() Execute:1.:
ResultsIn this case the checkmate is detected by the ChessEngine itself (showing on screen, game exits). |
Just tried, did not change the outcome of |
Checkmates are not detected if they happen within a pawn promotion move.
Situation:
Board:
White's turn.
Valid moves:
['Ra5', 'Rd2', 'Rc5', 'Kc2', 'e6', 'Rd1', 'Kd2', 'Rb5', 'Rd4', 'Kb1', 'Kd1', 'Rd3', 'Kb2', 'Rd6']
White makes move: 'e6'
Board:
Expected Behaviour:
Pawn gets promoted to Rook. Black King is in Checkmate (gameState.checkMate evaluates to
True
)Actual Behaviour:
Pawn gets promoted to Rook. Black King is not in Checkmate (gameState.checkMate evaluates to
False
)The text was updated successfully, but these errors were encountered: