Creates a game from the move stack of a :class:`~chess.Board()`.
173048
def from_board(cls: Type[GameT], board: chess.Board) -> GameT:
        """"""
        # Setup the initial position.
        game = cls()
        game.setup(board.root())
        node = game  # type: GameNode

        # Replay all moves.
        for move in board.move_stack:
            node = node.add_variation(move)

        game.headers["Result"] = board.result()
        return game
7780
def gnuchess_move
      pipe = IO.popen('gnuchess -x', 'r+')
      begin
        pipe.puts('depth 1')
        pipe.puts('manual')
        self.coord_moves.each do |m|
          pipe.puts(m)
        end
        pipe.puts('go')
        while line = pipe.gets
          raise IllegalMoveError if line.include?('Invalid move')
          match = line.match(/My move is : ([a-h][1-8][a-h][1-8][rkbq]?)/)
          return match[1] if match
        end
      ensure
        pipe.puts('quit')
        pipe.close
      end
      return moves
    end
1162041
def gameloop(self):
        
        try:
            while True:
                for event in pygame.event.get():
                    if event.type == pygame.QUIT:
                        sys.exit()
                    if event.type == pygame.KEYDOWN:
                        if event.key == pygame.K_ESCAPE:
                            pygame.event.post(pygame.event.Event(pygame.QUIT))

                self.recv_data()
                self.update()
                self.render()
        except KeyboardInterrupt:
            pass
612639
def run_game(load_file, selfplay_dir=None, holdout_dir=None,
             sgf_dir=None, holdout_pct=0.05):
    """"""
    if sgf_dir is not None:
        minimal_sgf_dir = os.path.join(sgf_dir, 'clean')
        full_sgf_dir = os.path.join(sgf_dir, 'full')
        utils.ensure_dir_exists(minimal_sgf_dir)
        utils.ensure_dir_exists(full_sgf_dir)
    if selfplay_dir is not None:
        utils.ensure_dir_exists(selfplay_dir)
        utils.ensure_dir_exists(holdout_dir)

    with utils.logged_timer("Loading weights from %s ... " % load_file):
        network = dual_net.DualNetwork(load_file)

    with utils.logged_timer("Playing game"):
        player = play(network)

    output_name = '{}-{}'.format(int(time.time()), socket.gethostname())
    game_data = player.extract_data()
    if sgf_dir is not None:
        with gfile.GFile(os.path.join(minimal_sgf_dir, '{}.sgf'.format(output_name)), 'w') as f:
            f.write(player.to_sgf(use_comments=False))
        with gfile.GFile(os.path.join(full_sgf_dir, '{}.sgf'.format(output_name)), 'w') as f:
            f.write(player.to_sgf())

    tf_examples = preprocessing.make_dataset_from_selfplay(game_data)

    if selfplay_dir is not None:
        # Hold out 5% of games for validation.
        if random.random() < holdout_pct:
            fname = os.path.join(holdout_dir,
                                 "{}.tfrecord.zz".format(output_name))
        else:
            fname = os.path.join(selfplay_dir,
                                 "{}.tfrecord.zz".format(output_name))

        preprocessing.write_tf_examples(fname, tf_examples)
1038018
def copy(self: BaseBoardT) -> BaseBoardT:
        """"""
        board = type(self)(None)

        board.pawns = self.pawns
        board.knights = self.knights
        board.bishops = self.bishops
        board.rooks = self.rooks
        board.queens = self.queens
        board.kings = self.kings

        board.occupied_co[WHITE] = self.occupied_co[WHITE]
        board.occupied_co[BLACK] = self.occupied_co[BLACK]
        board.occupied = self.occupied
        board.promoted = self.promoted

        return board
