Esempio n. 1
0
 def __init__(self, size, opponent=None, **args):
     EpisodicTask.__init__(self, GomokuGame((size, size)))
     self.setArgs(**args)
     if opponent == None:
         opponent = RandomGomokuPlayer(self.env)
     elif isclass(opponent):
         # assume the agent can be initialized without arguments then.
         opponent = opponent(self.env)
     if not self.opponentStart:
         opponent.color = GomokuGame.WHITE
     self.opponent = opponent
     self.minmoves = 9
     self.maxmoves = self.env.size[0] * self.env.size[1]
     self.reset()
Esempio n. 2
0
 def __init__(self, size, opponent = None, **args):        
     EpisodicTask.__init__(self, GomokuGame((size, size)))
     self.setArgs(**args)
     if opponent == None:
         opponent = RandomGomokuPlayer(self.env)
     elif isclass(opponent):
         # assume the agent can be initialized without arguments then.
         opponent = opponent(self.env)
     if not self.opponentStart:
         opponent.color = GomokuGame.WHITE
     self.opponent = opponent
     self.minmoves = 9
     self.maxmoves = self.env.size[0] * self.env.size[1]
     self.reset()
Esempio n. 3
0
 def __init__(self, size, opponent=None, **args):
     EpisodicTask.__init__(self, CaptureGame(size))
     self.setArgs(**args)
     if opponent == None:
         opponent = RandomCapturePlayer(self.env)
     elif isclass(opponent):
         # assume the agent can be initialized without arguments then.
         opponent = opponent(self.env)
     else:
         opponent.game = self.env
     if not self.opponentStart:
         opponent.color = CaptureGame.WHITE
     self.opponent = opponent
     self.maxmoves = self.env.size * self.env.size
     self.minmoves = 3
     self.reset()
Esempio n. 4
0
 def __init__(self, size, opponent=None, **args):
     EpisodicTask.__init__(self, CaptureGame(size))
     self.setArgs(**args)
     if opponent == None:
         opponent = RandomCapturePlayer(self.env)
     elif isclass(opponent):
         # assume the agent can be initialized without arguments then.
         opponent = opponent(self.env)
     else:
         opponent.game = self.env
     if not self.opponentStart:
         opponent.color = CaptureGame.WHITE
     self.opponent = opponent
     self.maxmoves = self.env.size * self.env.size
     self.minmoves = 3
     self.reset()
Esempio n. 5
0
 def __call__(self, x):
     """ If a module is given, wrap it into a ModuleDecidingAgent before evaluating it. 
     Also, if applicable, average the result over multiple games. """
     if isinstance(x, Module):
         agent = ModuleDecidingPlayer(x, self.env, greedySelection = True)
     elif isinstance(x, GomokuPlayer):
         agent = x
     else:
         raise NotImplementedError('Missing implementation for '+x.__class__.__name__+' evaluation')
     res = 0
     agent.game = self.env
     self.opponent.game = self.env
     for dummy in range(self.averageOverGames):
         agent.color = -self.opponent.color
         res += EpisodicTask.__call__(self, agent)            
     return res / float(self.averageOverGames)
Esempio n. 6
0
 def __call__(self, x):
     """ If a module is given, wrap it into a ModuleDecidingAgent before evaluating it. 
     Also, if applicable, average the result over multiple games. """
     if isinstance(x, Module):
         agent = ModuleDecidingPlayer(x, self.env, greedySelection=True)
     elif isinstance(x, GomokuPlayer):
         agent = x
     else:
         raise NotImplementedError('Missing implementation for ' +
                                   x.__class__.__name__ + ' evaluation')
     res = 0
     agent.game = self.env
     self.opponent.game = self.env
     for dummy in range(self.averageOverGames):
         agent.color = -self.opponent.color
         res += EpisodicTask.__call__(self, agent)
     return res / float(self.averageOverGames)
Esempio n. 7
0
 def performAction(self, action):
     EpisodicTask.performAction(self, action)
     if not self.isFinished():
         EpisodicTask.performAction(self, self.opponent.getAction())            
Esempio n. 8
0
 def reset(self):
     self.switched = False
     EpisodicTask.reset(self)   
     if self.opponent.color == GomokuGame.BLACK:     
         # first move by opponent
         EpisodicTask.performAction(self, self.opponent.getAction())
Esempio n. 9
0
 def performAction(self, action):
     EpisodicTask.performAction(self, action)
     if not self.isFinished():
         EpisodicTask.performAction(self, self.opponent.getAction())
Esempio n. 10
0
 def reset(self):
     self.switched = False
     EpisodicTask.reset(self)
     if self.opponent.color == CaptureGame.BLACK:
         # first move by opponent
         EpisodicTask.performAction(self, self.opponent.getAction())