Skip to content

Instantly share code, notes, and snippets.

@akkartik
Created September 15, 2011 06:27
Show Gist options
  • Save akkartik/1218667 to your computer and use it in GitHub Desktop.
Save akkartik/1218667 to your computer and use it in GitHub Desktop.
Nakamura - Fierro Baquero, Kings vs Queens Tournament, 2011
from sys import stdout, stdin
from string import atoi
import copy
p = 'p'
r = 'r'
n = 'n'
b = 'b'
q = 'q'
k = 'k'
P = '\033[1;33mP\033[m'
R = '\033[1;33mR\033[m'
N = '\033[1;33mN\033[m'
B = '\033[1;33mB\033[m'
Q = '\033[1;33mQ\033[m'
K = '\033[1;33mK\033[m'
_ = ' '
# Nakamura - Fierro Baquero, 2011, Chess960
# http://chessbase.com/newsdetail.asp?newsid=7527
board = [[q, r, k, r, b, b, n, n],
[p, p, p, p, p, p, p, p],
[_, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _],
[_, _, _, _, _, _, _, _],
[P, P, P, P, P, P, P, P],
[Q, R, K, R, B, B, N, N]]
# Uppercase = White, lowercase = black, n = knight
origBoard = copy.deepcopy(board)
movelist = [7274, 5755, 8173, 8876, 7385, 4746, 4244, 5847, 6263, 6765, 7465,
4765, 5254, 6547, 4143, 7866, 8566, 7766, 2141, 6886, 3121, 4868, 5162,
2848, 4313, 1716, 2224, 1817, 7183, 4783, 6183, 3828, 6271, 1726, 1122,
5544, 7144, 2636, 2425]
currMove = 0
def display():
runMoves()
print
print ' + - - - - - - +'
for i in range(0, 8):
stdout.write(' %d ' % (8-i))
for j in range(0, 8):
stdout.write('%s ' % (board[i][j]))
print
print ' + - - - - - - +'
print ' a b c d e f g h'
print """
. - forward
, - back
0 - restore
Ctrl-c - quit"""
def restore():
for i in range(0, 8):
for j in range(0, 8):
board[i][j] = origBoard[i][j]
def readMove():
global currMove
x = raw_input('? ')
if x == '0':
currMove = 0
elif x == ',':
currMove = currMove-1
else:
currMove = currMove+1
def runMove(a):
# x is row and y is col.
tx = 8-a%10; a = a/10
ty = a%10-1; a = a/10
fx = 8-a%10; a = a/10
fy = a%10-1; a = a/10
board[tx][ty] = board[fx][fy]
board[fx][fy] = _
def runMoves():
restore()
for a in movelist[:currMove]:
runMove(a)
try:
while 1:
display()
readMove()
except KeyboardInterrupt:
print
except EOFError:
print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment