<commit_before>#!/usr/bin/python

import pentai.db.games_mgr as gm_m
import pentai.db.openings_book as ol_m
import pentai.base.human_player as h_m
import pentai.db.players_mgr as pm_m
import pentai.db.zodb_dict as z_m
import pentai.ai.ai_genome as aig_m
from pentai.base.defines import *
import pentai.base.logger as log

import sys
import os

def dot():
    sys.stdout.write('.')
    sys.stdout.flush()

if __name__ == "__main__":
    z_m.set_db("db.fs")
    create_default_names()

def set_default_game(defaults):
    # Set up default players for first game
    import pentai.base.rules as r_m
    rules = r_m.Rules(13, "S")
    pm = pm_m.PlayersMgr() 
    you = pm.get_p_key_from_name("You")
    anthony = pm.get_p_key_from_name("Anthony")
    defaults.play_game(("Human", you), ("AI", anthony), rules)

    z_m.sync()

def create_default_players(defaults):
    pm = pm_m.PlayersMgr() 
    if pm.get_num_players() == 0:
        create_default_humans()
        create_default_ais()
        set_default_game(defaults)

def create_default_humans():

    log.debug("Creating Human Players")
    pm = pm_m.PlayersMgr()

    # TODO: Don't release these.
    player_names = ["BC", "Bruce", "Mark", "Jespah", "Arwen", "Sascha",
            "Marion", "Wendy", "You"]

    player_names.reverse()
    for name in player_names:
        h = pm.find_by_name(name, "Human")
        if not h:
            h = h_m.HumanPlayer(name)
        dot()
        pm.save(h)
    print

def create_default_ais():
    log.debug("Creating AI Players")
    pm = pm_m.PlayersMgr()

    players = [
    { "p_name": "Samuel", "use_openings_book": True, "max_depth": 10,
        "judgement": 100, "vision": 100, "capture_score_base": 350 },
    { "p_name": "Reanne", "use_openings_book": True, "max_depth": 9,
        "judgement": 95, "vision": 95, "capture_score_base": 350 },
    { "p_name": "Quentin", "use_openings_book": True, "max_depth": 9,
        "judgement": 90, "vision": 90, "capture_score_base": 350 },
    { "p_name": "Petunia", "use_openings_book": True, "max_depth": 8,
        "judgement": 85, "vision": 85, "capture_score_base": 350 },
    { "p_name": "Oscar", "use_openings_book": True, "max_depth": 8,
        "judgement": 80, "vision": 80, "capture_score_base": 350 },
    { "p_name": "Noreen", "use_openings_book": True, "max_depth": 7,
        "judgement": 75, "vision": 75, "capture_score_base": 350 },
    { "p_name": "Marmaduke", "use_openings_book": True, "max_depth": 7,
        "judgement": 70, "vision": 70, "capture_score_base": 350 },
    { "p_name": "Lenora", "use_openings_book": True, "max_depth": 6,
        "judgement": 65, "vision": 65, "capture_score_base": 350 },
    { "p_name": "*killer*", "use_openings_book": True, "max_depth": 6,
        "judgement": 100, "vision": 100, "capture_score_base": 300 },
    { "p_name": "Kelvin", "use_openings_book": True, "max_depth": 6,
        "judgement": 60, "vision": 60, "capture_score_base": 350 },
    { "p_name": "Jamima", "use_openings_book": True, "max_depth": 5,
        "judgement": 55, "vision": 55, "capture_score_base": 350 },
    { "p_name": "Irwin", "use_openings_book": True, "max_depth": 5,
        "judgement": 50, "vision": 50, "capture_score_base": 350 },
    { "p_name": "Henrietta", "use_openings_book": True, "max_depth": 4,
        "judgement": 45, "vision": 45, "capture_score_base": 350 },
    { "p_name": "Grant", "use_openings_book": True, "max_depth": 4,
        "judgement": 40, "vision": 40, "capture_score_base": 350 },
    { "p_name": "Fleur", "use_openings_book": False, "max_depth": 3,
        "judgement": 35, "vision": 35, "capture_score_base": 350 },
    { "p_name": "Erik", "use_openings_book": False, "max_depth": 3,
        "judgement": 30, "vision": 30, "capture_score_base": 350 },
    { "p_name": "Denise", "use_openings_book": False, "max_depth": 2,
        "judgement": 25, "vision": 25, "capture_score_base": 300 },
    { "p_name": "Claude", "use_openings_book": False, "max_depth": 2,
        "judgement": 20, "vision": 20, "capture_score_base": 400 },
    { "p_name": "Beatrice", "use_openings_book": False, "max_depth": 1,
        "judgement": 15, "vision": 15, "capture_score_base": 200 },
    { "p_name": "Anthony", "use_openings_book": False, "max_depth": 1,
        "judgement": 10, "vision": 10, "capture_score_base": 300 },
    { "p_name": "*nemesis*", "use_openings_book": False, "max_depth": 3,
        "judgement": 100, "vision": 100, "capture_score_base": 300 },
    { "p_name": "*tony*", "use_openings_book": False, "max_depth": 1,
        "judgement": 0, "vision": 10, "capture_score_base": 400 },
    ]

    for p in players:
        genome = aig_m.AIGenome("")
        for k,v in p.items():
            setattr(genome, k, v)
        p = pm.find_genome_by_name(genome.p_name, "AI")
        if not p:
            genome.p_key = pm.next_id()
            pm.save(genome)
        dot()

    z_m.sync()
    print
