2020 04 17


Reading time: about 1 minute

Collecting Style 12 chess data

Style 12 is a data format used by Internet Chess Servers and clients to exchange information about chess games.

The protocol for connecting to an Internet Chess Server is relatively simple. It is a text-based protocol. It looks like it was designed to be used by humans rather than computers, but things like Style 12 try to make it easier for computers to parse the data.

The Python code I used to collect the data is given below.

import socket

full = False

s = socket.socket()
s.connect(("freechess.org", 5000))

# Not Full: Removing game 166 from observation list.
# Full: You are already observing the maximum number of games.

f = s.makefile('rwb')

f.write(b'guest\n')
f.flush()

for line in f:
    line = line.strip()
    if line.startswith(b'Press return to enter the server'):
        f.write(b'\n')
        f.flush()
        break

f.write(b'set style 12\n')
f.flush()

with open('style12.txt', 'a+') as logfile:
    for line in f:
        line = line.strip()
        if b'Removing game' in line and b'from observation list.' in line:
            full = False
        if b'You are already observing the maximum number of games.' in line:
            full = True
        if not full:
            f.write(b"observe *\r\n")
            f.flush()
        if line.startswith(b'<12>'):
            logfile.write(f"{line.decode('utf-8')}\n")
        print(line)

Citation

If you find this work useful, please cite it as:
@article{yaltirakli,
  title   = "2020 04 17",
  author  = "Yaltirakli, Gokberk",
  journal = "gkbrk.com",
  year    = "2024",
  url     = "https://www.gkbrk.com/journal/2020-04-17"
}
Not using BibTeX? Click here for more citation styles.
IEEE Citation
Gokberk Yaltirakli, "2020 04 17", November, 2024. [Online]. Available: https://www.gkbrk.com/journal/2020-04-17. [Accessed Nov. 12, 2024].
APA Style
Yaltirakli, G. (2024, November 12). 2020 04 17. https://www.gkbrk.com/journal/2020-04-17
Bluebook Style
Gokberk Yaltirakli, 2020 04 17, GKBRK.COM (Nov. 12, 2024), https://www.gkbrk.com/journal/2020-04-17

Comments

© 2024 Gokberk Yaltirakli