-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulateData.py
More file actions
51 lines (47 loc) · 2.16 KB
/
simulateData.py
File metadata and controls
51 lines (47 loc) · 2.16 KB
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
# Script for dataset simulation
import sys
import io
import pandas as pd
from game.board import Board
from scripts.ai import AI
from game.macro import *
def generateData(numGames, path, whiteLevel, blackLevel):
'''
Function for generating dataset for training nn-based content filtering model;
Dataset columns:
board (List[List[str]]): current veiled chess board (with veiled pieces represented by 'v' or 'V')
player (str): current player to move
gameStateInfo (List[bool]): current castling availibilities for white King, white Queen, black King and black queen
score (float): the "true score" from stockfish, the label column
Input:
numGames (int): number of games to player to generate the dataset
path (str): path of output csv file
whiteLevel (int): level of AI agent for player white
blackLevel (int): level of AI agent for player black
Output:
data (pd.DataFrame): dataset for training in pandas dataframe format
'''
# initialization
data = pd.DataFrame(columns=['board', 'player', 'gameInfo', 'score'])
index = 0
for i in range(numGames):
print(f"================== Game {i+1} ==================")
GameBoard = Board()
whiteAI = AI(GameBoard, whiteLevel)
blackAI = AI(GameBoard, blackLevel)
sys.stdin = io.StringIO('q\n'*100000) # default pawn promotion to queen for AI (may be modified later)
while not GameBoard.gameOver:
player = GameBoard.currPlayer
board, gameStateInfo = GameBoard.getBoard()
score, move = whiteAI.nextMove() if player == PLAYER_WHITE else blackAI.nextMove()
start, end = GameBoard.convertTupleToCoord(move[0]), GameBoard.convertTupleToCoord(move[1])
# create new row and insert new row to dataframe
data.at[index, 'board'] = board
data.at[index, 'player'] = player
data.at[index, 'gameInfo'] = gameStateInfo
data.at[index, 'score'] = score
data.to_csv(path, index=False)
GameBoard.move(start, end, verbose=True)
GameBoard.printBoard()
index += 1
return data