class Connect4(object):
    def __init__(self):
        self.pieces = [[] for i in xrange(7)]
        self.turn = 0

    def check(self, column):
        vectors = ((1, 0), (1, 1), (0, 1), (-1, 1))
        for i in xrange(4):
            row = []
            for j in xrange(-3, 4):
                try:
                    if column + j*vectors[i][0] >= 0 and len(self.pieces[column]) - 1 + j*vectors[i][1] >= 0:
                        row.append(self.pieces[column + j*vectors[i][0]][len(self.pieces[column]) - 1 + j*vectors[i][1]])
                    else:
                        row.append(None)
                except IndexError:
                    row.append(None)
            for j in xrange(4):
                if row[j] == row[j + 1] == row[j + 2] == row[j + 3] is not None:
                    return row[j]
        if sum(len(piece_column) for piece_column in self.pieces) == 42:
            return 2

    def move(self, column):
        for i in xrange(column, column + 7):
            if len(self.pieces[i % 7]) < 6:
                self.pieces[i % 7].append(self.turn)
                self.turn = 1 - self.turn
                return self.check(i % 7)

    def input(self, inputs):
        return self.move(sum(j*2**i for i, j in enumerate(inputs)))

    def output(self):
        return [piece for piece_column in self.pieces for piece in piece_column + [1] + [0] * (6 - len(piece_column))]

    def __str__(self):
        output = ''
        for i in xrange(6):
            output += i and '\n|' or '|'
            for piece_column in self.pieces:
                try:
                    output += piece_column[5 - i] and 'X|' or 'O|'
                except IndexError:
                    output += ' |'
        output += '\n 0 1 2 3 4 5 6 '
        return output


def start():
    players = input('Players: ')
    if players == 2:
        connect4 = Connect4()
        while True:
            print connect4
            winner = connect4.move(column=input('{0}\'s turn: '.format(connect4.turn and 'X' or 'O')))
            if winner is not None:
                print connect4
                if winner == 2:
                    print "It's a tie!"
                else:
                    print "{0} wins!".format(winner and 'X' or 'O')
                break

@@ -1,8 +1,44 @@
+from ANN.ANN import NeuralNetwork%0A%0A%0A
 class Co
@@ -1863,16 +1863,654 @@
 ers: ')%0A
+    if players == 1:%0A        connect4 = Connect4()%0A        ANN = NeuralNetwork(49, 3, 49, 2)%0A        while True:%0A            print connect4%0A            if connect4.turn == 0:%0A                winner = connect4.move(column=input('%7B0%7D%5C's turn: '.format(connect4.turn and 'X' or 'O')))%0A            else:%0A                winner = connect4.input(inputs=ANN.calculate(inputs=connect4.output()))%0A            if winner is not None:%0A                print connect4%0A                if winner == 2:%0A                    print %22It's a tie!%22%0A                else:%0A                    print %22%7B0%7D wins!%22.format(winner and 'X' or 'O')%0A                break%0A
     if p

Add option to play against ANN