Upgrade to Chess.com Premium!

Python Code for Daniel Rensch's "Achieving Full Board Awareness" Lecture, part II

Next, here is a code for the second exercise.  When a square is printed type the 'brother' or 'corresponding' square and click enter.

 

from random import choice
from time import time

files = ['a','b','c','d','e','f','g','h']
rank = [str(i+1) for i in range(8)]
coordinates = {}

for i in range(8):
    for j in range(8):
        exec('coordinates.update('+files[i]+rank[j]+'=\''+files[7-i]+rank[7-j]+'\')')

print 'enter the corresponding square to the square printed'

start_time = time()

for i in range(15):
    tmp = choice(coordinates.keys())
    ans = coordinates[tmp]
    Bogoliubon = 0
    while Bogoliubon != ans:
        Bogoliubon = raw_input(tmp+" ")

end_time = time()

print 'exercise finished in ', end_time-start_time, ' seconds.'

 

from random import choice
from time import time

files = ['a','b','c','d','e','f','g','h']
rank = [str(i+1) for i in range(8)]
coordinates = {}

for i in range(8):
    for j in range(8):
        exec('coordinates.update('+files[i]+rank[j]+'=\''+files[7-i]+rank[7-j]+'\')')

print 'enter the corresponding square to the square printed'

start_time = time()

for i in range(15):
    tmp = choice(coordinates.keys())
    ans = coordinates[tmp]
    Bogoliubon = 0
    while Bogoliubon != ans:
        Bogoliubon = raw_input(tmp+" ")

end_time = time()

print 'exercise finished in ', end_time-start_time, ' seconds.'

Comments


  • 13 months ago

    DrFrank124c

    Can u give the code in Java Script? My Python is rusty!

Back to Top

Post your reply: