Ejemplo n.º 1
0
    def get_next_move(self):
        """ Use an reverse indices vector to optimize for free turns. """

        reverse_indices = list(range(0, 6))
        reverse_indices.reverse()

        # First optimize for free moves.
        for i in reverse_indices:
            if self.eligible_free_turns[i] == 1:
                if self.pits[i] == reverse_index(i) + 1:
                    if self.print_game_status:
                        print ("VectorAI, mode 1, playing: " + str(i+1))
                    return i
        # Then clear out inefficient pits.
        for i in reverse_indices:
            if self.pits[i] > reverse_index(i) + 1:
                if self.print_game_status:
                    print ("VectorAI, mode 2, playing: " + str(i+1))
                return i
        # Finally, select a random eligible move.
        move = choice(self.eligible_moves)
        if self.print_game_status:
            moveprint = move +1
            print ("VectorAI, mode 3, " + str(moveprint))
        return move
Ejemplo n.º 2
0
    def _get_opposing_area_and_index(self, orig_area, index):
        """ Returns opposing_area, opposing_index

        Optionally returns as tuple for assertion testing.
         """

        try:
            from .mancala import reverse_index
        except Exception:  #ImportError
            from mancala import reverse_index
        #from .mancala import reverse_index

        if orig_area == P1_PITS:
            opposing_area = P2_PITS
        elif orig_area == P2_PITS:
            opposing_area = P1_PITS
        elif orig_area == P1_STORE:
            opposing_area = P2_STORE
        elif orig_area == P2_STORE:
            opposing_area = P1_STORE
        else:
            raise InvalidBoardArea

        opposing_index = reverse_index(index)

        return opposing_area, opposing_index
Ejemplo n.º 3
0
    def get_next_move(self):
        """ Use an reverse indices vector to optimize for free turns. """

        self._think()

        reverse_indices = range(0, 6)
        reverse_indices.reverse()

        # First optimize for free moves.
        for i in reverse_indices:
            if self.eligible_free_turns[i] == 1:
                if self.pits[i] == reverse_index(i) + 1:
                    print "VectorAI, mode 1, playing: " + str(i)
                    return i
        # Then clear out inefficient pits.
        for i in reverse_indices:
            if self.pits[i] > reverse_index(i) + 1:
                print "VectorAI, mode 2, playing: " + str(i)
                return i
        # Finally, select a random eligible move.
        print "VectorAI, mode 3, playing an eligible move."
        return choice(self.eligible_moves)
Ejemplo n.º 4
0
    def _get_opposing_area_and_index(self, orig_area, index):
        """ Returns opposing_area, opposing_index

        Optionally returns as tuple for assertion testing.
         """

        from mancala import reverse_index

        if orig_area == P1_PITS:
            opposing_area = P2_PITS
        elif orig_area == P2_PITS:
            opposing_area = P1_PITS
        elif orig_area == P1_STORE:
            opposing_area = P2_STORE
        elif orig_area == P2_STORE:
            opposing_area = P1_STORE
        else:
            raise InvalidBoardArea

        opposing_index = reverse_index(index)

        return opposing_area, opposing_index