我正在尝试创建一个数据库来训练基本的机器学习算法。但是,当我运行代码时,它只创建了两行,但我试图为游戏中的每个单独位置创建多行,并在最后对位置进行鱼分析。该代码似乎正在进行三个动作,然后写入文件或覆盖每个动作的文件。我不能说它是哪一个。为了进一步详细说明,下面的示例是我编写的代码的输出,其中 number = 3:
但是,我正在寻找这样的东西:
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
---|---|---|---|---|---|---|---|---|
磷 | 磷 | p | p | |||||
磷 | 磷 | p | p | |||||
磷 | 磷 | p | p |
这是我的代码:
import chess
import chess.engine
import random
import numpy
import csv
from stockfish import Stockfish
header = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63]
data = []
def create_file(number):
board = chess.Board()
moves = 0
turns = 0
black_v = 0
white_v = 0
while moves < number:
if chess.Board.is_game_over(board) == True:
chess.Board.reset()
if turns > 200:
chess.Board.reset()
for position in header:
data.append(board.piece_at(position))
with open('/content/Positions Data/position.csv', 'w', encoding='UTF8', newline='') as f:
writer = csv.writer(f)
header.append('sf')
data.append((stockfish(board, 10))/100)
writer.writerow(header)
writer.writerow(data)
data.clear()
header.pop()
turns = turns + 1
moves = moves + 1
random_move = random.choice(list(board.legal_moves))
board.push(random_move)