167610
function(){
		var opemgr = this.puzzle.opemgr;
		opemgr.newOperation();
		opemgr.add(new this.puzzle.klass.BoardClearOperation());
		
		this.cell.ansclear();
		this.cross.ansclear();
		this.border.ansclear();
		this.excell.ansclear();
		opemgr.rejectTrial(true);
		if(opemgr.history[opemgr.history.length-1].length===1){
			opemgr.puzzle.undo();
			opemgr.removeDescendant();
		}
		
		this.rebuildInfo();
	}
1022817
def board_fen(self, *, promoted: Optional[bool] = False) -> str:
        
        builder = []
        empty = 0

        for square in SQUARES_180:
            piece = self.piece_at(square)

            if not piece:
                empty += 1
            else:
                if empty:
                    builder.append(str(empty))
                    empty = 0
                builder.append(piece.symbol())
                if promoted and BB_SQUARES[square] & self.promoted:
                    builder.append("~")

            if BB_SQUARES[square] & BB_FILE_H:
                if empty:
                    builder.append(str(empty))
                    empty = 0

                if square != H1:
                    builder.append("/")

        return "".join(builder)
78913
def make_pawn(self, thing):
        
        if thing["name"] in self.pawn:
            raise KeyError("Already have a Pawn for this Thing")
        r = self.pawn_cls(
            board=self,
            thing=thing
        )
        self.pawn[thing["name"]] = r
        return r
142201
def solve(self):
        
        # Create a new, empty board.
        board = Board(self.length, self.height)

        # Iterate through all combinations of positions.
        permutations = Permutations(self.pieces, self.vector_size)
        for positions in permutations:

            # Reuse board but flush all pieces.
            board.reset()

            for level, (piece_uid, linear_position) in enumerate(positions):
                # Try to place the piece on the board.
                try:
                    board.add(piece_uid, linear_position)
                # If one of the piece can't be added, throw the whole set, skip
                # the rotten branch and proceed to the next.
                except (OccupiedPosition, VulnerablePosition, AttackablePiece):
                    permutations.skip_branch(level)
                    break

            else:
                # All pieces fits, save solution and proceeed to the next
                # permutation.
                self.result_counter += 1
                yield board
1257474
function getGameAfterMove(game, move, backMove = false) {
    if (!backMove && canNotMove(game, move))
        return game;
    const board = getBoardAfterMove(game.board, move);
    return {
        players: game.players,
        board,
        score: Score.getScore(game.board),
        moves: backMove ? game.moves : game.moves.concat(getMoveXAndY(move))
    };
}
283005
def board(self, *, _cache: bool = True) -> chess.Board:
        
        if self.board_cached is not None:
            board = self.board_cached()
            if board is not None:
                return board.copy()

        board = self.parent.board(_cache=False)
        board.push(self.move)

        if _cache:
            self.board_cached = weakref.ref(board)
            return board.copy()
        else:
            return board
792435
def board(self):
        """"""
        board = []
        if self.flop:
            board.extend(self.flop.cards)
            if self.turn:
                board.append(self.turn)
                if self.river:
                    board.append(self.river)
        return tuple(board) if board else None
1297749
def from_board(cls, board):
        '''
        
        '''
        if len(board):
            left = board.left_end()
            right = board.right_end()
        else:
            left = None
            right = None

        return cls(left, right, len(board))
