Exemplo n.º 1
0
    def __init__(self, parent=None):
        super().__init__(parent)  #调用父类构造函数,创建窗体
        self.ui = Ui_Widget()  #创建UI对象
        self.ui.setupUi(self)  #构造UI界面

        self.boy = Human("Boy", 16)
        self.boy.nameChanged.connect(self.do_nameChanged)

        self.boy.ageChanged.connect(self.do_ageChanged_int)
        self.boy.ageChanged[str].connect(self.do_ageChanged_str)
Exemplo n.º 2
0
    def __init__(self):
        super().__init__()
        self.ui = Ui_Widget()
        self.ui.setupUi(self)

        self.boy = Human("Boy", 16)
        #创建三个连接,将实例中的三个信号与3个自定义槽函数关联
        self.boy.nameChanged.connect(self.do_nameChanged)
        self.boy.ageChanged.connect(self.do_ageChanged_int)
        self.boy.ageChanged[str].connect(self.do_ageChanged_str)
Exemplo n.º 3
0
 def select_player2(self):
     player2_prompt = input('is player two a computer player?')
     if player2_prompt == 'no':
         self.player2 = Human()
         return self.player2
     elif player2_prompt == 'yes':
         self.player2 = Computer()
         return self.player2
     else:
         print('sorry that input is invalid. please print "yes"" or "no"')
         self.select_player2()
Exemplo n.º 4
0
def run():
    board = Board(width=7, height=7, n_in_row=4)
    game = Game(board)
    best_policy = PolicyValueNetwork(N=7,
                                     planes=4,
                                     model_name='models/558.model.h5')
    mcts_player = MCTSPlayer(best_policy.policy_value_fn, c_puct=5, n_mcts=500)
    human = Human()
    if (not game.PlayWithHumanMode(
            human, mcts_player, BOARD_RAOD=7, start_player=1, is_shown=1)):
        return False
Exemplo n.º 5
0
    def __init__(self):
        policy_param = pickle.load(open('best_policy_8_8_5.model', 'rb'),
                                   encoding='bytes')
        best_policy = PolicyValueNetNumpy(8, 8, policy_param)
        mcts_player = MCTSPlayer(best_policy.policy_value_fn,
                                 c_puct=10,
                                 n_playout=1000)
        human = Human()

        self.game = Game(Board(width=8, height=8, n_in_row=5), human,
                         mcts_player)
Exemplo n.º 6
0
def human_against_agent(player_num, filename):
  play = True
  while play == True:
    # Assign players
    if player_num == 1:
      player_1 = Human(1)
      player_2 = Agent(2, -1, 0.0, .1, 0.9, True, filename)
    else:
      player_1 = Agent(1, -1, 0.0, .1, 0.9, True, filename)
      player_2 = Human(2)

    winner, board_state_hash = TicTacToe.play(player_1, player_2)
    if player_num == 2:
      # then player 1 must be the agent
      print("Thanks for the training data silly human!")
      player_1.dump_policy_to_csv('p1_policy.csv')

    action = input('Play Again? (y or n)')
    if action != 'y':
      return
Exemplo n.º 7
0
def main():
    board = Board()
    players = [
        Human(0),
        RandomBot(1),
        GreedyActionBot(2, time=120),
        MCTSBot(3, adaptive_budget=True)
    ]
    scores = game_loop(board, players, visualize=True)
    print(np.argmax(scores) + 1, 'wins!')
    return scores
Exemplo n.º 8
0
def setup():
    print("\033c")
    print("Please enter in the following information: ")
    name = input("What is your name: ")
    age = int(input("What is your age: "))
    while not validSetup(age):
        age = int(input("What is your age: "))
    gender = input("what is your gender: ")
    person = Human(name, age, gender)
    print("Now we got you set up, time to choose your car!!!")
    carInfo(person)
