Chess player: Difference between revisions

Content added Content deleted
(→‎{{libheader|python-chess}}: add some randomness as a tie breaker)
Line 959: Line 959:


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.
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.

Increasing RANDFAC, e.g. RANDFAC = 15, creates more variety in computer moves, so that there is less repetition in games and openings.


The computer may say some things that allude to the chess game in ''2001: A Space Odyssey'', by the way.
The computer may say some things that allude to the chess game in ''2001: A Space Odyssey'', by the way.
Line 969: Line 971:
UNICODE = True # Print board with Unicode symbols?
UNICODE = True # Print board with Unicode symbols?
DARKMODE = False # Invert symbol colors?
DARKMODE = False # Invert symbol colors?
RANDFAC = 1 # Randomness factor


board = chess.Board()
board = chess.Board()
Line 1,015: Line 1,018:
p = (9 * (v['q']-v['Q']) + 5 * (v['r']-v['R']) + 3 * (v['b']-v['B'])
p = (9 * (v['q']-v['Q']) + 5 * (v['r']-v['R']) + 3 * (v['b']-v['B'])
+ 3 * (v['n']-v['N']) + v['p'] - v['P'])
+ 3 * (v['n']-v['N']) + v['p'] - v['P'])
mobility = len(list(board.legal_moves)) + random.random()
mobility = len(list(board.legal_moves)) + RANDFAC * random.random()
p += mobility / 1000
p += mobility / 1000
#print(mymove, yourmove, p)
#print(mymove, yourmove, p)