Python 3

Using the code provided you will build a networked Connect Four game, which enables gameplay between two users, using console user interfaces, on a networked connection. While doing this, you will implement your own protocol to define how the client and server are to “talk” to one another.

-There should be a file named which contains the console UI for printing out the board object and a server object for network communications

-There should be a file named which contains the console UI for interacting with the user and printing out the board object. It will construct a “game client “object which uses sockets for communicating with the server

-You shouldn't need to call any functions manually to make your program run

-client, game_client, and your Connect Four module must have mutually exclusive functionality

client: Prints and inputs only, no socket communication, no game logic

game_client: Socket communication only, no prints or inputs, no game logic

Connect Four: Game logic only, no prints or inputs, no socket communication

Connect Four Game

class connectFour(object):
def __init__(self):
self.player = 'R'
self.board = gboard
def __str__(self):
a = ” ”
r2= a.join(self.board[5])
r3= a.join(self.board[4])
r4= a.join(self.board[3])
r5= a.join(self.board[2])
r6= a.join(self.board[1])
r7= a.join(self.board[0])
return ” 1 2 3 4 5 6 7n %sn %sn %sn %sn %sn %sn” % (r7, r6, r5, r4, r3, r2)
def __new__(self):
return object.__new__(self)
def player_getBoard(self):
return self.board
def gameOver(self, player):
board = connectFour.player_getBoard(self)
for c in range(4):
for r in range(6):
if board[r][c] == player and board[r][c+1] == player and board[r][c+2] == player and board[r][c+3] == player:
return True
for c in range(6):
for r in range(3):
if board[r][c] == player and board[r+1][c] == player and board[r+2][c] == player and board[r+3][c] == player:
return True
for c in range(4):
for r in range(3):
if board[r][c] == player and board[r+1][c+1] == player and board[r+2][c+2] == player and board[r+3][c+3] == player:
return True
for c in range(4):
for r in range(3, 6):
if board[r][c] == player and board[r-1][c+1] == player and board[r-2][c+2] == player and board[r-3][c+3] == player:
return True
for c in range(len(self.board)):
for r in self.board[c]:
if r == '.':
if counter==0:
return True
def playerTurn(self, player):
if connectFour.gameOver(self, player):
self.player = “Winner is player {}”.format(player)
return self.player
elif player == 'R':
self.player = 'Y'
return self.player
self.player = 'R'
return self.player
def playerMove(self, player, col):
row = 5
while True:
if self.board[row][col] == '.':
self.board[row][col] = player
return “success”
row -= 1
except IndexError:
return “Error”
except TypeError:
return “Error”
return self.board


from connectFour import connectFour

if __name__ == '__main__':
   player = 'R'
game = connectFour()
print(“Game start”)
while True and player == “R” or player == “Y”:
print(“Player”, player, “Enter column between 1 and 7):”)   
move = int(input())
if game.playerMove(player, move-1) == 'success':
player = game.playerTurn(player)
except ValueError:
print('Make another move')

"Get 15% discount on your first 3 orders with us"
Use the following coupon

Order Now