<commit_msg>Don't create friend's human players for release.<commit_after>#!/usr/bin/python

import pentai.db.games_mgr as gm_m
import pentai.db.openings_book as ol_m
import pentai.base.human_player as h_m
import pentai.db.players_mgr as pm_m
import pentai.db.zodb_dict as z_m
import pentai.ai.ai_genome as aig_m
from pentai.base.defines import *
import pentai.base.logger as log

import sys
import os

def dot():
    sys.stdout.write('.')
    sys.stdout.flush()

def set_default_game(defaults):
    # Set up default players for first game
    import pentai.base.rules as r_m
    rules = r_m.Rules(13, "S")
    pm = pm_m.PlayersMgr() 
    you = pm.get_p_key_from_name("You")
    anthony = pm.get_p_key_from_name("Anthony")
    defaults.play_game(("Human", you), ("AI", anthony), rules)

    z_m.sync()

def create_default_players(defaults=None):
    import pentai.gui.game_defaults as gd_m
    import misc_db as m_m
    def misc():
        return m_m.get_instance()
    if not defaults:
        try:
            defaults = misc()["game_defaults"]
        except KeyError:
            defaults = misc()["game_defaults"] = gd_m.GameDefaults()

    pm = pm_m.PlayersMgr() 
    if pm.get_num_players() == 0:
        try:
            release = bool(sys.argv[1])
        except:
            release = False
        print "Release mode: %s" % release

        create_default_humans(release)
        create_default_ais()
        set_default_game(defaults)

def create_default_humans(release):

    log.debug("Creating Human Players")
    if release:
        log.debug("(for release)")
    pm = pm_m.PlayersMgr()

    player_names = ["You"]
    if not release:
        player_names.extend(["BC", "Bruce", "Mark", "Jespah", "Arwen", "Sascha",
                "Marion", "Wendy"])

    player_names.reverse()
    for name in player_names:
        h = pm.find_by_name(name, "Human")
        if not h:
            h = h_m.HumanPlayer(name)
        dot()
        pm.save(h)
    print

