Anonymous user
Chess player: Difference between revisions
→{{libheader|python-chess}}: play winning move immediately if possible
(→{{libheader|python-chess}}: needs more HAL 9000) |
(→{{libheader|python-chess}}: play winning move immediately if possible) |
||
Line 969:
def hal9000():
print("Thank you for a very enjoyable game.")
def pboard():
"Print board"
print(board.unicode())
while not board.outcome():
Line 974 ⟶ 978:
try:
move = input("Your move? ")
if move in ("q", "quit", "resign", "exit"):
hal9000()
sys.exit()
Line 984 ⟶ 988:
for mymove in board.legal_moves:
board.push(mymove)
if board.result() == "0-1": # Can Black win? If so, end the game.
print(mymove)
pboard()
print("I'm sorry, Frank. I think you missed it:")
pm = board.peek()
pn = chess.piece_name(board.piece_at(pm.to_square).piece_type)
ps = chess.square_name(pm.to_square)
print(f"{pn.capitalize()} to {ps}, mate.")
hal9000()
sys.exit()
for yourmove in board.legal_moves:
board.push(yourmove)
Line 1,000 ⟶ 1,015:
print(sel)
board.push(sel)
print(f"Game finished, result is {board.result()}")
|