#!/usr/bin/python import os.path #nxn board, in this case n = 10 n = 10 #will hold the positions similar to n-queens allPositions = [] #current state of board used for comparisons state = [] #defining captured and inaRow blackPairCap = 0 whitePairCap = 0 blackInaRow = 0 whiteInaRow = 0 #the initial state of the board is all blank #im storing each row of the board as a list #this is pretty much only for displaying the board row0 = [] row1 = [] row2 = [] row3 = [] row4 = [] row5 = [] row6 = [] row7 = [] row8 = [] row9 = [] #similar to the n-queens problem, #i'll make an allDirections list so i can test later for things such as #if it's next to another piece of itself or the opponent allDirections = [[-1, 0],[1, 0],[0, -1],[0, 1],[-1, -1],[-1, 1],[1, -1],[1, 1]] #creating all rules without precond or anything def createPositions(): for i in range(0,n): for j in range(0,n): allPositions.append([i,j]) #winner def winner(): if (blackPairCap == 5): print "White is the winner!" return True elif (whitePairCap == 5): print "Black is the winner!" return True elif (blackInaRow >= 5): print "Black is the winner!" return True elif (whiteInaRow >= 5): print "White is the winner!" return True else: inGameMenu() #for next function player1 = "" player2 = "" comp1 = "" comp2 = "" #current players currentPlayers = [] #save files list FILES = [] #startGameMenu def startGameMenu(): print "Do you have a save file that you would like to run the game from?\n" saveFile = raw_input("y or n") saveFile = str(saveFile) if saveFile == "y": fileName = raw_input("What is the name of the save file (with extension)? \n") FILES.append(fileName) f = open(fileName, 'r') for line in f: if line == 0: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 1: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 2: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 3: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 4: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 5: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 6: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 7: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 8: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 9: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) f.close() inGameMenu() elif saveFile == "n": print "Welcome to Pente!\n" print "Would you like to play a new game?\n" answer = raw_input("y or n:") answer = str(answer) if (answer == "y"): numPlayers = raw_input("How many players are going to be playing? (1-4):\n") numPlayers = int(numPlayers) for p in range(0,numPlayers): print "Would you like to be Player 1, Player 2, PC 1, or PC 2?\n" player = raw_input("p1, p2, pc1, or pc2:") player = str(player) if (player == "p1"): currentPlayers.append(player1) elif (player == "p2"): currentPlayers.append(player2) elif (player == "pc1"): currentPlayers.append(comp1) elif (player == "pc2"): currentPlayers.append(comp2) print "Which color would you like to play as?\n" color = raw_input("b (black) or w (white):") color = str(color) if (color == "b"): currentPlayers[p] = "black" elif (color == "w"): currentPlayers[p] = "white" inGameMenu() #defining players and their colors #inGameMenu def inGameMenu(): return #inGameMenu from save file def saveFileGame(): return #startGameMenu()
elif and else must have the same indentation than the corresponding if .
#!/usr/bin/python import os.path #nxn board, in this case n = 10 n = 10 #will hold the positions similar to n-queens allPositions = [] #current state of board used for comparisons state = [] #defining captured and inaRow blackPairCap = 0 whitePairCap = 0 blackInaRow = 0 whiteInaRow = 0 #the initial state of the board is all blank #im storing each row of the board as a list #this is pretty much only for displaying the board row0 = [] row1 = [] row2 = [] row3 = [] row4 = [] row5 = [] row6 = [] row7 = [] row8 = [] row9 = [] #similar to the n-queens problem, #i'll make an allDirections list so i can test later for things such as #if it's next to another piece of itself or the opponent allDirections = [[-1, 0],[1, 0],[0, -1],[0, 1],[-1, -1],[-1, 1],[1, -1],[1, 1]] #creating all rules without precond or anything def createPositions(): for i in range(0,n): for j in range(0,n): allPositions.append([i,j]) #winner def winner(): if (blackPairCap == 5): print "White is the winner!" return True elif (whitePairCap == 5): print "Black is the winner!" return True elif (blackInaRow >= 5): print "Black is the winner!" return True elif (whiteInaRow >= 5): print "White is the winner!" return True else: inGameMenu() #for next function player1 = "" player2 = "" comp1 = "" comp2 = "" #current players currentPlayers = [] #save files list FILES = [] #startGameMenu def startGameMenu(): print "Do you have a save file that you would like to run the game from?\n" saveFile = raw_input("y or n") saveFile = str(saveFile) if saveFile == "y": saveFileGame() elif saveFile == "n": newGame() #defining players and their colors #inGameMenu def inGameMenu(): return #new game def newGame(): print "Welcome to Pente!\n" print "Would you like to play a new game?\n" answer = raw_input("y or n:") answer = str(answer) if (answer == "y"): numPlayers = raw_input("How many players are going to be playing? (1-4):\n") numPlayers = int(numPlayers) for p in range(0,numPlayers): print "Would you like to be Player 1, Player 2, PC 1, or PC 2?\n" player = raw_input("p1, p2, pc1, or pc2:") player = str(player) if (player == "p1"): currentPlayers.append(player1) elif (player == "p2"): currentPlayers.append(player2) elif (player == "pc1"): currentPlayers.append(comp1) elif (player == "pc2"): currentPlayers.append(comp2) print "Which color would you like to play as?\n" color = raw_input("b (black) or w (white):") color = str(color) if (color == "b"): currentPlayers[p] = "black" elif (color == "w"): currentPlayers[p] = "white" inGameMenu() #inGameMenu from save file def saveFileGame(): fileName = raw_input("What is the name of the save file (with extension)? \n") FILES.append(fileName) f = open(fileName, 'r') for line in f: if line == 0: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 1: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 2: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 3: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 4: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 5: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 6: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 7: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 8: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 9: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) f.close() inGameMenu() #startGameMenu()
#!/usr/bin/python import os.path #nxn board, in this case n = 10 n = 10 #will hold the positions similar to n-queens allPositions = [] #current state of board used for comparisons state = [] #defining captured and inaRow blackPairCap = 0 whitePairCap = 0 blackInaRow = 0 whiteInaRow = 0 #the initial state of the board is all blank #im storing each row of the board as a list #this is pretty much only for displaying the board row0 = [] row1 = [] row2 = [] row3 = [] row4 = [] row5 = [] row6 = [] row7 = [] row8 = [] row9 = [] #similar to the n-queens problem, #i'll make an allDirections list so i can test later for things such as #if it's next to another piece of itself or the opponent allDirections = [[-1, 0],[1, 0],[0, -1],[0, 1],[-1, -1],[-1, 1],[1, -1],[1, 1]] #creating all rules without precond or anything def createPositions(): for i in range(0,n): for j in range(0,n): allPositions.append([i,j]) #winner def winner(): if (blackPairCap == 5): print "White is the winner!" return True elif (whitePairCap == 5): print "Black is the winner!" return True elif (blackInaRow >= 5): print "Black is the winner!" return True elif (whiteInaRow >= 5): print "White is the winner!" return True else: inGameMenu() #for next function player1 = "" player2 = "" comp1 = "" comp2 = "" #current players currentPlayers = [] #save files list FILES = [] #startGameMenu def startGameMenu(): print "Do you have a save file that you would like to run the game from?\n" saveFile = raw_input("y or n") saveFile = str(saveFile) if saveFile == "y": fileName = raw_input("What is the name of the save file (with extension)? \n") FILES.append(fileName) f = open(fileName, 'r') for line in f: if line == 0: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 1: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 2: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 3: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 4: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 5: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 6: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 7: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 8: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) if line == 9: row0.extend([line[0],line[1],line[2],line[3],line[4],line[5],line[6],line[7],line[8],line[9]]) f.close() inGameMenu() elif saveFile == "n": newGame() #defining players and their colors #inGameMenu def inGameMenu(): return #inGameMenu from save file def saveFileGame(): return #newGame def newGame(): print "Welcome to Pente!\n" print "Would you like to play a new game?\n" answer = raw_input("y or n:") answer = str(answer) if (answer == "y"): numPlayers = raw_input("How many players are going to be playing? (1-4):\n") numPlayers = int(numPlayers) for p in range(0,numPlayers): print "Would you like to be Player 1, Player 2, PC 1, or PC 2?\n" player = raw_input("p1, p2, pc1, or pc2:") player = str(player) if (player == "p1"): currentPlayers.append(player1) elif (player == "p2"): currentPlayers.append(player2) elif (player == "pc1"): currentPlayers.append(comp1) elif (player == "pc2"): currentPlayers.append(comp2) print "Which color would you like to play as?\n" color = raw_input("b (black) or w (white):") color = str(color) if (color == "b"): currentPlayers[p] = "black" elif (color == "w"): currentPlayers[p] = "white" inGameMenu() #startGameMenu()
Ugh I hate these elif errors!
## instead of if line == 0 ,1 2, etc. for line in f: if (line > -1) and (line < 10): row0.extend([line[x] for x in range (0, 10)]) ## ##------------------------------------------------------------------ """ #the initial state of the board is all blank #im storing each row of the board as a list #this is pretty much only for displaying the board row0 = [] row1 = [] row2 = [] row3 = [] row4 = [] row5 = [] row6 = [] row7 = [] row8 = [] row9 = [] """ ## use a list of lists or a dictionary instead ## this is a dictionary with the key = 0 --> 9 instead ## of row0 --> row9 row_dic = {} for j in range(0, 10): row_dic[j] = [] ## ##------------------------------------------------------------------ """ instead of elif (player == "p2"):, etc. """ player_dic = {} player_dic["p1"] = player1 player_dic["p2"] = player2 player_dic["pc1"] = comp1 player_dic["pc2"] = comp2 for p in range(0,numPlayers): print "Would you like to be Player 1, Player 2, PC 1, or PC 2?\n" player = raw_input("p1, p2, pc1, or pc2:") player = player.lower() if (player in player_dic): currentPlayers.append( player_dic[player] ) else: print "That is not a valid player"
| DaniWeb Message | |
| Cancel Changes | |