<commit_before># -*- coding: utf-8 -*-
import sys
sys.path.append("../")

import os

from flask import Flask, request, send_from_directory, jsonify
import json
from othello import Board
from value import ModelScorer, ScorerWrapper
from ai import Bot

board = Board()
model_file = "../model/model.cpt.npy.4"
scorer = ModelScorer(model_file)
black_bot = Bot(scorer, 4, 7, Board.BLACK)
white_bot = Bot(scorer, 4, 7, Board.WHITE)

role_mapping = { "black": (black_bot, Board.BLACK), "white": (white_bot, Board.WHITE) }

def _opponent(role):
    if role == Board.BLACK:
        return Board.WHITE, "white"
    else:
        return Board.BLACK, "black"

app = Flask(__name__, static_folder="./ui/build/", static_url_path="")

@app.route("/othello")
def index():
    return send_from_directory("./ui/build/", "index.html")

@app.route("/othello/new")
def new_game():
    board.init_board()
    ret = { "board": board.board.tolist(),
            "options": board.feasible_pos(Board.BLACK),
            "blackScore": 2,
            "whiteScore": 2,
            "turn": "black" }

    return jsonify(**ret)

@app.route("/othello/play", methods=["POST"])
def play():
    data = json.loads(request.form["data"])

    player, role = role_mapping[data["player"]]

    board.set_board(data["board"])

    if "action" in data:
        r, c = data["action"]
    else:
        r, c = player.play(board)

    app.logger.info("{} {} ({},{}) {}".format(data["gameId"],
                                                data["player"],
                                                r, c,
                                                board.board.reshape(64)))

    board.flip(r, c, role)

    next_role, next_role_name = _opponent(role)
    options = board.feasible_pos(next_role)
    if len(options) == 0:
        next_role, next_role_name = role, data["player"]
        options = board.feasible_pos(next_role)
    if len(options) == 0:
        next_role_name = "none"

    black_score = board.score(Board.BLACK)<commit_msg>change model<commit_after># -*- coding: utf-8 -*-
import sys
sys.path.append("../")

import os

from flask import Flask, request, send_from_directory, jsonify
import json
from othello import Board
from value import ModelScorer, ScorerWrapper
from ai import Bot

board = Board()
model_file = "../model/model.cpt.npy.6"
scorer = ModelScorer(model_file)
black_bot = Bot(scorer, 4, 7, Board.BLACK)
white_bot = Bot(scorer, 4, 7, Board.WHITE)

role_mapping = { "black": (black_bot, Board.BLACK), "white": (white_bot, Board.WHITE) }

def _opponent(role):
    if role == Board.BLACK:
        return Board.WHITE, "white"
    else:
        return Board.BLACK, "black"

app = Flask(__name__, static_folder="./ui/build/", static_url_path="")

@app.route("/othello")
def index():
    return send_from_directory("./ui/build/", "index.html")

@app.route("/othello/new")
def new_game():
    board.init_board()
    ret = { "board": board.board.tolist(),
            "options": board.feasible_pos(Board.BLACK),
            "blackScore": 2,
            "whiteScore": 2,
            "turn": "black" }

    return jsonify(**ret)

@app.route("/othello/play", methods=["POST"])
def play():
    data = json.loads(request.form["data"])

    player, role = role_mapping[data["player"]]

    board.set_board(data["board"])

    if "action" in data:
        r, c = data["action"]
    else:
        r, c = player.play(board)

    app.logger.info("{} {} ({},{}) {}".format(data["gameId"],
                                              data["player"],
                                              r, c,
                                              ','.join(map(str, board.board.reshape(64)))))

    board.flip(r, c, role)

    next_role, next_role_name = _opponent(role)
    options = board.feasible_pos(next_role)
    if len(options) == 0:
        next_role, next_role_name = role, data["player"]
        options = board.feasible_pos(next_role)
    if len(options) == 0:
        next_role_name = "none"

    black_score = board.score(Board.BLACK)
{'fraction_non_alphanumeric': 0.15734526472781507, 'fraction_numerical': 0.005965697240865026, 'mean_word_length': 2.548500881834215, 'pattern_counts': {'":': 14, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4575677', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1298, 'n_words': 287}