Python client for noprune chess bot platform - easily create custom chess engines
Project description
noprune
Python client for the noprune chess bot platform.
Installation
pip install noprune
Or for development:
pip install -e clients/python
Quick Start
가장 간단한 봇:
from noprune import Bot
import random
@Bot(system_id="your-system-id", secret="your-secret")
def my_bot(board) -> str:
"""board는 python-chess의 Board 객체"""
return random.choice(list(board.legal_moves)).uci()
my_bot.run()
Game Actions
기권, 무승부 제안 등:
from noprune import Bot, Action
@Bot(system_id="...", secret="...")
def my_bot(board) -> str | Action:
# 불리하면 기권
if is_losing_badly(board):
return Action.RESIGN
# 무승부 제안
if board.halfmove_clock >= 50:
return Action.OFFER_DRAW
return calculate_best_move(board)
Advanced Usage
클래스를 상속해서 더 세밀한 제어:
from noprune import Bot, GameState, Action
class MyBot(Bot):
def on_game_start(self, game: GameState):
print(f"게임 시작! 상대: {game.opponent}, 내 색: {game.color}")
self.move_count = 0
def on_move(self, game: GameState, move: str, is_my_move: bool):
print(f"{'나' if is_my_move else '상대'}: {move}")
def on_game_end(self, game: GameState, result: str, reason: str):
print(f"게임 종료: {result} ({reason})")
def on_draw_offer(self, game: GameState) -> bool:
"""상대가 무승부 제안 시. True=수락"""
return len(game.moves) > 100
def think(self, board) -> str | Action:
self.move_count += 1
# 여기서 수 계산
return "e2e4"
bot = MyBot(system_id="...", secret="...")
bot.run()
GameState
@dataclass
class GameState:
game_id: str # 게임 ID
board: chess.Board # python-chess Board
color: str # "white" | "black"
opponent: str # 상대 이름
moves: list[str] # UCI 수 목록
my_time_ms: int # 내 남은 시간 (ms)
opponent_time_ms: int # 상대 남은 시간 (ms)
Action
Action.RESIGN # 기권
Action.OFFER_DRAW # 무승부 제안
Action.move("e2e4") # 수 두기 (문자열 반환과 동일)
Examples
examples/ 디렉토리 참고:
random_bot.py- 가장 간단한 예제stockfish_bot.py- Stockfish 엔진 연동minimax_bot.py- 커스텀 미니맥스 알고리즘
실행 방법
# 환경변수 설정
export SYSTEM_ID="your-system-id"
export SYSTEM_SECRET="your-secret"
export SERVER_URL="wss://noprune.org/ws" # 또는 ws://localhost:8086/ws
# 봇 실행
python examples/random_bot.py
Dependencies
websockets>=12.0python-chess>=1.10.0
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
noprune-0.1.0.tar.gz
(6.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file noprune-0.1.0.tar.gz.
File metadata
- Download URL: noprune-0.1.0.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e01fe7b9807b3ad8327f007fc8184392ca2d71ea57dc52142df07a256ef2ff9a
|
|
| MD5 |
c92624a4b05fc1d41d09f25fc01dc21a
|
|
| BLAKE2b-256 |
8aedb38c0180cbfd610a9495cf6682ec9cc76f919a0612f72090350456ce6803
|
File details
Details for the file noprune-0.1.0-py3-none-any.whl.
File metadata
- Download URL: noprune-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
092c43dc05eebc82184e13b3d5b480c87d9c87b4854718779e18238c88488cf3
|
|
| MD5 |
152e8f54980faf1a377ee7365020e4be
|
|
| BLAKE2b-256 |
f2582bfe35f42dead6754678e15f4d0a41b37c2981ff9ee7053c92f5aa19f1f5
|