Пример #1
0
 def opposite_direction(direction):
     for opposite_direction, opposite_direction_vector in ab.DIRECTION_VECTORS.items(
     ):
         direction_vector = Board().position_adjacent_to(
             ab.Position(0, 0), direction)
         if direction_vector + opposite_direction_vector == ab.Position(
                 0, 0):
             return opposite_direction
Пример #2
0
 def parse_from_move_string(self, move_string):
     tail_position = ab.Position(MoveParser._ROWS.index(move_string[0]),int(move_string[1]))
     if move_string[2] == '-':
         head_position = ab.Position(MoveParser._ROWS.index(move_string[3]),int(move_string[4]))
         desitination_position = ab.Position(MoveParser._ROWS.index(move_string[6]),int(move_string[7]))
         move_direction = self.board.direction(tail_position, head_position)
         return ab.Move(tail_position, head_position, move_direction)
     elif move_string[2] == ',':
         desitination_position = ab.Position(MoveParser._ROWS.index(move_string[3]),int(move_string[4]))
         move_direction = self.board.direction(tail_position, desitination_position)
         field = self.board.field(tail_position)
         if field and not field.is_empty:
             color = field.piece.color
             while field and not field.is_empty and field.piece.color == color:
                 previous_field = field
                 field = field.adjacent_field(move_direction)
             return ab.Move(tail_position, previous_field.position, move_direction)
     return None
Пример #3
0
        def init_board(self, outer_self):
            self.fields = {}

            for x in range(Board._SIZE):
                for y in range(Board._SIZE):
                    position = ab.Position(x, y)
                    if (x == 0 or x == 10 or y == 0 or y == 10 or x + y <= 5
                            or x + y >= 15):
                        type_ = ab.FieldType.GUTTER
                    else:
                        type_ = ab.FieldType.BOARD
                    field = ab.Field(
                        outer_self, type_, position
                    )  #pass Board-instance: outer_self to each Field-object
                    self.fields[position] = field
Пример #4
0
def main():
    game = Game(ab.Color.BLACK)
    # for _ in range(500):
    #     for color in ab.Color.__members__.values():
    #         moves = game.get_moves(color)
    #         move = random.choice(moves)
    #         game.do_move(move)
    #         print(game.board)
    #         print(move)
    #         print(game.score)

    moves = game.get_moves(ab.Color.BLACK)
    print("number of possible moves: {}".format(len(moves)))

    print(game.board)
    print("------------")
    move = ab.Move(ab.Position(1, 5), ab.Position(3, 5),
                   ab.Direction.RIGHT_DOWN)
    game.do_move(move)

    print(game.board)
    print("------------")
    move = ab.Move(ab.Position(8, 5), ab.Position(7, 5), ab.Direction.RIGHT_UP)
    game.do_move(move)

    print(game.board)
    print("------------")
    move = ab.Move(ab.Position(2, 5), ab.Position(4, 5),
                   ab.Direction.RIGHT_DOWN)
    game.do_move(move)

    print(game.board)
    print("------------")
    move = ab.Move(ab.Position(3, 5), ab.Position(5, 5),
                   ab.Direction.RIGHT_DOWN)
    game.do_move(move)

    print(game.board)
    print("------------")
    move = ab.Move(ab.Position(4, 5), ab.Position(6, 5),
                   ab.Direction.RIGHT_DOWN)
    game.do_move(move)

    print(game.board)
    print(move)
    print(game.score)
    print("------------")

    move = ab.Move(ab.Position(5, 5), ab.Position(7, 5),
                   ab.Direction.RIGHT_DOWN)
    game.do_move(move)
    print(game.board)
    print(move)
    print(game.score)
    print("------------")

    print(abman.MoveParser().parse_from_move_string("d5,c5"))

    move = ab.Move(ab.Position(6, 5), ab.Position(8, 5),
                   ab.Direction.RIGHT_DOWN)

    print(abman.MoveParser().parse_to_move_string(move))

    game.do_move(move)
    print(game.board)
    print(move)

    print(game.score)
    print("------------")

    moves = game.get_moves(ab.Color.WHITE)
    [print(move) for move in moves]
    print("number of possible moves: {}".format(len(moves)))
import abalone_base as ab

#definition of board setup
CLASSIC_PLAYER = [ab.Position(1,5), ab.Position(1,6), ab.Position(1,7), ab.Position(1,8), ab.Position(1,9),ab.Position(2,4),ab.Position(2,5),ab.Position(2,6),ab.Position(2,7),ab.Position(2,8),ab.Position(2,9),ab.Position(3,5),ab.Position(3,6),ab.Position(3,7)]
CLASSIC_OPPONENT = [ab.Position(9,1), ab.Position(9,2), ab.Position(9,3), ab.Position(9,4),ab.Position(9,5),ab.Position(8,1),ab.Position(8,2),ab.Position(8,3),ab.Position(8,4),ab.Position(8,5),ab.Position(8,6),ab.Position(7,3),ab.Position(7,4),ab.Position(7,5)]