Nov-19-2021, 08:27 PM
Hi all,
I'm writing a pretty rudimentary code that essentially plays chess with itself. Dictionaries are the data types used to contain all of the data about each individual piece. I have only programmed the movement of pawns this far. I've been using functions for most of the content but I'm having an issue with one of the functions referencing a dictionary. I'm trying to reference an input from the function using an if statement, but the function simply skips over it and executes the else statement. Attached below is the chess code and subsequent UDF code. The code below is the function causing issues.
P.S. I am interested in hearing any good advice on optimizing the code as it is.
Thanks.
I'm writing a pretty rudimentary code that essentially plays chess with itself. Dictionaries are the data types used to contain all of the data about each individual piece. I have only programmed the movement of pawns this far. I've been using functions for most of the content but I'm having an issue with one of the functions referencing a dictionary. I'm trying to reference an input from the function using an if statement, but the function simply skips over it and executes the else statement. Attached below is the chess code and subsequent UDF code. The code below is the function causing issues.
P.S. I am interested in hearing any good advice on optimizing the code as it is.
Thanks.
def pawn(board,color,which): if color == white: nr = -1 spot = 'W_pawn' else: nr = 1 spot = 'B_pawn' # empty current pos board[color['Pawns']['Pawn %s' %(which)]['Row'],color['Pawns']['Pawn %s' %(which)]['Column']] = '' # edit row value in dictionary color['Pawns']['Pawn %s' %(which)]['Row'] += nr # update new pos in board board[color['Pawns']['Pawn %s' %(which)]['Row'],color['Pawns']['Pawn %s' %(which)]['Column']] = spot return board,color
Attached Files
ChessBoard.txt (Size: 566 bytes / Downloads: 197)
ChessUDF.py (Size: 7.75 KB / Downloads: 190)
Robots Play Chess 1.2.py (Size: 2.07 KB / Downloads: 183)