A very simple FICS bot in Python

Below is a Python code for a very simple bot that logs in into FICS, ask for a username and password that one must manually enter and then the bot will chat in channel 53, a channel for general discussion where guests can participate.

The code assume that you have a file called “random-words.txt” in /path-to/ directory. You can edit those according to your needs. The bot will randomly pick lines in the text file and send them in the 53th channel. It will do so at a rate of 1 line every 30 seconds by default, but this is adjustable.

Have fun editing and using this bot!


import getpass
import sys
import telnetlib
import string
import time
import random

HOST = "freechess.org"
# user = raw_input("Enter your user name account: ")
user = input("Enter your user name account: ")
password = input("Enter your password: ")
user_bytes = user.encode('utf-8')
password_bytes = password.encode('utf-8')

tn = telnetlib.Telnet(HOST)

tn.read_until(b"login: ")
tn.write(user_bytes + b"\n")
tn.write(password_bytes + b"\n")
tn.read_until(b":")
tn.write(b"\n")
tn.write(b"set tell 1\n")
tn.write(b"set pin 1\n")
tn.write(b"tell 53 Hello, I am a robot!\n")

word_file = "/path-to/random-words.txt"
WORDS = open(word_file).read().splitlines()

while 1:
    word = random.choice(WORDS)
    word_bytes = word.encode('utf-8')
    tn.write(b"t 53 " + word_bytes + b"\n")
    time.sleep(30)

Average number of stones randomly placed on a 19×19 goban so that 2 are adjacent

This time what caught my attention was the average number of stones ramdomly placed on a 19×19 goban required such that 2 stones are adjacent.

So I’ve written a python program (https://github.com/arbolis/pythonstuff/blob/master/goproblem_random/gorandom_1.py) and a R script for the plotting part (https://github.com/arbolis/personalscripts/blob/master/goban_random.R) to solve the problem numerically. It turns out that the number is around 13.1 which, in my opinion, is counter intuitive in the sense that most go players expect that number to be much higher (scarce are the go players who predicted a number below 30).

Anyway here is a summary of the data after 1,000,000 simulations of placing stones on a 19×19 goban until 2 stones are adjacent:

Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
2.00    8.00   12.00   12.97   17.00   49.00

And there comes a bar plot:bar-plot-go-19x19

I find that plot interesting and the summary of the data interesting.

Now I could get similar data for the 8×8 chessboard. Out of my memory the number of pieces randomly placed on a chessboard until 2 are adjacent is around 6.1. I expect a similar histogram than the one for the game of go somehow, except that the width of the distribution should be much smaller.