Exemplo n.º 9
0
    def __init__(self, id, player1, player2):
        self.id = id
        self.player1 = player1
        self.player2 = player2

        self.player1_name = ""
        self.player2_name = ""

        self.current_announcement = ""

        self.player_moving = 1

        #All types of decks, including discard piles, trash pile, and player decks
        self.cancer_deck = []
        self.zombie_deck = []
        self.doctor_deck = []
        self.doctor_discard_pile = []
        self.zombie_discard_pile = []
        self.trash_pile = []
        self.player1_deck = []
        self.player2_deck = []
        self.master_deck = []

        self.zombie_reshuffled = 0
        self.doctor_reshuffled = 0

        self.winner = -1

        self.humans = []
        self.humans.append(Human(0, "Man 1"))
        self.humans.append(Human(1, "Man 2"))
        self.humans.append(Human(2, "Woman 1"))
        self.humans.append(Human(3, "Woman 2"))
        
        self.spec_map = {"L":"Lung Cancer", "B":"Breast Cancer","P":"Prostate Cancer","C":"Colon Cancer","N":"Pancreatic Cancer","M":"Mouth Cancer", "U":"Uterus/Ovary Cancer","R":"Cervical Cancer"}
        self.index_map = {"L": 0, "B": 1, "P": 2, "C": 3, "N": 4, "M": 5, "U": 6, "R":7}
        self.name_map = {"L": "Lung", "B": "Breast", "P": "Prostate", "C": "Colon", "N": "Pancreatic", "M": "Mouth", "U": "Uterus/Ovary", "R":"Cervical"}
        self.human_map = {0: "Liam", 1: "Noah", 2: "Emma", 3: "Ava"}

        self.init_cancer_points()
        self.init_cards()
Exemplo n.º 10
0
    def play(self):

        model_file = "current.model"
        best_policy = PolicyValueNet(self.width, self.height, model_file)
        mcts_player = MCTSPlayer(best_policy.policy_value_fn,
                                 c_puct=5,
                                 n_playout=300)
        pure_player = MCTS_Pure(c_puct=5, n_playout=300)

        human1 = Human()
        human2 = Human()
        # self.show()

        win_cnt = defaultdict(int)
        for i in range(10):
            winner = self.start_play(mcts_player,
                                     pure_player,
                                     start_player=(i % 2),
                                     is_shown=1)
            win_cnt[winner] += 1
        print "win", win_cnt[1], "lose", win_cnt[2], "tie", win_cnt[0]
Exemplo n.º 11
0
 def get_human_list(self, human_data_list):
     human_list = []
     print(human_data_list)
     for human_data in human_data_list:
         human_data = ast.literal_eval(human_data)
         human = Human(
             id=human_data['id'],
             height=human_data['height'],
             weight=human_data['weight'],
         )
         human_list.append(human)
     return human_list
Exemplo n.º 12
0
 def __init__(self):
     self.name = "Chess"
     self.theme_mode = 0
     self.loadThemes()
     self.window = Window(name=self.name, size=[700, 700])
     self.player1 = Human(1)
     self.player2 = Robot(2)
     self.board = Board()
     self.delta = 0.00000001
     self.cursor = None
     self.click = None
     self.player = self.player1
Exemplo n.º 13
0
 def check_new_peaple(self):
     part_food = self.village.get_surplus_food2()
     # print("part_food", part_food)
     if part_food >= 6:
         human = Human()
         self.village.add_human(human)
         faith = 10
         self.player.add_faith(faith)
         print(
             colored(
                 "Житель {} прибыл в деневню. Вера увеличилась на {}".
                 format(human.name, faith), "cyan"))
Exemplo n.º 14
0
 def select_player_type(self, player_number):
     print(
         f'Please select a player type for Player {player_number}! Enter C for Computer or H for Human'
     )
     while True:
         string = input("Enter Player Type: ")
         string = string.lower()
         if string == 'c':
             return Computer()
         elif string == "h":
             return Human()
         print('Please enter C or H only!')
Exemplo n.º 15
0
 def creer_joueurs(self):
     """
     Crée les 4 joueurs (Humains et IAs et les répartit aléatoirement
     """
     liste = [i+1 for i in range(self.nb_clients)] + [0]*(4-self.nb_clients)
     random.shuffle(liste)
     for i, p in enumerate(liste):
         if p > 0:
             self.envoi(self.clients[p-1], "indice,"+str(i))
             self.players.append(Human(0, i, self.clients[p-1]))
         else:
             self.players.append(IA(0, i, self.database))
def getHuman():
    """Load a human model with modifiers."""
    with mhpath:
        # maxFaces *uint* Number of faces per vertex (pole), None for default (min 4)
        human = Human(files3d.loadMesh(
            getpath.getSysDataPath("3dobjs/base.obj"),
            maxFaces=5))
        # load modifiers onto human
        humanmodifier.mods_loaded = False
        modifiers = humanmodifier.loadModifiers(
            getpath.getSysDataPath('modifiers/modeling_modifiers.json'), human)
        return human
Exemplo n.º 17
0
 def run_game(self):
     multiplayer = self.multiplayer()
     rounds_to_win = self.rounds()
     if multiplayer:
         self.player_two = Human("Player Two")
     while self.player_one.wins < rounds_to_win and self.player_two.wins < rounds_to_win:
         self.player_choice_prompt(self.player_one)
         if self.player_two.name == "Player Two":
             self.player_choice_prompt(self.player_two)
         else:
             self.computer_choice()
         self.results()
     self.display_winner()
