i have a dictionary board:
board={
"h2":"WP"
}
this represents a chessboard to be specific
so each key is a square. the value is a piece.
for each piece, it has different points on different squares.
how can i like create/use a data structure so that if i have smth like this:
for square in board:
i get the points of the piece on that square
#🔒 Data Structure help
48 messages · Page 1 of 1 (latest)
@drifting locust
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
scores={"WP":{'a8': 0, 'b8': 0, 'c8': 0, 'd8': 0, 'e8': 0, 'f8': 0, 'g8': 0, 'h8': 0, 'a7': 50, 'b7': 50, 'c7': 50, 'd7': 50, 'e7': 50, 'f7': 50, 'g7': 50, 'h7': 50, 'a6': 10, 'b6': 10, 'c6': 20, 'd6': 30, 'e6': 30, 'f6': 20, 'g6': 10, 'h6': 10, 'a5': 5, 'b5': 5, 'c5': 10, 'd5': 25, 'e5': 25, 'f5': 10, 'g5': 5, 'h5': 5, 'a4': 0, 'b4': 0, 'c4': 0, 'd4': 20, 'e4': 20, 'f4': 0, 'g4': 0, 'h4': 0, 'a3': 5, 'b3': -5, 'c3': -10, 'd3': 0, 'e3': 0, 'f3': -10, 'g3': -5, 'h3': 5, 'a2': 5, 'b2': 10, 'c2': 10, 'd2': -20, 'e2': -20, 'f2': 10, 'g2': 10, 'h2': 5, 'a1': 0, 'b1': 0, 'c1': 0, 'd1': 0, 'e1': 0, 'f1': 0, 'g1': 0, 'h1': 0},
ive used this before but i feel like its too inefficient
this way i was able to get the square, and then write like the points as score[board[square]][square]
this is gonna happen millions of times so i need like a fast way to do it
you can make another dictionary containing the scores of a piece
lemme write out an example 1 sec
one dictionary for one piece?
!e
piece_scores = {'WP': 1, 'BP': 1, 'WQ': 9, 'BQ': 9,} # I'm not writing out the whole thing for now
board = {'a1': 'WP', 'b1': 0, 'c1': 'BQ'}
for square, piece in board.items():
if piece != 0: # ensure square isn't empty
score = piece_scores[piece]
print("score of", piece, "is", score)
:white_check_mark: Your 3.12 eval job has completed with return code 0.
001 | score of WP is 1
002 | score of BQ is 9
you dont what
so uh
pieces have base scores yes
but for like more precise calculation of the best move
it then looks at how optimally the piece is placed
so the points for a piece are its base value +
its score for that square
and they have different scores for diff squares
hm yes i know what you're talking about
the reason i went with this was cuz i was getting the piece in a string
and then i could reference it as a key in the dictionary and then the square its on in the nested dictionary
but now that im trying to make like an efficient code i feel like this is prob not good :P
if you're looking for efficiency ditch using dictionaries to store the board
should i just have a bunch of if conditions and a dictionary for each piece?
yee i saw people use
integers
ohh omg i see it it
i couldnt understand that rn
sorry i misinterpreted your question ðŸ˜
oh np
if you're worried that it is slow to run, it's not
if you're worried that it is slow to write out, that it most definitely is
nope
o ohk
dictionaries (which are really just hash maps) are blazingly fast to look up
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.