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

Bogoliubon
  • 1,623 Reads
  • 3 Comments

For those of us whose friends include command terminals, I wrote a quick little python code to do the first exercise in Daniel Rensch's 'Achieving Full Board Awareness' lectures.  Save the following lines of codes to a .py file and run it at a terminal.  A square name will pop up, enter lower case 'b' if the square is black and 'w' if the square is white.  After 15 squares are completed succesfully the time the exercise took will be posted. 

  Enjoy,

     Bogoliubon

 

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):
        if (i+j)%2 == 0:
            exec('coordinates.update('+files[i]+rank[j]+'=\'b\')')
        else:
            exec('coordinates.update('+files[i]+rank[j]+'=\'w\')')

print 'enter b if the square is black or w if square is white'

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

Online Now