let to = board.piece_at(move.to_square) let fro = board.piece_at(move.from_square)
return float(pieceValue[int(to.piece_type)] - pieceValue[int(fro.piece_type)])
I am trying to create chess engine in nim but I am using python-chess library through nimpy. I am stuck on this error and can't seem to fix it. If anyone can help me please do.
You should use codeblocks to surround your code, like this:
```nim
# Code goes here
```
Result is this:
# Code goes here
Seeing as you pasted code where your variable is called to instead of too like when you asked on discord, it seems like you reverted some of your changes.
I still stand by the comment of making sure not to reuse symbols in ways that don't match. Because nimpy defines the proc to you shouldn't use that same name for your private variables as it can cause confusion incredibly easily.
From my memory the issue was on the return line, specifically the return float(pieceValue[int(to.piece_type)] - pieceValue[int(fro.piece_type)]) line which produced,
Error: type mismatch: got 'PyObject' for 'getAttr(to, "piece_type")' but expected 'int'
pieceValue does expect an int, but that's not how to get it. We know that to or (too in your discord example) is a pyobject because that is what piece_at returns. With your current syntax, as the error says, you retrieved data from your to.piece is of type PyObject but there is no converter defined to convert PyObject -> int due to PyObject being a custom data type. To turn the PyObject into an int you neet to call the defined to proc which you can do via
too.piece_type.to(int) # is int
# or
to(too.piece_type, int) # is int # Both are the same due to UFCS
This then return an int which the index lookup can use. So likely this should work or at least bring you closer to compiling.
proc evaluateCapture(board= chess.Board, move= chess.Move): float =
if board.is_en_passant(move).to(bool):
return float(pieceValue[Pawn])
let dest = board.piece_at(move.to_square) # We know that dest & src are of type PyObject
let src = board.piece_at(move.from_square)
if dest.isNone().to(bool) or src.isNone().to(bool):
echo("Pieces were expected at both " & $move.to_square & " and " & $move.from_square )
return float(pieceValue[dest.piece_type.to(int)] - pieceValue[src.piece_type.to(int)])
/home/runner/Engine/evaluate.nim:144:28 Error: type mismatch: got <array[1..6, int], int>
Still getting a error from your code and btw I already tried renaming the variables to too and to and used this method but it gives this error with either variable name so I don't think it's problem with the variable name