349830
def chess960_pos(self) -> Optional[int]:
        
        if self.occupied_co[WHITE] != BB_RANK_1 | BB_RANK_2:
            return None
        if self.occupied_co[BLACK] != BB_RANK_7 | BB_RANK_8:
            return None
        if self.pawns != BB_RANK_2 | BB_RANK_7:
            return None
        if self.promoted:
            return None

        # Piece counts.
        brnqk = [self.bishops, self.rooks, self.knights, self.queens, self.kings]
        if [popcount(pieces) for pieces in brnqk] != [4, 4, 4, 2, 2]:
            return None

        # Symmetry.
        if any((BB_RANK_1 & pieces) << 56 != BB_RANK_8 & pieces for pieces in brnqk):
            return None

        # Algorithm from ChessX, src/database/bitboard.cpp, r2254.
        x = self.bishops & (2 + 8 + 32 + 128)
        if not x:
            return None
        bs1 = (lsb(x) - 1) // 2
        cc_pos = bs1
        x = self.bishops & (1 + 4 + 16 + 64)
        if not x:
            return None
        bs2 = lsb(x) * 2
        cc_pos += bs2

        q = 0
        qf = False
        n0 = 0
        n1 = 0
        n0f = False
        n1f = False
        rf = 0
        n0s = [0, 4, 7, 9]
        for square in range(A1, H1 + 1):
            bb = BB_SQUARES[square]
            if bb & self.queens:
                qf = True
            elif bb & self.rooks or bb & self.kings:
                if bb & self.kings:
                    if rf != 1:
                        return None
                else:
                    rf += 1

                if not qf:
                    q += 1

                if not n0f:
                    n0 += 1
                elif not n1f:
                    n1 += 1
            elif bb & self.knights:
                if not qf:
                    q += 1

                if not n0f:
                    n0f = True
                elif not n1f:
                    n1f = True

        if n0 < 4 and n1f and qf:
            cc_pos += q * 16
            krn = n0s[n0] + n1
            cc_pos += krn * 96
            return cc_pos
        else:
            return None
927847
def pgn
      pgn = Chess::Pgn.new
      pgn.moves = self.moves
      pgn.result = self.result
      return pgn
    end
771592
def learn(self, initial_state_key, limit=1000, game_n=1):
        '''
        
            
        '''
        end_flag = False
        state_key_list = [None] * len(self.q_learning_list)
        action_key_list = [None] * len(self.q_learning_list)
        next_action_key_list = [None] * len(self.q_learning_list)
        for game in range(game_n):
            state_key = initial_state_key
            self.t = 1
            while self.t <= limit:
                for i in range(len(self.q_learning_list)):
                    state_key_list[i] = state_key
                    if game + 1 == game_n:
                        self.state_key_list.append(tuple(i, state_key_list))
                    self.q_learning_list[i].t = self.t
                    next_action_list = self.q_learning_list[i].extract_possible_actions(tuple(i, state_key_list))
                    if len(next_action_list):
                        action_key = self.q_learning_list[i].select_action(
                            state_key=tuple(i, state_key_list),
                            next_action_list=next_action_list
                        )
                        action_key_list[i] = action_key
                        reward_value = self.q_learning_list[i].observe_reward_value(
                            tuple(i, state_key_list), 
                            tuple(i, action_key_list)
                        )

                        # Check.
                        if self.q_learning_list[i].check_the_end_flag(tuple(i, state_key_list)) is True:
                            end_flag = True

                        # Max-Q-Value in next action time.
                        next_next_action_list = self.q_learning_list[i].extract_possible_actions(
                            tuple(i, action_key_list)
                        )
                        if len(next_next_action_list):
                            next_action_key = self.q_learning_list[i].predict_next_action(
                                tuple(i, action_key_list), 
                                next_next_action_list
                            )
                            next_action_key_list[i] = next_action_key
                            next_max_q = self.q_learning_list[i].extract_q_df(
                                tuple(i, action_key_list), 
                                next_action_key
                            )

                            # Update Q-Value.
                            self.q_learning_list[i].update_q(
                                state_key=tuple(i, state_key_list),
                                action_key=tuple(i, action_key_list),
                                reward_value=reward_value,
                                next_max_q=next_max_q
                            )

                            # Update State.
                            state_key = self.q_learning_list[i].update_state(
                                state_key=tuple(i, state_key_list),
                                action_key=tuple(i, action_key_list)
                            )
                            state_key_list[i] = state_key

                    # Epsode.
                    self.t += 1
                    self.q_learning_list[i].t = self.t
                    if end_flag is True:
                        break
186090
def simple_generate(cls, create, **kwargs):
        
        strategy = enums.CREATE_STRATEGY if create else enums.BUILD_STRATEGY
        return cls.generate(strategy, **kwargs)