Chess player: Difference between revisions

Line 958:
A very simple chess engine using [https://github.com/niklasf/python-chess python-chess]. The computer plays Black. The program uses a two-ply search which computes material value for both sides and its own piece mobility after Black and White have made their moves.
 
The default Unicode board may look wonky and misaligned with certain terminal fonts. To use an ASCII board instead (like in the output shown below), replaceset "print(boardUNICODE = False.unicode())" withIf your terminal uses dark "print(board)"mode, inset theDARKMODE "pboard()"= functionTrue.
 
If your terminal uses dark mode, change the "pboard()" function to "print(board.unicode(invert_color=True))".
<lang python># Simple Python chess engine
# Computer plays Black
Line 966 ⟶ 964:
import sys, chess
from collections import Counter
 
UNICODE = True # Print board with Unicode symbols?
DARKMODE = False # Invert symbol colors?
 
board = chess.Board()
Line 974 ⟶ 975:
def pboard():
"Print board"
if UNICODE and DARKMODE:
print(board.unicode())
If your terminal uses dark mode, change the "pboard()" function to "print(board.unicode(invert_color=True))".
elif UNICODE:
print(board.unicode())
else:
print(board)
 
while not board.outcome():
Anonymous user