forked from oivas000/lichess-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrategies.py
36 lines (26 loc) · 1.01 KB
/
strategies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Some example strategies for people who want to create a custom, homemade bot.
"""
from __future__ import annotations
import chess
from chess.engine import PlayResult
import random
from engine_wrapper import MinimalEngine
from typing import Any
class ExampleEngine(MinimalEngine):
pass
# Strategy names and ideas from tom7's excellent eloWorld video
class RandomMove(ExampleEngine):
def search(self, board: chess.Board, *args: Any) -> PlayResult:
return PlayResult(random.choice(list(board.legal_moves)), None)
class Alphabetical(ExampleEngine):
def search(self, board: chess.Board, *args: Any) -> PlayResult:
moves = list(board.legal_moves)
moves.sort(key=board.san)
return PlayResult(moves[0], None)
class FirstMove(ExampleEngine):
"""Gets the first move when sorted by uci representation"""
def search(self, board: chess.Board, *args: Any) -> PlayResult:
moves = list(board.legal_moves)
moves.sort(key=str)
return PlayResult(moves[0], None)