Skip to content

Commit

Permalink
Put everything in 4DManager and wrote print board func
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Nattestad committed Apr 23, 2013
1 parent 140f4a6 commit 8ddadc2
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 15 deletions.
62 changes: 60 additions & 2 deletions 4DManager.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,65 @@
import metaBoard
import bigBoard
import smallBoard

class small_board():
def __init__(self):
self.smallBoardList = ["X" for i in range(9)]

class big_board(): #tic-tac-toe board object
def __init__(self):
self.bigBoardList = [small_board() for i in range(9)]

#prints out the board
def print_board(self):
print("#########################")
print("# # # #")

for m in range(0,9,3):
for k in range(0, 9, 3):
toPrintString = "# "
for i in range(0, 3):
for j in range(0,3):
toPrintString += self.bigBoardList[i+m].smallBoardList[j+k]
if(j != 2):
toPrintString += "|"
else:
toPrintString += " # "

print(toPrintString)
if(m != 6):
print("# # # #")
print("#########################")
print("# # # #")
print("# # # #")
print("#########################")

class aGame():
numPlayers = 0

def __init__(self):
theBigBoard = big_board()
def getPlayers(self):
numPlayers = input("Number of Players: ")
playersSymbol = []
numPlayers = int(numPlayers)
for i in range(0, numPlayers):
isValidInput = False
while(not isValidInput):
inputAsk = "Player number " + str(i+1) + " symbol is : "
playersSymbol += input(inputAsk)
if(len(playersSymbol[i]) == 1):
isValidInput = True
else:
playersSymbol.pop()

def printPlayers(self):
for i in range(0, numPlayers):
print("Player " + i + " is symbol " + playerSymbol[i])

def startGame(self):
self.getPlayers()


theGame = aGame()
theGame.startGame()
theGame.printPlayers()

28 changes: 15 additions & 13 deletions bigBoard.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import smallBoard

class meta_board(): #tic-tac-toe board object
class big_board(): #tic-tac-toe board object
def __init__(self):
self.board_list = [tic_tac_toe_board() for i in range(9)] #create list of boards
self.win_list = [None for i in range(9)] #create empty list to hold the winners of the boards

def check_win_p(self): #returns the wining player
for player in ('x', 'o'): #iterate through the players
positions = set(get_player_wins(player)) #create a set of the boards the player has won
for win_line in win_combos: #iterate through every possible winning combination
win = True #set the default to True
for pos in win_line: #compare positions
if pos not in positions: #if any positions is not in the winnign combination
win = False #set it to False
break #escape loop
if win:
return player #return the winning player
return None #return None if no one won
for player in ('x', 'o'): #iterate through the players
positions = set(get_player_wins(player)) #create a set of the boards the player has won
for win_line in win_combos: #iterate through every possible winning combination
win = True #set the default to True
for pos in win_line: #compare positions
if pos not in positions: #if any positions is not in the winnign combination
win = False #set it to False
break #escape loop
if win:
return player #return the winning player
return None #return None if no one won

def get_player_wins(self, player): #returns a list of all boards the player has won
return [pos for pos, value in enumerate(self.win_list) if value == player]
Expand All @@ -29,4 +29,6 @@ def is_board_full(board_pos): #checks if specific board is full
if len(self.board_list[board_pos].available_moves()) == 0:
return True
else:
return False
return False
def print_board(self):
pass

0 comments on commit 8ddadc2

Please sign in to comment.