Original code taken from ttt-computer