def create_default_ais():
    log.debug("Creating AI Players")
    pm = pm_m.PlayersMgr()

    players = [
    { "p_name": "Samuel", "use_openings_book": True, "max_depth": 10,
        "judgement": 100, "vision": 100, "capture_score_base": 350 },
    { "p_name": "Reanne", "use_openings_book": True, "max_depth": 9,
        "judgement": 95, "vision": 95, "capture_score_base": 350 },
    { "p_name": "Quentin", "use_openings_book": True, "max_depth": 9,
        "judgement": 90, "vision": 90, "capture_score_base": 350 },
    { "p_name": "Petunia", "use_openings_book": True, "max_depth": 8,
        "judgement": 85, "vision": 85, "capture_score_base": 350 },
    { "p_name": "Oscar", "use_openings_book": True, "max_depth": 8,
        "judgement": 80, "vision": 80, "capture_score_base": 350 },
    { "p_name": "Noreen", "use_openings_book": True, "max_depth": 7,
        "judgement": 75, "vision": 75, "capture_score_base": 350 },
    { "p_name": "Marmaduke", "use_openings_book": True, "max_depth": 7,
        "judgement": 70, "vision": 70, "capture_score_base": 350 },
    { "p_name": "Lenora", "use_openings_book": True, "max_depth": 6,
        "judgement": 65, "vision": 65, "capture_score_base": 350 },
    { "p_name": "*killer*", "use_openings_book": True, "max_depth": 6,
        "judgement": 100, "vision": 100, "capture_score_base": 300 },
    { "p_name": "Kelvin", "use_openings_book": True, "max_depth": 6,
        "judgement": 60, "vision": 60, "capture_score_base": 350 },
    { "p_name": "Jamima", "use_openings_book": True, "max_depth": 5,
        "judgement": 55, "vision": 55, "capture_score_base": 350 },
    { "p_name": "Irwin", "use_openings_book": True, "max_depth": 5,
        "judgement": 50, "vision": 50, "capture_score_base": 350 },
    { "p_name": "Henrietta", "use_openings_book": True, "max_depth": 4,
        "judgement": 45, "vision": 45, "capture_score_base": 350 },
    { "p_name": "Grant", "use_openings_book": True, "max_depth": 4,
        "judgement": 40, "vision": 40, "capture_score_base": 350 },
    { "p_name": "Fleur", "use_openings_book": False, "max_depth": 3,
        "judgement": 35, "vision": 35, "capture_score_base": 350 },
    { "p_name": "Erik", "use_openings_book": False, "max_depth": 3,
        "judgement": 30, "vision": 30, "capture_score_base": 350 },
    { "p_name": "Denise", "use_openings_book": False, "max_depth": 2,
        "judgement": 25, "vision": 25, "capture_score_base": 300 },
    { "p_name": "Claude", "use_openings_book": False, "max_depth": 2,
        "judgement": 20, "vision": 20, "capture_score_base": 400 },
    { "p_name": "Beatrice", "use_openings_book": False, "max_depth": 1,
        "judgement": 15, "vision": 15, "capture_score_base": 200 },
    { "p_name": "Anthony", "use_openings_book": False, "max_depth": 1,
        "judgement": 10, "vision": 10, "capture_score_base": 300 },
    { "p_name": "*nemesis*", "use_openings_book": False, "max_depth": 3,
        "judgement": 100, "vision": 100, "capture_score_base": 300 },
    { "p_name": "*tony*", "use_openings_book": False, "max_depth": 1,
        "judgement": 0, "vision": 10, "capture_score_base": 400 },
    ]

    for p in players:
        genome = aig_m.AIGenome("")
        for k,v in p.items():
            setattr(genome, k, v)
        p = pm.find_genome_by_name(genome.p_name, "AI")
        if not p:
            genome.p_key = pm.next_id()
            pm.save(genome)
        dot()

    z_m.sync()
    print

if __name__ == "__main__":
    z_m.set_db("db.fs")
    create_default_players()

{'fraction_non_alphanumeric': 0.17016786570743406, 'fraction_numerical': 0.03558752997601918, 'mean_word_length': 3.414055884843353, 'pattern_counts': {'":': 266, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2346399', 'n_tokens_mistral': 4277, 'n_tokens_neox': 3801, 'n_words': 877}