Exemplo n.º 18
0
  def generate(self):
    planet = Planet()
    for count in range(random.randint(0, 100)):
      robot = Robot(f"Robot{count}")
      planet.add_robot(robot)
      self.robots = self.robots + 1 

    for count in range(random.randint(0, 100)):
      human = Human(f"Human{count}")
      planet.add_human(human)
      self.humans = self.humans + 1 

    self.planets.append(planet)
Exemplo n.º 19
0
    def __init__(self, master):
        self.master = master
        self.game_over = False
        self.player_1 = Human()
        self.player_2 = Human()
        self.temp1 = Human()
        self.temp2 = Human()
        self.curr_player = Human()
        self.game = Connect4(7, 6)

        master.title('Connect Four')

        label = Label(master, text="Connect Four")
        label.grid(row=0)

        self.canvas = Canvas(master, width=500, height=500)
        self.canvas.grid(row=2)

        self.draw_grid()

        self.canvas.bind('<Button-1>', self.canvas_click)
        self.drawButtons()
Exemplo n.º 20
0
def run_game():
    fps = 60
    pygame.init()
    win = Window()
    scr = pygame.display.set_mode(win.screen_size)
    clock = pygame.time.Clock()
    pygame.display.set_caption("COVID - 19 (SIMULATOR)")
    s = Settings(pun=None)
    humans = []
    for i in range(s.human_number - 1):
        humans.append(Human(win, scr))
    ill_human = Human(win, scr)
    ill_human.is_ill = True
    ill_humans = [ill_human]

    while True:
        gf.check_event()
        clock.tick(fps)
        gf.update_screen(win, scr, humans, ill_humans)
        for human in humans:
            if human.is_ill:
                humans.pop(humans.index(human))
                ill_humans.append(human)
Exemplo n.º 21
0
 def getHuman(self):
     self.humans = []
     count = 0
     #print("Start appending")
     for node in self.model.nodes:
         if node.nodeType == 'Human':
             count = count + 1
             human = Human(node.nodeIdentifier,
                           float(node.attributes['xPos']),
                           float(node.attributes['yPos']),
                           float(node.attributes['angle']))
             self.humans.append(human)
     #print("End Appending")
     print("Added " + str(count) + "Humans")
Exemplo n.º 22
0
  def generate(self):
    planet = Planet()

    num_humans = random.randit(0, 100)
    num_robots = random.randit(0, 100)

    for count in range(num_humans):
      human = Human()
      planet.add_human(human)

    for count in range(num_robots):
      robot = Robot()
      planet.add_robot(robot)

    for index in range(random.randint(1,10)):
      robot = Robot(f"Robot{index}")
      planet.add_robot(human)

    for index in range(random.randint(1,10)):
      human = Human(f"Human{index}")
      planet.add_human(human)
    
    self.planets.append(planet)
Exemplo n.º 23
0
    def generate(self):
        #Creates a new planet
        planet = Planet()

        for index in range(rnd.randint(1, 10)):
            robot = Robot(f"Robot{index}")
            planet.add_robot(robot)

        for index in range(rnd.randint(1, 10)):
            human = Human(f"Robot{index}")
            planet.add_human(human)

        #Populates the list of planets
        self.planets.append(planet)
Exemplo n.º 24
0
def main(argv):
    if not args_check(argv):
        quit()
    else:
        port = int(argv[2])
        if len(argv) == 4:
            ip = argv[3]
        else:
            ip = None
        character = argv[1].lower()

        if ip == None:
            if platform == 'linux':
                root.root.configure(bg="white",
                                    cursor="dot blue blue")
                root.root.title("Connect Four - server")
                if character == 'is_human':
                    Human(0, root, port)
                else:
                    AI(0, root, port)
            if platform == 'win32':
                root.root.configure(bg="white",
                                    cursor="@assets/cursor_blue.cur")
                root.root.title("Connect Four - server")
                if character == 'is_human':
                    Human(0, root, port)
                else:
                    AI(0, root, port)
            else:
                root.root.title("Connect Four - client")
                if character == 'is_human':
                    Human(1, root, port, ip)
                else:
                    AI(1, root, port, ip)
        else:
            if platform == 'linux':
                root.root.configure(bg="white",
                                    cursor="dot red red")
                root.root.title("Connect Four - client")
                if character == 'is_human':
                    Human(1, root, port, ip)
                else:
                    AI(1, root, port, ip)
            if platform == 'win32':
                root.root.configure(bg="white",
                                    cursor="@assets/cursor_red.cur")
                root.root.title("Connect Four - client")
                if character == 'is_human':
                    Human(1, root, port, ip)
                else:
                    AI(1, root, port, ip)
            else:
                root.root.title("Connect Four - client")
                if character == 'is_human':
                    Human(1, root, port, ip)
                else:
                    AI(1, root, port, ip)
