当前位置: 首页>>代码示例>>Python>>正文


Python AI.clean_records方法代码示例

本文整理汇总了Python中ai.AI.clean_records方法的典型用法代码示例。如果您正苦于以下问题:Python AI.clean_records方法的具体用法?Python AI.clean_records怎么用?Python AI.clean_records使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ai.AI的用法示例。


在下文中一共展示了AI.clean_records方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: game

# 需要导入模块: from ai import AI [as 别名]
# 或者: from ai.AI import clean_records [as 别名]

#.........这里部分代码省略.........
                    elif mv == 'hist':
                        print '\n'.join([ str(i+1)+'. '+self.white['hist'][i]+' '+self.black['hist'][i] for i in range(len(self.black['hist']))]), \
                              ('\n'+str(len(self.white['hist']))+'. '+self.white['hist'][-1])*(len(self.black['hist'])<len(self.white['hist']))
                        validated_move = ''
                    elif mv == 'export':
                        print self.zboard.board
                        validated_move = ''
                    elif mv == 'undo':
                        self.turnundo(verbose)
                        validated_move = ''
                    elif mv.count('eval')>0:
                        print 'mv',mv,'mv command', mv[5:-1]
                        eval(mv[5:-1])
                        validated_move = ''
                    elif mv == 'verbose':
                        if verbose == 0:
                            verbose=1
                        else:
                            verbose=0
                        validated_move = ''
                    else:
                        verified_moves = self.verified(mv[0]) #mv[0] is the piece
                        if (mv[2],mv[3]) in [(z[0],z[1]) for z in verified_moves]: # move type, destination sq, notation 
                            validated_move = mv
                            #previous_move = mv
                        else:
                            if verbose>0:
                                print('notation was correct, but move is invalid')
                                print('move',mv)
                                print('allowed moves',verified_moves)
                            self.logit('notation was correct, but move is invalid -- move',mv,'allowed moves',verified_moves)
            else:
                start_stamp = time.clock()
                if verbose>0:
                    print 'AI ('+self.turn['col']+') starts at time:',time.strftime("%Y/%m/%d %H:%M:%S", time.localtime())
                
                vm = self.ai.AI_move(old_board_state,validated_move,self.turn['col'],self.white['hist'],self.black['hist'],aidepth,verbose) #turn_color,verbose ### used to be depth,verbose
                run_time = time.clock() - start_stamp
                validated_move = (self.zboard.piece_by_sq(vm['origin']),vm['origin'],vm['move'][0],vm['move'][1],vm['move'][2])
                if verbose >0:
                    print('AI:',vm,' completed in:',run_time)
                self.logit('AI:',vm)
                
            if not eksit and len(validated_move)>0:
                #turn_time = now - stamp
                # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                old_board_state = self.zboard.board.copy() # used to create ai_board
                
                #execute move
                if verbose >0:
                    print validated_move
                self.undo_stack.append(self.zboard.exec_move(validated_move[0],(validated_move[2],validated_move[3],validated_move[4])))
                if verbose>1:
                    print 'self.zboard.winch & binch:',self.zboard.winch,self.zboard.binch
                    print 'self.turn["col"] ',self.turn['col'] 

                #memory reuse
                if validated_move[2] == 't':
                    self.ai.clean_records(64 - self.zboard.board.values().count('  '))

                #switch turn & and check if the new player is in check
                if self.turn['col'] == 'w':
                    self.turn_count +=1
                    self.turn = self.black
                    self.turn['is_in_check'] = self.zboard.sq_in_check(self.zboard.bk,'w',verbose=0)
                    self.white['hist'].append(validated_move[4]+'+'*self.turn['is_in_check'])
                else:
                    self.turn = self.white
                    self.turn['is_in_check'] = self.zboard.sq_in_check(self.zboard.wk,'b',verbose=0)
                    self.black['hist'].append(validated_move[4]+'+'*self.turn['is_in_check'])
               
                #check if mate or stalemate
                mate = self.mate(verbose=0)
                if verbose>1:
                    print 'self.zboard.winch & binch:',self.zboard.winch,self.zboard.binch
                    print self.white['hist']+'\n'+self.black['hist']
                    print 'self.turn["is_in_check"] ',self.turn['is_in_check'] 
                    print 'mate detected as',mate
        
        # --------- end of while not eksit and mate=='':
        if verbose>0:
            print self.show()
            self.full_notation = '\n'.join([ str(i+1)+'. '+self.white['hist'][i]+' '+self.black['hist'][i] for i in range(len(self.black['hist']))])+ \
                                 ('\n'+str(len(self.white['hist']))+'. '+self.white['hist'][-1])*(len(self.black['hist'])<len(self.white['hist']))

        result = 'exit'
        if mate == 'stalemate':
            self.full_notation += '\n1/2-1/2'
            result = '1/2-1/2'
        if mate == 'mate':
            if self.turn['col']=='w':
                result = '0-1'
            else:
                result = '1-0'
            self.full_notation = self.full_notation[:-1]+'#\n'+result

        if verbose>0:
            print self.full_notation
        
        return result
开发者ID:bobev18,项目名称:my-py-chess,代码行数:104,代码来源:chesslib.py


注:本文中的ai.AI.clean_records方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。