Exemplo n.º 1
0
def tt_s(idx, mv_i):
    table = TranspositionTable()
    ai_1 = AI_Player(Negamax(4, tt=table))
    ai_2 = AI_Player(Negamax(4, tt=table))
    game = Gomoku([ai_1, ai_2], moves=mv_i)
    game.play(nmoves=8, verbose=False)
    table.to_file(f"{DIR}tt_{idx}.data")
Exemplo n.º 2
0
def gtt(n):
    tt_g = Parallel(n_jobs=1, verbose=10)(delayed(ext_s)(idx) for idx in range(n))
    rst = {}
    for tt in tt_g:
        if tt is not None:
            for key, value in tt.items():
                rst[key] = value
    table_g = TranspositionTable(own_dict=rst)
    table_g.to_file(f"{DIR}gtt_1.data")
Exemplo n.º 3
0
def tt_para(depth):
    mvs_df = pd.read_parquet(f"{DIR}mvs.pqt")
    tt_g = Parallel(n_jobs=-1, verbose=10)(delayed(tt_s)(depth, mv) for mv in mvs_df['moves'])
    dic_tt = {}
    for tt in tt_g:
        for key, value in tt.items():
            dic_tt[key] = value
    table = TranspositionTable(own_dict=dic_tt)
    table.to_file(f"{DIR}gtt_d1.data")
Exemplo n.º 4
0
def ext_s(depth, idx):
    if os.path.exists(f"{DIR}tt_{idx}.data"):
        table = TranspositionTable()
        table.from_file(f"{DIR}tt_{idx}.data")
        rst = {
            key: value
            for key, value in table.d.items() if value['depth'] == depth
        }
        return rst
Exemplo n.º 5
0
def play_gomoku():
    # Load transposition table
    table = TranspositionTable()
    table.from_file(f"{DIR}gtt3s.data")
    ply_1 = Human_Player()
    ply_2 = AI_Player(SSS(4))
    game = Gomoku([ply_1, ply_2], moves=['H8', 'I7'], show='test')
    game.play()
    set_trace()
Exemplo n.º 6
0
def gomoku_AI_run():
    table = TranspositionTable()
    table.from_file(f"{DIR}gtt.data")
    print(len(table.d))
    set_trace()
    ai_1 = AI_Player(Negamax(3, tt=table))
    ai_2 = AI_Player(Negamax(3, tt=table))
    game = Gomoku([ai_1, ai_2], moves=['H8', 'I7', 'G7'])
    game.play()
    print(len(table.d))
    set_trace()
Exemplo n.º 7
0
def tt_s(depth, mv_i):
    table = TranspositionTable()
    table.from_file(f"{DIR}gtt_1.data")
    ai_1 = AI_Player(Negamax(depth, tt=table))
    ai_2 = AI_Player(Negamax(depth, tt=table))
    game = Gomoku([ai_1, ai_2], moves=mv_i.tolist())
    game.play(nmoves=1, verbose=False)
    rst = {
        key: value
        for key, value in table.d.items() if value['depth'] == depth
    }
    return rst
Exemplo n.º 8
0
def gen_train():
    table = TranspositionTable()
    table.from_file(f"{DIR}gtt.data")
    rst = Parallel(n_jobs=-1, batch_size=1000,
                   verbose=10)(delayed(obs_s)(key, value)
                               for key, value in table.d.items())
    n_tt = len(table.d)
    x_tr, y_tr = np.empty((n_tt, 15, 15),
                          dtype='int8'), np.empty(n_tt, dtype='float64')
    for i in range(n_tt):
        y_tr[i], x_tr[i] = rst[i]
    tr = (y_tr, x_tr)
    with open(f"{DIR}train.data", 'wb') as f:
        dump(tr, f)
Exemplo n.º 9
0
def gomoku_AI_run():
    table = TranspositionTable()
    ai_1 = AI_Player(Negamax(2, tt=table))
    ai_2 = AI_Player(Negamax(2, tt=table))
    game = Gomoku([ai_1, ai_2], moves=['H8', 'I7', 'G7', 'I9', 'G6'])
    game.play()
    set_trace()
Exemplo n.º 10
0
def tt_s(idx, mv_i):
    table = TranspositionTable()
    table.from_file(f"{DIR}gtt3s.data")
    ai_1 = AI_Player(SSS(4, tt=table))
    ai_2 = AI_Player(SSS(4, tt=table))
    game = Gomoku([ai_1, ai_2], moves=mv_i)
    game.play(verbose=False)
    table.to_file(f"{DIR}tt3s_{idx}.data")
Exemplo n.º 11
0
def ext_s(idx):
    if os.path.exists(f"{DIR}tt_{idx}.data"):
        table = TranspositionTable()
        table.from_file(f"{DIR}tt_{idx}.data")
        return table.d