refactoring
This commit is contained in:
@@ -5,7 +5,7 @@ from chesspp.lc0_strategy import Lc0Strategy
|
||||
from chesspp.random_strategy import RandomStrategy
|
||||
from chesspp.stockfish_strategy import StockFishStrategy
|
||||
from chesspp.random_stockfish_strategy import RandomStockfishStrategy
|
||||
from chesspp.eval_pesto import PestoStrategy
|
||||
from chesspp.pesto_strategy import PestoStrategy
|
||||
from chesspp.i_strategy import IStrategy
|
||||
import chess
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import chess.engine
|
||||
import chess
|
||||
from chesspp.i_strategy import IStrategy
|
||||
from functools import cache
|
||||
|
||||
from chesspp.i_strategy import IStrategy
|
||||
import numba
|
||||
|
||||
# Scoring based on PeSTO (Piece-Square Tables Only) Evaluation Functions
|
||||
# https://www.chessprogramming.org/PeSTO%27s_Evaluation_Function
|
||||
@@ -224,6 +226,37 @@ eg_table = [
|
||||
]
|
||||
|
||||
|
||||
#import chess
|
||||
import sys
|
||||
|
||||
|
||||
def minimax(depth, board, alpha, beta, is_maximizing):
|
||||
if depth == 0 or board.is_game_over():
|
||||
return score(board)
|
||||
|
||||
if is_maximizing:
|
||||
best_move = -9999
|
||||
for move in board.legal_moves:
|
||||
board.push(move)
|
||||
best_move = max(best_move, minimax(depth - 1, board, alpha, beta, not is_maximizing))
|
||||
board.pop()
|
||||
alpha = max(alpha, best_move)
|
||||
if beta <= alpha:
|
||||
return best_move
|
||||
return best_move
|
||||
else:
|
||||
best_move = 9999
|
||||
for x in board.legal_moves:
|
||||
move = chess.Move.from_uci(str(x))
|
||||
board.push(move)
|
||||
best_move = min(best_move, minimax(depth - 1, board, alpha, beta, not is_maximizing))
|
||||
board.pop()
|
||||
beta = min(beta, best_move)
|
||||
if beta <= alpha:
|
||||
return best_move
|
||||
return best_move
|
||||
|
||||
|
||||
def score(board: chess.Board) -> int:
|
||||
mg = [0, 0]
|
||||
eg = [0, 0]
|
||||
@@ -8,7 +8,7 @@ import chess
|
||||
from chesspp import engine
|
||||
from chesspp.engine_factory import EngineFactory
|
||||
from chesspp.stockfish_strategy import StockFishStrategy
|
||||
from chesspp.eval_pesto import PestoStrategy
|
||||
from chesspp.pesto_strategy import PestoStrategy
|
||||
|
||||
_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
_DATA_DIR = os.path.abspath(os.path.join(_DIR, "static_data"))
|
||||
@@ -75,7 +75,7 @@ class WebInterface:
|
||||
async def turns():
|
||||
""" Simulates the game and sends the response to the client """
|
||||
white = EngineFactory.create_engine(self.white, self.strategy1, chess.WHITE, self.stockfish_path, self.lc0_path)
|
||||
black = EngineFactory.create_engine(self.black, self.strategy1, chess.BLACK, self.stockfish_path, self.lc0_path)
|
||||
black = EngineFactory.create_engine(self.black, self.strategy2, chess.BLACK, self.stockfish_path, self.lc0_path)
|
||||
runner = Simulate(white, black).run(self.limit)
|
||||
def sim():
|
||||
return next(runner, None)
|
||||
@@ -102,8 +102,3 @@ class WebInterface:
|
||||
web.static('/img/chesspieces/wikipedia/', _DATA_DIR),
|
||||
])
|
||||
web.run_app(app)
|
||||
|
||||
|
||||
def run_sample():
|
||||
limit = engine.Limit(time=1)
|
||||
WebInterface(engine.BayesMctsEngine, engine.ClassicMctsEngine, limit).run_app()
|
||||
|
||||
2
web.py
2
web.py
@@ -5,5 +5,5 @@ from main import read_arguments
|
||||
|
||||
if __name__ == '__main__':
|
||||
engine1, engine2, strategy1, strategy2, n_games, time, stockfish_path, lc0_path, n_proc = read_arguments()
|
||||
limit = engine.Limit(time=0.5)
|
||||
limit = engine.Limit(time=time)
|
||||
web.WebInterface(engine1, engine2, strategy1, strategy2, stockfish_path, lc0_path, limit).run_app()
|
||||
|
||||
Reference in New Issue
Block a user