def dumb_value_function(node): board = node['board'] move = node['move'] value = -node['to_move'] * inf if check_victory(board, move - 1) else 0 player_logger.debug('evaluated move %s on board %s: value %s', move, board, value) return value
def process_turn_input(self, inp): a = self.available_moves = [] for r, row in zip('ABC', inp): for c, cell in zip('123', row.split()): if cell == EMPTY: a.append(r + c) player_logger.debug('available_moves: %s', self.available_moves)
def compute_available_moves(self): ''' each pawn to last row movement accounts for 4 different promotions if I really cared about the random player, probably I'd rescale the probabilities ''' am = list(get_available_moves_from_game(self.game, self.id)) player_logger.debug('available moves: %s', am) return am
def process_turn_input(self, inp): b = self.board = {} a = self.available_moves = [] for r, row in zip('ABC', inp): for c, cell in zip('123', row.split()): k = r + c b[k] = cell if cell == EMPTY: a.append(k) player_logger.debug('board state: %s; available moves: %s;', b, a)
def _compute_move(self): while True: move = IOPlayer.compute_move(self) # using super here would create a loop if self.algebraic: try: move = self.parse_algebraic(move) except (ValueError, IndexError, StopIteration): print('invalid move!') continue player_logger.debug(move) if move in get_available_moves_from_game(self.game, self.id): break print('invalid move!') return move
def to_algebraic(self, mov): ''' converts a valid move in coordinates notation to algebraic notation ''' g = self.game b = g.board starting = XCOORD.index(mov[0]), YCOORD.index(mov[1]) target = XCOORD.index(mov[2]), YCOORD.index(mov[3]) spiece = b[starting][1] if spiece == 'K': # check for castle d = abs(starting[0] - target[0]) if d == 2: return '0-0' elif d == 3: return '0-0-0' otherpieces = () else: otherpieces = [t for t in g.player_pieces[self.id] if t != starting and b[t] == spiece] # in case of promotion, can be more than 1 tpart = mov[2:] # pawn promotion is managed as well this way if b[target] != EMPTY: tpart = 'x' + tpart elif b[starting] == 'P' and starting[0] != target[0]: tpart = 'x' + tpart + 'e.p.' if spiece == 'P': spart = mov[0] if 'x' in tpart else '' else: spart = spiece player_logger.debug('checking available moves for using proper algebraic notation') if any(target in available_piece_moves(b, op) for op in otherpieces): # disambiguation needed if all(op[0] != starting[0] for op in otherpieces): spart = spart + mov[0] elif all(op[1] != starting[1] for op in otherpieces): spart = spart + mov[1] else: spart += mov[:2] kingpos = g.kings[self.id] player_logger.debug('checking if it is a king check to signal it') check = g.check_menace(kingpos, (self.id % 2) + 1, free_cell=starting, block_cell=target) if check: player_logger.debug('king in %s menaced by %s after move %s%s', kingpos, check, spart, tpart) tpart += '+' return spart + tpart
def compute_move(self): move = self._compute_move() player_logger.debug('updating internal state for player move %s', move) self.game.execute_turn(self.id, move) return move
def process_turn_input(self, inp): inp = inp[0] if inp != NULLMOVE: player_logger.debug('updating internal state for opponent move %s', inp) self.game.execute_turn((self.id % 2) + 1, inp)
def process_turn_input(self, inp): a = self.available_moves = [] for i, col in enumerate(inp): if col[-1] == '0': a.append(str(i + 1)) player_logger.debug('available_moves: %s', self.available_moves)
def compute_move(self): outp = self.nn(self.network_input) player_logger.debug('nn output: %s', outp) move = max((el, i) for i, el in enumerate(outp) if self.network_input[i] == 0)[1] return 'ABC'[move // 3] + '123'[move % 3]