Chess player: Difference between revisions
Content added Content deleted
Line 958: | 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. |
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), |
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), set UNICODE = False. If your terminal uses dark mode, set DARKMODE = True. |
||
⚫ | |||
<lang python># Simple Python chess engine |
<lang python># Simple Python chess engine |
||
# Computer plays Black |
# Computer plays Black |
||
Line 966: | Line 964: | ||
import sys, chess |
import sys, chess |
||
from collections import Counter |
from collections import Counter |
||
UNICODE = True # Print board with Unicode symbols? |
|||
DARKMODE = False # Invert symbol colors? |
|||
board = chess.Board() |
board = chess.Board() |
||
Line 974: | Line 975: | ||
def pboard(): |
def pboard(): |
||
"Print board" |
"Print board" |
||
if UNICODE and DARKMODE: |
|||
⚫ | |||
⚫ | |||
elif UNICODE: |
|||
⚫ | |||
else: |
|||
print(board) |
|||
while not board.outcome(): |
while not board.outcome(): |