Esempio n. 1
0
def do_decode_n_move_pieces(board,move):
    i_pos, f_pos, prom = ed.decode_action(board,move)
    for i, f, p in zip(i_pos,f_pos,prom):
        board.move_piece(i,f,p) # move piece to get next board state s
        a,b = i; c,d = f
        if board.current_board[c,d] in ["K","k"] and abs(d-b) == 2: # if king moves 2 squares, then move rook too for castling
            if a == 7 and d-b > 0: # castle kingside for white
                board.player = 0
                board.move_piece((7,7),(7,5),None)
            if a == 7 and d-b < 0: # castle queenside for white
                board.player = 0
                board.move_piece((7,0),(7,3),None)
            if a == 0 and d-b > 0: # castle kingside for black
                board.player = 1
                board.move_piece((0,7),(0,5),None)
            if a == 0 and d-b < 0: # castle queenside for black
                board.player = 1
                board.move_piece((0,0),(0,3),None)
    return board
@author: WT
"""

import os
import numpy as np
import pickle
import encoder_decoder as ed
from visualize_board import view_board as vb
import matplotlib.pyplot as plt

data_path = "./datasets/iter2/"
file = "dataset_cpu1_5"
filename = os.path.join(data_path, file)
with open(filename, 'rb') as fo:
    dataset = pickle.load(fo, encoding='bytes')

last_move = np.argmax(dataset[-1][1])
b = ed.decode_board(dataset[-1][0])
act = ed.decode_action(b, last_move)

b.move_piece(act[0][0], act[1][0], act[2][0])
for i in range(len(dataset)):
    board = ed.decode_board(dataset[i][0])
    fig = vb(board.current_board)
    plt.savefig(os.path.join("C:/Users/WT/Desktop/Python_Projects/chess/chess_ai_py35updated/gamesimages/ex4/", \
                             f"{file}_{i}.png"))

fig = vb(b.current_board)
plt.savefig(os.path.join("C:/Users/WT/Desktop/Python_Projects/chess/chess_ai_py35updated/gamesimages/ex4/", \
                             f"{file}_{i+1}.png"))