[Baseline] Chess Configuration
A getting started code for the Chess Configuration challenge.
Download Necessary Packages 📚¶
In this baseline we are going to use FastAI as our main library to train out model and making & submitting predictions
!pip install --upgrade fastai git+https://gitlab.aicrowd.com/yoogottamk/aicrowd-cli.git >/dev/null %load_ext aicrowd.magic
The first step is to download out train test data. We will be training a model on the train data and make predictions on test data. We submit our predictions.
API_KEY = '' #Please enter your API Key [https://www.aicrowd.com/participants/me] %aicrowd login --api-key $API_KEY
%aicrowd dataset download --challenge chess-configuration -j 3
!rm -rf data !mkdir data !unzip train.zip -d data/ !unzip val.zip -d data/ !unzip test.zip -d data/ !mv train.csv data/train.csv !mv val.csv data/val.csv !mv sample_submission.csv data/sample_submission.csv
import pandas as pd from fastai.vision.all import * import os from tqdm.notebook import tqdm
sample_submission = pd.read_csv("data/sample_submission.csv")
Creating Random Submission 👀¶
In below cell, we are going to create a random labels to submit our predictions.
piece_list = ["R", "N", "B", "Q", "P"] def place_kings(brd): while True: rank_white, file_white, rank_black, file_black = random.randint(0,7), random.randint(0,7), random.randint(0,7), random.randint(0,7) diff_list = [abs(rank_white - rank_black), abs(file_white - file_black)] if sum(diff_list) > 2 or set(diff_list) == set([0, 2]): brd[rank_white][file_white], brd[rank_black][file_black] = "K", "k" break def populate_board(brd, wp, bp): for x in range(2): if x == 0: piece_amount = wp pieces = piece_list else: piece_amount = bp pieces = [s.lower() for s in piece_list] while piece_amount != 0: piece_rank, piece_file = random.randint(0, 7), random.randint(0, 7) piece = random.choice(pieces) if brd[piece_rank][piece_file] == " " and pawn_on_promotion_square(piece, piece_rank) == False: brd[piece_rank][piece_file] = piece piece_amount -= 1 def fen_from_board(brd): fen = "" for x in brd: n = 0 for y in x: if y == " ": n += 1 else: if n != 0: fen += str(n) fen += y n = 0 if n != 0: fen += str(n) fen += "/" if fen.count("/") < 7 else "" return fen def pawn_on_promotion_square(pc, pr): if pc == "P" and pr == 0: return True elif pc == "p" and pr == 7: return True return False def start(): board = [[" " for x in range(8)] for y in range(8)] piece_amount_white, piece_amount_black = random.randint(0, 15), random.randint(0, 15) place_kings(board) populate_board(board, piece_amount_white, piece_amount_black) fen = fen_from_board(board) board = [[" " for x in range(8)] for y in range(8)] return fen
predictions =  for n in tqdm(range(sample_submission.shape)): predictions.append(start())
sample_submission['label'] = predictions sample_submission
🚧 Note :¶
- Do take a look at the submission format.
- The submission file should contain a header.
- Follow all submission guidelines strictly to avoid inconvenience.
You can submit via AIcrowd CLI directly, (which is still in its beta phase 🙃 ). If you face any problems you can submit by downloading the submission file.
%aicrowd submission create -c chess-configuration -f submission.csv
try: from google.colab import files files.download('submission.csv') except: print("Option Only avilable in Google Colab")
You must login before you can post a comment.