Exemplo n.º 25
0
 def generateHuman(self, availableId):
     human = None
     while human is None:
         if time.time() - self.generation_time > MAX_GENERATION_WAIT:
             raise RuntimeError('MAX_GENERATION_ATTEMPTS')
         if QtCore.qrand() % 3 == 0:
             xx = int(random.normalvariate(0, 150))
             yy = int(random.normalvariate(0, 150))
         else:
             xx = QtCore.qrand() % 800 - 400
             yy = QtCore.qrand() % 800 - 400
         human = Human(availableId, xx, yy, (QtCore.qrand() % 360) - 180)
         if not self.room.containsPolygon(human.polygon()):
             human = None
     return human
Exemplo n.º 26
0
    def generate(self):
        # create a new planet
        planet = Planet2()

        # populate with random humans and robots
        for index in range(random.randint(1, 10)):
            robot = Robot(f"Robot{index}")
            planet.add_robot(robot)

        for index in range(random.randint(1, 10)):
            human = Human(f"Human{index}")
            planet.add_human(human)

        # add to list of planets
        self.planets.append(planet)
Exemplo n.º 27
0
 def __init__(self):
     self.players = [Human('Player'), CPU('CPU')]
     self.dealToCrib = False
     if (len(self.players) == 2):
         self.dealCardNumber = 6
     elif (len(self.players) == 3 or len(self.players) == 4):
         self.dealCardNumber = 5
         self.dealToCrib = True
     else:
         raise ValueError('Number of players not supported')
     self.gameWinningScore = 121
     self.cutCard = None
     self.currentDealer = None
     self.deck = Deck()
     self.crib = Hand()
Exemplo n.º 28
0
    def generate(self):
        #creates a planet
        planet = Planet()

        #adds a random number of humans and robots to the planet object

        for index in range(random.randint(1, 10)):
            robot = Robot(f"Robot{index}")
            planet.add_robot(robot)

        for index in range(random.randint(1, 10)):
            human = Human(f"Human{index}")
            planet.add_human(human)

        # add to list of planets
        self.planets.append(planet)
Exemplo n.º 29
0
def main():
    epsilon, discount, alpha, iterations, selfPlay, readValues = get_args(
        sys.argv)
    if selfPlay == True:
        agent1 = Agent(1, epsilon, discount, alpha)
        agent2 = Agent(-1, epsilon, discount, alpha)
        print(
            "Beginning self play. Corresponding state values will be stored in agent1_values.txt and agent2_values.txt"
        )
        for i in range(iterations):
            print("Iteration %d..." % (i))
            self_play(agent1, agent2)

        agent1.write_qvalues('agent1_values.txt')
        agent2.write_qvalues('agent2_values.txt')

    elif readValues == True:
        token = 0
        ai = 0
        while (True):
            token = input("What piece would you like to be (X/O)")
            if token == "X" or token == "O":
                break
        if token == "X":
            token = 1
            ai = Agent(token * -1,
                       epsilon=.2,
                       discount=.7,
                       alpha=.7,
                       readValues=True,
                       file="./agent2_values.txt")
        else:
            token = -1
            ai = Agent(token * -1,
                       epsilon=.2,
                       discount=.7,
                       alpha=.7,
                       readValues=True,
                       file="./agent1_values.txt")
        human = Human(token)
        if token == 1:
            # human is X
            play_human_vs_ai(human, ai, token)
            ai.write_qvalues("agent2_values.txt")
        else:
            play_human_vs_ai(ai, human, token)
            ai.write_qvalues("agent1_values.txt")
Exemplo n.º 30
0
 def __init__(self):
     self.bg = pygame.image.load("images/bg.jpg")
     self.bg = pygame.transform.scale(self.bg,
                                      (SCREEN_WIDTH, SCREEN_HEIGHT))
     self.bgrect = self.bg.get_rect()
     self.ball = Ball()
     self.human = Human()
     self.robot = Robot()
     self.goal = Goal(0)
     self.win = Win(0)
     self.lose = Lose(0)
     self.menu = Menu()
     self.mouse = (0, 0)
     self.sounds = Sounds()
     self.sounds.music()
     self.status = Game.MENU
     self.reset()