示例#1
0
def main():

    pos = (5, 5)
    posHistory = [pos]
    for i in range(10):
        pos = GeneticTrainer.randomAdjacentPosition(pos)
        posHistory.append(pos)

    from Models.Board import Board
    board = Board()
    for pos in posHistory:
        board.place('X', pos)
    print()
    posSet = set(posHistory)
    print(f"Same length? {len(posHistory) == len(posSet)}")
    if not len(posHistory) == len(posSet):
        print("History:")
        print(posHistory)
        print("\nSet:")
        print(posSet)

    # Ensure that crossover works properly.
    # There should be a mix of 1's, 2's, and potentially a random number or more.
    dict1 = {'weights': torch.Tensor([[1, 1, 1], [1, 1, 1], [1, 1, 1]])}
    dict2 = {'weights': torch.Tensor([[2, 2, 2], [2, 2, 2], [2, 2, 2]])}
    crossover = GeneticTrainer.crossover(dict1, dict2, mutation_rate=0.4)
    print(crossover.get('weights'))

    # Randomize the weights
    print(dict1.get('weights'))
    GeneticTrainer.randomize(dict1, mutation_rate=0.5)
    print(dict1.get('weights'))
示例#2
0
def main():
    word = RandomWord(choice(JsonWords().get_words()))

    while "-" in word.random_word or " " in word.random_word:  # avoids words like "water-based" or entries with spaces
        word = RandomWord(choice(JsonWords().get_words()))

    board = Board(player, word)
    view = View()
    controller = Controller(board, view)

    controller.hint()

    while True:
        controller.take_guess()
        controller.handle_guess()
        controller.result()
        controller.check_winner()

        if controller.winner is not None:
            if play_again():
                main()

            else:
                controller.close()
                quit()
示例#3
0
    def __init__(self, board: Board = None, snakes: List[Snake] = None):
        self.board = board if board is not None else Board()
        self.snakeDict: Dict[str, Snake] = {}
        self.point = None

        if snakes is not None:
            for snake in snakes:
                self.addSnake(snake)
            self.generatePoint()
示例#4
0
 def new_game(cls, board_size, rule_set):
     assert isinstance(board_size, int)
     board_size = (board_size, board_size)
     board = Board(*board_size)
     return State(board, rule_set, Color.black, None, None, rule_set.komi)
示例#5
0
 def init_board(self):
     columns = input("Nombre de colonnes : ")
     rows = input("Nombre de lignes : ")
     self.board_instance = Board(columns, rows)
     self.board_instance.add_building()
     self.init_player()