Example #1
0
class GridManager:
	# Constructor
	def __init__(self):
		self.__grid = Grid()
		self.__gamePlayer = GamePlayer()
		self.__userPlayer = UserPlayer()

	# Start Game
	def startGame(self):
		# Will continue toggling between
		# Game and User turns until the
		# Grid is Full (which is a loss)
		# or a 2048 tile is encountered
		# (which is a win)
		while (not self.__grid.gridContains(2048)):
			self.__gamePlayer.makeMove(self.__grid)

			self.__grid.printGrid()

			if (not self.__userPlayer.makeMove(self.__grid)):
				print "User Lost!"
				break

		if (self.__grid.gridContains(2048)):
			print "User Won!"
Example #2
0
    def __init__(self, players, verbose=True):
        self.max_rounds = MIN_ROUNDS + int(random.expovariate(1/(AVERAGE_ROUNDS - MIN_ROUNDS)))
        self.round = 0
        self.gameRoundList = []

        self.gamePlayerList = []
        #For each player, we're going to construct a "GamePlayer" object to help us keep
        #track of food and reputation and whatnot.
        for eachPlayer in players:
        	newGamePlayer = GamePlayer()
        	#Start the players off with 300*(P - 1) food
        	newGamePlayer.food = (len(players) - 1) * 300
        	newGamePlayer.player = eachPlayer

        	self.gamePlayerList += [newGamePlayer]
Example #3
0
    def NewSimulation(self, gameSource, numPlayers, generations,
                      gamesPerGeneration):
        self.activePlayers = []
        self.inactivePlayers = []
        self.avgScores = []
        self.generations = generations
        self.gamesPerGeneration = gamesPerGeneration

        try:
            for i in range(numPlayers):
                game = gameSource()
                self.inactivePlayers.append(
                    GamePlayer(NeuralNet([16, 32, 32, 4], 0.01), game,
                               self.bus))
        except:
            super().SendEvent(SIMULATION_CREATION_FAILED())
            self.hasActiveSim = False
            return

        self.ResetGamePlayers()
        self.hasActiveSim = True
        super().SendEvent(SIMULATION_CREATION_SUCCESS())
Example #4
0
	def __init__(self):
		self.__grid = Grid()
		self.__gamePlayer = GamePlayer()
		self.__userPlayer = UserPlayer()