Linux资源管理器:使用pgn创建游戏资源管理器(如lichess资源管理器)

关于Linux资源管理器的问题,在lichess database中经常遇到, 目前我正在寻找 python 做一个失败的“ia”,这给了我最好的成功率(使用 lichess 数据库的 grand master 部分)的最小,并且只采取已经打过至少 100 个位置的动作,以免在 1 个单场比赛中达到 100 % 的黑色成功率。

目前我正在寻找 python 做一个失败的“ia”,这给了我最好的成功率(使用 lichess 数据库的 grand master 部分)的最小,并且只采取已经打过至少 100 个位置的动作,以免在 1 个单场比赛中达到 100 % 的黑色成功率。

我告诉自己,我要做同样的事情,但不是使用 lichess API,我打算使用大师部分的.pgn 和库“国际象棋”我可以做类似的事情,但目前我被阻止如何通过示例“e2-e4”过滤这个文件,并具有每次移动的成功率,并有一个递归函数来探索这个文件。

我无法通过国际象棋-py 文档找到邀请,我的谷歌搜索没有任何结果。

有人有想法吗?

api lichess:https://lichess.org/api#tag/Opening-Explorer

png 文件:https://odysee.com/@Toadofsky:b/Lichess-Elite-Database:b

0

一种方法是通过构建像 mongodb 这样的数据库。

1. Read each game in the pgn file.
2. Record the epd after every move in the game.
3. Get the result of this game.
4. Record white_win, white_loss, white_draw, black_win, black_loss, black_draw, num_game.
5. Save/update to database the following info.
{
  "epd": <epd> 
  "white_win": ...,
  "white_loss": ..., 
  "...": ...
}

您现在可以通过 epd 查询数据库并获取那里的内容。

您可以使用例如 python-chess 库解析 pgn 文件中的每个游戏。

首先将其保存到数据库的优点是,当您稍后查询时,您将快速获得结果。

如果您不喜欢将其保存在数据库中,则可以这样做,但是如果文件很大,则可能会很昂贵。您仍然可以使用上述算法。

0

这里是 @ fougueux 的指示的一个例子(我没有想过用这个文件创建一个数据库,我错过了“erd”代码,这正是我需要的)

填充数据库(dbname =“game”,行 ID,行 fen,行结果)

import json
import requests
import chess
import chess.pgn
import chess.polyglot
import pymysql
pgn = open('C:/Users/pierr/OneDrive/Bureau/lichess_elite_2020-05.pgn')
result = []
while True:
    game = chess.pgn.read_game(pgn)
    if game is not None:
        board = game.board()
        for move in game.mainline_moves():
            board.push(move)
            result.append([board.epd(), game.headers["Result"]])
    else: 
        break
connection = pymysql.connect(host='localhost',
                             user='root',
                             password='',
                             database='chess-master',
                             cursorclass=pymysql.cursors.DictCursor)
with connection:
    with connection.cursor() as cursor:
        # Create a new record
        for i in result:
            sql = "INSERT INTO `game` (`fen`, `result`) VALUES (%s, %s)"
            cursor.execute(sql, (i[0], i[1]))

和算法搜索 minmax 得分(得分 = % winrate 白色 * 1,+ % winrate 黑色 * 0,+ % winrate 抽奖 * 0.5),他采取了更多的 100 移动播放的移动

import json
import requests
import chess
import chess.pgn
import chess.polyglot
board = chess.Board()
def parcourir(board, depth, traitblanc):
    
    scorelist = []
    
    for move in board.legal_moves:
        board.push(move)
                   
        url = 'http://localhost/chess-master/?fen='
        url += board.epd() # fen
        
        r = requests.get(url)
        data  = json.loads(r.text)
        
        somme = int(data[0]['COUNT(result)']) + int(data[1]['COUNT(result)']) + int(data[2]['COUNT(result)'])
       
        if(somme > 100):  
            score = (int(data[0]['COUNT(result)']) * 1) + (int(data[1]['COUNT(result)']) * 0) + (int(data[2]['COUNT(result)']) * 0.5)
            scorelist.append(score)
        board.pop()
        
    if(depth != 0):
        score = []
        for move in board.legal_moves:
            board.push(move)
            score.append(parcourir(board, depth-1, not traitblanc))
            board.pop()
            
    if(traitblanc):
        if(not scorelist):
            return -100
        return max(scorelist)
    else:
        if(not scorelist):
            return 100
        return min(scorelist)
    
print (parcourir(board, 1, True))

与 PHP 比 Python 更舒适,我通过这个代码选择了 fen:

<?php
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "chess-master";
    
    $doCount = array("1-0","0-1","1/2-1/2");
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    $results = array();
    
    foreach($doCount as $c) {
        
        $sql = "SELECT COUNT(result) FROM `game` WHERE fen = '".$_GET['fen']."' and result = '".$c."'";
        $result = $conn->query($sql);
        while($row = $result->fetch_assoc()) {
            $results[] = $row;
            #print_r($row);
        }
    
    }   
    echo json_encode($results)
?>

感谢您的帮助:)

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(133)
爱奇艺服务器崩溃:服务器 ram使用率增加并使服务器崩溃
上一篇
开发一个网页游戏:集成只是一个网页的一个部门
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(64条)