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


Python Board.set方法代码示例

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


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

示例1: testUse

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import set [as 别名]
 def testUse(self):
     val = "x"
     b = Board(2, 2)
     b.set(1, 1, val)
     self.assertEqual(b.get(1, 1), val)
开发者ID:marco-arthur,项目名称:sandbox,代码行数:7,代码来源:board_tests.py

示例2: Game

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import set [as 别名]
class Game(object):
    def __init__(self, display=None):
        self.players = []
        self.rules = Rules()
        self.board = Board()
        self.display = display
        self.current_player = None
        self.other_player = None

    def new_rules(self, rules):
        self.rules = rules

    def run(self):
        if self._has_enough_players():
            self._prepare_players()
            self._play_game()
            self._display_board_content()

            return self._game_state()
        else:
            raise TooFewPlayers()

    def add_player(self, player):
        self.players.append(player)

    def _prepare_players(self):
        self.current_player = self.players[0]
        self.other_player = self.players[1]

    def _play_game(self):
        while self._is_not_finished():
            self._display_board_content()
            self._place_move_of_current_player()
            self._switch_players()

    def _has_enough_players(self):
        return self.rules.enough_players(self.players)

    def _is_not_finished(self):
        return not self.rules.finished(self.board)

    def _place_move_of_current_player(self):
        while True:
            try:
                move = self.current_player.next_move(self.board)
                self.board.set(move, self.current_player.symbol)
                break
            except UnallowedMove:
                self._display_illegal_move_warning()

    def _switch_players(self):
        self.current_player, self.other_player = self.other_player, self.current_player

    def _game_state(self):
        return self.rules.game_state(self.board)

    def _display_board_content(self):
        if self.display:
            self.display.show_board_state(self.board)

    def _display_illegal_move_warning(self):
        if self.display:
            self.display.show_illegal_move_warning()
开发者ID:christophgockel,项目名称:tictactoe,代码行数:65,代码来源:game.py

示例3: ScrabbleVision

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import set [as 别名]

#.........这里部分代码省略.........
          #Draw appropriate gridlines on the board
          x = configs.LSTEP
          for i in range(0,14):
            x += float(configs.SIZE-configs.LSTEP-configs.RSTEP) / 15
            cv2.line(norm_draw, (int(x),configs.TSTEP), (int(x),configs.SIZE-configs.BSTEP), line_color)

          y = configs.TSTEP
          for i in range(0,14):
            y += float(configs.SIZE-configs.TSTEP-configs.BSTEP) / 15
            cv2.line(norm_draw, (configs.LSTEP,int(y)), (configs.SIZE-configs.RSTEP,int(y)), line_color)

          #POST("remapped", norm_draw)

          #end norm draw

          experimental_thresh_board(norm)
           
          if configs.TRAIN:
            img = get_sub_image(norm, configs.COORD_X, configs.COORD_Y)
            classify_letter(img, configs.COORD_X, configs.COORD_Y, draw=True)
          else:

            blank_b = Board()

            letter_draw = norm_draw.copy()
            y = configs.TSTEP
            #Draw crazy grid thing
            for j in range(0,15):
              x = configs.LSTEP
              for i in range(0,15):
                img = get_sub_image(norm, i,j)
                r = classify_letter(img, i, j, draw=(configs.DEBUG and i == configs.COORD_X and j == configs.COORD_Y), blank_board=blank_b)
                in_blank = (blank_b.get(i,j) is not None)
                if not in_blank:
                  new_info(i,j,r)
                if r is not None:
                  cv2.putText(letter_draw, str(r.upper()), (int(x)+7,int(y)+22), cv2.FONT_HERSHEY_COMPLEX, 0.7, (255,255,255))
                x += float(configs.SIZE-configs.LSTEP-configs.RSTEP) / 15
              y += float(configs.SIZE-configs.TSTEP-configs.BSTEP) / 15


            #Analyze blank board to determine which are blanks and which are empty spaces
            #TODO: analyze blank_b
            for i in range(0,15):
              for j in range(0,15):
                r = blank_b.get(i,j)
                if r is not None:
                  nearest = np.array(blank_b.get_nearest_not_none(i,j, configs.BLANK_NEIGHBORS))
                  mean = np.mean(nearest)
                  std = np.std(nearest)
                  z = abs(r - mean) / std

                  if configs.DEBUG and i == configs.COORD_X and j == configs.COORD_Y:
                    print "Color is %d; mean of nearest %d neighbors is %.2f, std is %.2f, z is %.2f" % (r, configs.BLANK_NEIGHBORS, mean, std, z) 
                  if z > configs.BLANK_Z_THRESH:
                    #This is a blank!
                    new_info(i,j,'-')
                  else:
                    new_info(i,j,None) #not a blank
                  
            if configs.DEBUG:
              POST("letter draw", letter_draw)
             
            #Conduct averaging of the given letters
            avg_draw = norm_draw.copy()

            with self.l:
              y = configs.TSTEP
              #Draw crazy grid thing
              for j in range(0,15):
                x = configs.LSTEP
                for i in range(0,15):
                  r = lookup_char(i,j) 
                  self.board.set(i,j,r)
                  if r is not None:
                    cv2.putText(avg_draw, str(r.upper()), (int(x)+7,int(y)+22), cv2.FONT_HERSHEY_COMPLEX, 0.7, (255,255,255))
                  x += float(configs.SIZE-configs.LSTEP-configs.RSTEP) / 15
                y += float(configs.SIZE-configs.TSTEP-configs.BSTEP) / 15

            POST("Letter Detection (Filtered)", avg_draw)

        except IterSkip as e:
          pass
        except Exception as e:
          print "Exception occured: %s" % str(e)
          print "--------"
          print traceback.format_exc()
          print "--------"

        #END PROCESSING

        #next itr
        self.started = True

        # TODO: bleh.....
        key = cv2.waitKey(333)

        #rval, frame_raw = vc.read()

      print "Terminating..."
开发者ID:jheidel,项目名称:scrabble-opencv,代码行数:104,代码来源:vision.py

示例4: ScrabbleVision

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import set [as 别名]
class ScrabbleVision(Thread):
    def __init__(self):
        Thread.__init__(self)
        self.board = Board()
        self.l = Lock()
        self.started = False
        self.killed = False

    def get_current_board(self):
        with self.l:
            return self.board.copy()

    def kill(self):
        self.killed = True

    def run(self):

            vc = cv2.VideoCapture(-1)

            if vc.isOpened(): # try to get the first frame
                rval, frame_raw = vc.read()
            else:
                rval = False

            while rval:

                if self.killed:
                    print "Vision terminating"
                    return

                reload(configs)
                element = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (configs.ERODE_RAD,configs.ERODE_RAD))
                element2 = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (configs.DILATE_RAD,configs.DILATE_RAD))

                #BEGIN PROCESSING
                try:

                    
                    frame = cv2.flip(frame_raw, flipCode=-1)
                    POST("RAW", frame)

                    luv = cv2.split(cv2.cvtColor(frame, cv2.COLOR_RGB2LUV))

                    v_chan = luv[2]

                    #POST("V", v_chan)

                    blur = cv2.GaussianBlur(v_chan, (configs.BLUR_RAD,configs.BLUR_RAD), 0)

                    #POST("blur", blur)
                    thresh = cv2.adaptiveThreshold(blur, 255, 0, 1, configs.BOARD_THRESH_PARAM, configs.BOARD_BLOCK_SIZE)

                    #POST("thresh", thresh)

                    erode = cv2.erode(thresh, element)
                    erode = cv2.dilate(erode, element2)
                    
                    POST("erode", erode)

                    erode_draw = frame.copy()
                    
                    contours,hierarchy = cv2.findContours(erode, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

                    possible_corners = []

                    #Find large contour closest to center of image
                    for cnt in contours:
                        sz = cv2.contourArea(cnt)
                        if sz>75 and sz < 650:
                            ellipse = cv2.fitEllipse(cnt)
                            ((x,y), (w,h), r) = ellipse
                            ar = w / h if w > h else h / w
                            if ar > 1.8:
                                continue
                            pf = (w * h * 0.75) / sz
                            if pf > 1.5:
                                continue
                            cv2.ellipse(erode_draw,ellipse,(0,255,0),2)
                            possible_corners.append((x,y))


                    """


                    lines = cv2.HoughLinesP(erode, 1, 3.14/180, 300, minLineLength=200, maxLineGap=100)[0]
                    m,n = erode.shape

                    goodlines = lines[:40]

                    #Calculate intersection points
                    points = set()
                    CLUSTER_RAD = 50
                    clusters = []
                    for x in goodlines:
                        for y in goodlines:
                            i = intersect(x,y)
                            if i is not None:
                                added = False
                                for (ctr, st) in clusters:
                                    if distance(i, ctr) < CLUSTER_RAD:
#.........这里部分代码省略.........
开发者ID:ukasiu,项目名称:scrabble-opencv,代码行数:103,代码来源:vision.py

示例5: do_manual

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import set [as 别名]
def do_manual(rows=None,levelnum=None, onestep=False):
    levelst=time.time()
    levelnum=str(levelnum)
    #~ import simpleroom
    #~ simpleroom.g_allsols_cache={}
    #~ simpleroom.g_hassols_cache={}
    #~ simpleroom.kill_caches()
    #
    #this isn't actually necessary, but it's good cause you save ram.

    config.one_sol=0
    config.live=False
    config.levelnum=levelnum
    config.maxx,config.maxy=len(rows[0])-1,len(rows)-1

    if config.do_sol:
        sol=open('sols/%s.txt'%levelnum,'r').read()
        x=int(sol.split('((')[1].split(',')[0])
        y=int(sol.split(',')[1].split(')')[0])
        config.targetpos=x,y
        config.targetdv=int(sol.split(',')[2].split(')')[0])
        config.target=(config.targetpos, config.targetdv)
        config.monitored_start=(config.targetpos, config.targetdv)
    board=Board(config, rows=rows, levelnum=levelnum, onestep=onestep)
    board.allneighbors=get_allneighbors(config)
    board.boardst=levelst
    totst=len(board.starts)
    #~ print 'board starts is:',totst
    board.rows=[r[:] for r in board.orig_rows]
    has_solution=False
    origalleys=getorigalley(board)
    #~ if board.levelnum=='3489660927':
        #~ import ipdb;ipdb.set_trace()
    if len(origalleys)<=2:
        while board.starts:
            ii=len(board.starts)
            pos, dv=board.newstart()
            #~ print pos,dv
            #~ board.show()
            #~ if levelnum=='31336081391615' and pos==(4,1) and dv==2 and onestep:
                #~ import ipdb;ipdb.set_trace()
            #~ if levelnum=='3489660927' and pos==(4,1) and dv==2 and onestep:
                #~ import ipdb;ipdb.set_trace()
            #~ if levelnum=='3489660927':
                #~ import ipdb;ipdb.set_trace()
            if len(origalleys)==2 and pos not in origalleys:
                continue
            #~ print "%s: %03d-%03d %s %s / %s"%(levelnum,pos[0],pos[1],getd(dv),str(totst-ii),str(totst)),
            if not oob(config, pos) and not board.isopen(pos):
                import ipdb;ipdb.set_trace()
                board.show()
                sys.exit()
            board.set(pos)
            #~ if config.monitor_start and (pos,dv)==config.monitored_start:
                #~ import ipdb;ipdb.set_trace()
            #~ illegal_placement=do_placement(board,dv,pos)
            #~ if illegal_placement:
                #~ donestart(board,message='illegal placement')
                #~ board.unset(pos)
                #~ continue
            alley_backtrack=get_alleys(board,dv,pos)
            if alley_backtrack:
                #~ donestart(board,message='badalley')
                board.unset(pos)
                continue
            if board.isopen(add(pos,dv+1)) and not board.isopen(add(add(pos,dv+1),dv)):
                #for example  if you are moving upwards.  If right is open and upper right is open, add right.
                #only set up fake initial sometimes.
                board.sawr=[[add(pos,dv+1)]]
            else:
                board.sawr=[[]]
            if board.isopen(add(pos,dv-1)) and not board.isopen(add(add(pos,dv-1),dv)):
                board.sawl=[[add(pos,dv-1)]]
            else:
                board.sawl=[[]]
            if config.monitor_start and (pos,dv)==config.monitored_start:
                import ipdb;ipdb.set_trace()
            res=fork(board,pos,dv, onestep=onestep)
            #MAIN

            if res==0:
                board.solvetime=time.time()-board.boardst
                #~ donestart(board,res=res,message='DONE', onestep=onestep)
                has_solution=True
                res=dosolved(board)
                if config.one_sol or config.live:
                    doneboard(board)
                    board.unset(pos)
                    return res
            else:
                donestart(board,message='runout  ')

            board.unset(pos)
    doneboard(board)
    if has_solution:
        return True
开发者ID:ernop,项目名称:progpuz,代码行数:98,代码来源:split.py

示例6: __init__

# 需要导入模块: from board import Board [as 别名]
# 或者: from board.Board import set [as 别名]
class Game:
    cascade = True
    def __init__(self, width, height, mines):
        self.width = width
        self.height = height
        self.mines = mines
        self.board = Board(width, height)
        self.mine_array = MineArray(width, height, mines)

    def randomize_mines(self):
        self.mine_array.randomize()

    def start(self):
        self.board.clear()

    def new_game(self):
        self.randomize_mines()
        self.start()

    def neighbour_count(self, row, col):
        neighbours = self.mine_array.neighbours(row, col)
        return sum(self.mine_array.get(*coord) for coord in neighbours)

    def on_board(self, row, col):
        return (0 <= row < self.height) and (0 <= col < self.width)

    def click(self, row, col):
        if not self.on_board(row, col):
            raise RuntimeError("({}, {}) is not within the bounds of the board.".format(row, col))
        if self.mine_array.is_mine(row, col):
            for index, val in enumerate(self.mine_array.array):
                if val:
                    self.board.array[index] = Tile.MINE
            self.board.set(row, col, Tile.BLAST)
        else:
            if self.cascade:
                self.cascade_open(row, col)
            else:
                num = self.neighbour_count(row, col)
                self.board.set(row, col, Tile.num(num))

    def cascade_open(self, row, col):
        to_do = [(row, col)]
        board = self.board
        while to_do:
            row, col = to_do.pop()
            n_count = self.neighbour_count(row, col)
            board.set(row, col, Tile.num(n_count))
            if n_count == 0:
                for (i, j) in self.mine_array.neighbours(row, col):
                    if self.board.get(i, j).is_num():
                        continue
                    if (i, j) in to_do:
                        continue
                    to_do.append((i, j))

    def is_solved(self):
        for row in range(self.height):
            for col in range(self.width):
                mine = self.mine_array.get(row, col)
                if mine == 0:
                    if not self.board.get(row, col).is_num():
                        return False
        return True


    def __str__(self):
        return str(self.board)
开发者ID:a-r-a-d-e-s-h,项目名称:ms_solver,代码行数:70,代码来源:ms_game.py


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