请解释这段python代码以及如何用lisp编写等价的代码

2024-10-04 01:22:16 发布

您现在位置:Python中文网/ 问答频道 /正文

请解释[[[0]*64 for i in range(7)] for j in range(2)]部分以及如何编写lisp等价物。你知道吗

pieceHashes = [[[0]*64 for i in range(7)] for j in range(2)]
    for color in WHITE, BLACK:
        for piece in PAWN, KNIGHT, BISHOP, ROOK, QUEEN, KING:
            for cord in range(64):
                pieceHashes[color][piece][cord] = randint(0, maxint)

Tags: inforpiecerangebishopcolorblackwhite
2条回答

它生成一个具有64 x 7 x 2个元素的三维数组。 然后在最后一行填充数组。你知道吗

(let ((piece-array (make-array '(2 7 64) :initial-element 0)))
  (dolist (color `(,white ,black))
    (dolist (piece `(,pawn ,knight ,bishop ,rook ,queen ,king))
      (loop for cord below 64
            do (setf (aref piece-array color piece cord)
                     (random maxint))))))

相关问题 更多 >