Python Toy chess engine

  • From: "R Dinger" <rrdinger@xxxxxxxxxx>
  • To: "programming" <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 9 Dec 2009 16:27:20 -0800

Code follows:
--------
# test.py a simulated chess engine

import sys

# chess engine main processing loop:
while True:
  # get player's move from GUI:
  playerMove = sys.stdin.readline().strip('\n')

  # process command:
  if playerMove == 'e4':
    engineMove = 'e5'
  elif playerMove == 'd4':
    engineMove = 'd5'
  else:
    engineMove = 'Unknown move!'

  # send the engine response move back:
  sys.stdout.write("%s\n" % engineMove)
  # the following seems required:
  sys.stdout.flush()

Other related posts: