Example #1
0
    def set_values(self, board):

        values = {(b, l): 0.0 for b in range(9) for l in range(9)}

        win_value = 2000.0
        lose_board_value = -15.0
        score_value = 18.0
        bad_score_value = -12.0
        free_play_value = -18.0
        cats_play_value = 20.0

        center_board_value = 0.5

        #priotize the center
        for i in range(9):
            values[(4, i)] += center_board_value

        # priortize the board that could cause us to win
        masked_macrob = [0 if i < 0 else i for i in board.macroboard]
        canwin = sb_logic.can_score(masked_macrob, self.myid)
        if canwin is not False:
            logging.info("CAN WIN BOARD {}".format(canwin))
            for l in range(9):
                values[canwin, l] += win_value
        # depriortize the board that could cause us to win
        canlose = sb_logic.can_score(masked_macrob, self.oppid)
        if canlose is not False:
            for b in range(9):
                values[b, canlose] += lose_board_value

        # priortize scoring
        csm = board.canscorematrix()
        for b in range(9):
            if csm[self.myid][b] is not False:
                values[b, csm[self.myid][b]] += score_value

        # depriortize him scoring
        for b in range(9):
            if csm[self.oppid][b] is not False:
                for b2 in range(9):
                    values[b2, b] += bad_score_value

        # prioritize letting him play on cats
        catsmatrix = board.catsmatrix()
        for b in range(9):
            if catsmatrix[b] is True:
                for b2 in range(9):
                    values[b2, b] += cats_play_value

        # don't give him free play
        for b in range(9):
            if board.macroboard[b] > 0:
                for b2 in range(9):
                    values[b2, b] += free_play_value

        legal_values = {
            k: v
            for k, v in values.iteritems() if k in board.legal_moves()
        }
        return legal_values
Example #2
0
    def set_values(self, board):

        values = {(b,l): 0.0 for b in range(9) for l in range(9)}

        win_value = 2000.0
        lose_board_value = -15.0
        score_value = 18.0
        bad_score_value = -12.0
        free_play_value = -18.0
        cats_play_value = 20.0

        center_board_value = 0.5

        #priotize the center
        for i in range(9):
            values[(4,i)] += center_board_value

        # priortize the board that could cause us to win
        masked_macrob = [0 if i < 0 else i for i in board.macroboard]
        canwin = sb_logic.can_score(masked_macrob, self.myid)
        if canwin is not False:
            logging.info("CAN WIN BOARD {}".format(canwin))
            for l in range(9):
                values[canwin,l] += win_value
        # depriortize the board that could cause us to win
        canlose = sb_logic.can_score(masked_macrob, self.oppid)
        if canlose is not False:
            for b in range(9):
                values[b,canlose] += lose_board_value



        # priortize scoring
        csm = board.canscorematrix()
        for b in range(9):
            if csm[self.myid][b] is not False:
                values[b,csm[self.myid][b]] += score_value

        # depriortize him scoring
        for b in range(9):
            if csm[self.oppid][b] is not False:
                for b2 in range(9):
                    values[b2,b] += bad_score_value


        # prioritize letting him play on cats
        catsmatrix = board.catsmatrix()
        for b in range(9):
            if catsmatrix[b] is True:
                for b2 in range(9):
                    values[b2,b] += cats_play_value

        # don't give him free play
        for b in range(9):
            if board.macroboard[b] > 0:
                for b2 in range(9):
                    values[b2,b] += free_play_value

        legal_values = {k:v for k,v in values.iteritems() if k in board.legal_moves()}
        return legal_values
Example #3
0
    def best_move(self, board, tleft):
        logging.info("get_move {} {}".format(board, tleft))

        logging.info("winmat {}".format(board.winmatrix()))
        csm = board.canscorematrix()
        logging.info("canscoremat {}".format(csm))

        for sbi in range(9):
            if board.macroboard[sbi] == -1 and csm[self.myid][sbi]:
                scoring_loc = csm[self.myid][sbi]
                logging.info("we can score on board {} loc {}".format(
                    sbi, scoring_loc))
                scoring_move = board.locs_to_move(sbi, scoring_loc)
                logging.info("we can score with move {}".format(scoring_move))
                logging.info("sb\n{}".format(pprint(board.get_subboard(sbi))))
                logging.info("canscore \n{}".format(
                    sb_logic.can_score(board.get_subboard(sbi), self.myid)))
                return scoring_move

        # logging.info("board {}".format(board.get_board()))
        lmoves = board.legal_moves()
        logging.info("lmoves {}".format(lmoves))
        if len(lmoves) < 1:
            logging.error("There is no legal moves")
            for y in range(9):
                for x in range(9):
                    if board.field[y * 9 + x] == 0:
                        return (x, y)

        rm = randint(0, len(lmoves) - 1)
        logging.info("rm {}".format(rm))
        return board.locs_to_move(*lmoves[rm])
Example #4
0
 def canscorematrix(self):
     m = {}
     for t in (1, 2):
         m[t] = [sb_logic.can_score(sb, t) for sb in self.get_all_subs()]
     return m
Example #5
0
 def canscorematrix(self):
     m = {}
     for t in (1, 2):
         m[t] = [sb_logic.can_score(sb, t) for sb in self.get_all_subs()]
     return m