Created
April 12, 2010 08:05
-
-
Save enriqueaf/363376 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_turn(self): | |
print self.Name,'Tu turno' | |
while True: | |
a = self._comer_si_puede() | |
self.log.wrt(str(a)) | |
if a: | |
return a | |
return self._aleatorio() | |
def _comer_si_puede(self): | |
pieces = self._game.get_piece(type='CABALLO') | |
self.log.wrt(pieces) | |
for i in pieces: | |
position = self._game.get_position(i) | |
moves = self._game.possible_moves_of(position) | |
for a in moves: | |
if self._game.can_eat(position,a): | |
return [position,a] | |
return False | |
def _aleatorio(self): | |
pieces = self._game.get_piece(type='CABALLO') | |
rand = random.randrange(len(pieces)) | |
position = self._game.get_position(pieces[rand]) | |
positions = self._game.possible_moves_of(position) | |
rand2 = random.randrange(len(positions)) | |
self.log.wrt(str(rand2)+' '+str(positions)) | |
pF = positions[rand2] | |
print position,'->',pF | |
return [position,pF] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment