def run(self, verbose=False): agentIndex = 0 while not self.gameState.isGameOver(): if verbose and agentIndex == 0: util.printGrid(self.gameState.board.grid) print self.agents[0].evaluator.featureExtractor(self.gameState) agent = self.agents[agentIndex] action = agent.getAction(self.gameState) if verbose: self.moveHistory.append((agentIndex, action)) if action is None: break self.gameState = self.gameState.generateSuccessor(agentIndex, action) agentIndex = (agentIndex + 1) % len(self.agents) #print self.moveHistory #util.printGrid(self.moveHistory[-3][1][0]) if verbose: print 'Final score:', self.gameState.score print 'Lines completed:', self.gameState.lines print 'Pieces played:', self.gameState.rounds - 1
oPiece = 'L' else: # id == 6 oPiece = 'J' return oPiece def pieceByName(name): if name == 'O': return OPiece() elif name == 'I': return IPiece() elif name == 'T': return TPiece() elif name == 'S': return SPiece() elif name == 'Z': return ZPiece() elif name == 'L': return LPiece() elif name == 'J': return JPiece() return None defaultList = [IPiece(), OPiece(), TPiece(), SPiece(), ZPiece(), LPiece(), JPiece()] if __name__ == "__main__": l = [IPiece(), OPiece(), TPiece(), SPiece(), ZPiece(), LPiece(), JPiece()] for x in l: print x, '(%d rotations)' % len(x.getRotations()), '[id=%d]' % x.id for rotation in x.getRotations(): util.printGrid(rotation.grid)