def importDatabase(filename, numberOfBalls, numberOfPlayers): '''Opens up the specified Dodge Ball database, imports the information it contains, and generates the start condition of the game.''' #Creates an empty enviornment. court = Chunk_Module.Environment([]) #Imports the database database = open(filename) print '' print filename, "successfully opened." print '' #Establishes the empty list of balls, players, and pandas. ballList = [] playerList = [] for line in database: newline = line.split() if "Ball_{0}" in newline[2]: counter = 1 #Populates the environment with a number of dodge balls. for item in range(numberOfBalls): theThingx = newline[0] theRelation = newline[1] theThingy = newline[2].format(counter) counter = counter + 1 theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) ballList.append(theThingy) elif "Player_{0}" in newline[2]: counter = 1 #Populates the environment with a number of players. for item in range(numberOfPlayers): theThingx = newline[0] theRelation = newline[1] theThingy = newline[2].format(counter) counter = counter + 1 theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) playerList.append(theThingy) else: #Populates the environment with every other fact stated in the database. theThingx = newline[0] theRelation = newline[1] theThingy = newline[2] theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) #Turns balls and players into instances of Ball and Player classes. # Also splits the players into teams, and assigns starting positions to both balls and players. counter = 1 for item in ballList: if counter <= (len(ballList)) / 2: theThingx = item theRelation = 'Is_In' theThingy = 'Red_Court' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) counter = counter + 1 else: theThingx = item theRelation = 'Is_In' theThingy = 'Blue_Court' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) counter = counter + 1 counter = 1 for item in playerList: kitty = Game_Module.Player(item, 'kitty', Productions_Module.instantiateProduction(), Productions_Module.instantiateKnowledge()) #Note below that each instance of the player class is also appended # to the listOfAgents. This list is used by Run_Program. listOfAgents.append(kitty) if counter <= (len(playerList)) / 2: theThingx = item theRelation = 'Is_On' theThingy = 'Red_Team' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) theRelation = 'Is_In' theThingy = 'Red_Court' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) counter = counter + 1 else: theThingx = item theRelation = 'Is_On' theThingy = 'Blue_Team' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) theRelation = 'Is_In' theThingy = 'Blue_Court' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) counter = counter + 1 #Closes the database, prints the starting conditions of the simulation, # and returns the environment - which is used by Run_Program. database.close() for item in court.facts: print item.ID return court
def importDatabase(filename, numberOfBalls, numberOfPlayers): '''Opens up the specified Dodge Ball database, imports the information it contains, and generates the start condition of the game.''' #Creates an empty enviornment. court = Chunk_Module.Environment([]) #Imports the database database = open(filename) print '' print filename, "successfully opened." print '' #Establishes the empty list of balls, players, and pandas. ballList = [] playerList = [] for line in database: newline = line.split() if "Ball_{0}" in newline[2]: counter = 1 #Populates the environment with a number of dodge balls. for item in range(numberOfBalls): theThingx = newline[0] theRelation = newline[1] theThingy = newline[2].format(counter) counter = counter + 1 theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) ballList.append(theThingy) elif "Player_{0}" in newline[2]: counter = 1 #Populates the environment with a number of players. for item in range(numberOfPlayers): theThingx = newline[0] theRelation = newline[1] theThingy = newline[2].format(counter) counter = counter + 1 theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) playerList.append(theThingy) else: #Populates the environment with every other fact stated in the database. theThingx = newline[0] theRelation = newline[1] theThingy = newline[2] theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) #Turns balls and players into instances of Ball and Player classes. # Also splits the players into teams, and assigns starting positions to both balls and players. counter = 1 for item in ballList: if counter <= (len(ballList))/2: theThingx = item theRelation = 'Is_In' theThingy = 'Red_Court' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) counter = counter + 1 else: theThingx = item theRelation = 'Is_In' theThingy = 'Blue_Court' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) counter = counter + 1 counter = 1 for item in playerList: kitty = Game_Module.Player(item, 'kitty', Productions_Module.instantiateProduction(), Productions_Module.instantiateKnowledge()) #Note below that each instance of the player class is also appended # to the listOfAgents. This list is used by Run_Program. listOfAgents.append(kitty) if counter <= (len(playerList))/2: theThingx = item theRelation = 'Is_On' theThingy = 'Red_Team' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) theRelation = 'Is_In' theThingy = 'Red_Court' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) counter = counter + 1 else: theThingx = item theRelation = 'Is_On' theThingy = 'Blue_Team' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) theRelation = 'Is_In' theThingy = 'Blue_Court' theChunkID = theThingx, theRelation, theThingy Chunk_Module.Chunk3(court, theChunkID, theThingx, theRelation, theThingy) counter = counter + 1 #Closes the database, prints the starting conditions of the simulation, # and returns the environment - which is used by Run_Program. database.close() for item in court.facts: print item.ID return court