This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConnectFour(object): | |
def __init__(self): | |
self.board = [[' ']*7 for i in range(6)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def to_string(self): | |
sBoard = '' | |
for row in self.board: | |
for section in row: | |
sBoard += "( %s )" % section | |
sBoard += '\n-----------------------------------\n' | |
sBoard += ' 0 1 2 3 4 5 6' | |
return sBoard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConnectFour(object): | |
def __init__(self): | |
self.board = [[' ']*7 for i in range(6)] | |
def to_string(self): | |
sBoard = '' | |
for row in self.board: | |
for section in row: | |
sBoard += "( %s )" % section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConnectFour(object): | |
def __init__(self): | |
self.board = [[' ']*7 for i in range(6)] | |
def to_string(self): | |
sBoard = '' | |
for row in self.board: | |
for section in row: | |
sBoard += "( %s )" % section |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def start(self): | |
print self.to_string() | |
while True: | |
self.turn() | |
if(self.is_winner() == True): | |
print "Winner!" | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def start(self): | |
print self.to_string() | |
while True: | |
self.turn(self.p1) | |
if(self.is_winner(self.p1) == True): | |
print "Winner:", self.p1 | |
break | |
self.turn(self.p2) | |
if(self.is_winner(self.p2) == True): | |
print "Winner:", self.p2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConnectFour(object): | |
def __init__(self): | |
self.p1 = 'X' | |
self.p2 = 'O' | |
self.board = [[' ']*7 for i in range(6)] | |
def to_string(self): | |
sBoard = '' | |
for row in self.board: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def turn(self, player): | |
if (player == self.p1): | |
while True: | |
col = int(raw_input('p1>')) | |
if (self.board[0][col] == ' '): | |
break | |
else: | |
while True: | |
col = int(raw_input('p2>')) | |
if (self.board[0][col] == ' '): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_winner(self, player): | |
if (self.diagonal(player) == True or self.horizontal(player) == True or self.vertical(player) == True): | |
return True, False | |
if ( self.board[0][0] != ' ' and self.board[0][1] != ' ' and self.board[0][2] != ' ' and self.board[0][3] != ' ' and self.board[0][4] != ' ' and self.board[0][5] != ' ') and self.board[0][6] != ' ': | |
return False, True | |
return False, False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ConnectFour(object): | |
def __init__(self): | |
self.p1 = 'X' | |
self.p2 = 'O' | |
self.board = [[' ']*7 for i in range(6)] | |
def to_string(self): | |
sBoard = '' | |
for row in self.board: |