示例#1
0
def main_menu():
    click = False

    while True:
        screen.fill((192, 192, 192))
        text_tools.draw_text('IPSSI Card Game', font_title, (0, 0, 0), screen,
                             50, 20)
        mx, my = pygame.mouse.get_pos()
        button_1 = pygame.Rect(50, 200, 300, 100)
        button_2 = pygame.Rect(50, 350, 300, 100)
        button_3 = pygame.Rect(50, 500, 300, 100)
        button_4 = pygame.Rect(50, 650, 300, 100)

        if button_1.collidepoint(mx, my):
            if click:
                play.game()
        if button_2.collidepoint(mx, my):
            if click:
                rules()
        if button_3.collidepoint(mx, my):
            if click:
                options()
        if button_4.collidepoint(mx, my):
            if click:
                exit()

        pygame.draw.rect(screen, (0, 0, 0), button_1)
        pygame.draw.rect(screen, (0, 0, 0), button_2)
        pygame.draw.rect(screen, (0, 0, 0), button_3)
        pygame.draw.rect(screen, (0, 0, 0), button_4)

        screen.blit(font_title.render('Jouer', True, (255, 255, 255)),
                    (88, 225))
        screen.blit(font_title.render('Règles', True, (255, 255, 255)),
                    (88, 375))
        screen.blit(font_title.render('Options', True, (255, 255, 255)),
                    (88, 525))
        screen.blit(font_title.render('Quitter', True, (255, 255, 255)),
                    (88, 675))

        text_tools.blit_text(
            screen,
            'Cliquer sur le menu pour y accèder ou appuyer sur \'Echap\' pour revenir au menu précédent',
            (950, 455), font_text)

        click = False
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
            if event.type == MOUSEBUTTONDOWN:
                if event.button == 1:
                    click = True

        pygame.display.update()
示例#2
0
def main_menu():
    click = False

    while True:
        screen.fill((192, 192, 192))
        screen.blit(fond_ecran, (25, 25))
        text_tools.draw_text('Projet Dev', font_title, (0, 0, 0), screen, 50,
                             20)
        mx, my = pygame.mouse.get_pos()
        button_1 = pygame.Rect(50, 200, 300, 100)
        button_2 = pygame.Rect(50, 350, 300, 100)
        button_3 = pygame.Rect(50, 500, 300, 100)
        button_4 = pygame.Rect(50, 650, 300, 100)

        if button_1.collidepoint(mx, my):
            if click:
                play.game()
        if button_2.collidepoint(mx, my):
            if click:
                rules()
        if button_3.collidepoint(mx, my):
            if click:
                options()
        if button_4.collidepoint(mx, my):
            if click:
                exit()

        screen.blit(font_title.render('Jouer', True, (255, 255, 255)),
                    (88, 225))
        screen.blit(font_title.render('Regles', True, (255, 255, 255)),
                    (88, 375))
        screen.blit(font_title.render('Options', True, (255, 255, 255)),
                    (88, 525))
        screen.blit(font_title.render('Quitter', True, (255, 255, 255)),
                    (88, 675))

        text_tools.blit_text(
            screen, """Cliquer sur le bouton 
que vous voulez et appuyer sur \'Echap\' 
pour revenir au menu precedent""", (1105, 385), font_text, (0, 6, 251))

        click = False
        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    pygame.quit()
                    sys.exit()
            if event.type == MOUSEBUTTONDOWN:
                if event.button == 1:
                    click = True

        pygame.display.update()
示例#3
0
def checkInput():
    """

    :return:
    """
    print("asasaas")
    global grid_size, num_mines, row_size, col_size

    if grid_size.get():
        if num_mines.get():
            row_size = int(grid_size.get())
            col_size = int(grid_size.get())
            mine_size = int(num_mines.get())
            f2.tkraise()
            gm = game(row_size, mine_size)
            create_frame2(row_size, col_size, gm)
            return True
        else:
            num_mines.focus_set()
            return False
        return True
    else:
        grid_size.focus_set()
        return False
示例#4
0
def trainNetwork(current_q,sess):

    
    global sock1,addr1,sock2,addr2
    global data
    global data_2
    data='10'
    data_2='11'
    t1=threading.Thread(target=tcp,args=(sock1, addr1))
    t2=threading.Thread(target=tcp2,args=(sock2, addr2))
    t1.start()
    t2.start()
    pygame.mixer.init()
    pygame.mixer.Sound('audio/7301.wav').play()
    
    game_state = play.game(0,0,0)
    win32api.MessageBox(0,"白色代表人工智能(强化学习)\n蓝色代表人类\n操作电脑上下左右键,z表示蓝蛇加速\n按键1,2,3,4分别对应4种模式\n和人工智能比赛吧","规则",win32con.MB_OK)
    do_nothing = np.zeros(ACTIONS)
   
    do_nothing[random.randrange(ACTIONS)] = 1
    
    s_t,terminal,_= game_state.frame_step(do_nothing,data,data_2,mutex,mutex2)
    s_t = cv2.cvtColor(cv2.resize(s_t.astype(np.uint8), (80, 80)), cv2.COLOR_BGR2GRAY)
    _, s_t = cv2.threshold(s_t,1,255,cv2.THRESH_BINARY)
    s_1 = np.stack((s_t, s_t, s_t, s_t), axis=2)

    sess.run(tf.global_variables_initializer())
    checkpoint = tf.train.get_checkpoint_state("net_data")
    saver = tf.train.Saver()
    if checkpoint and checkpoint.model_checkpoint_path:
        saver.restore(sess, checkpoint.model_checkpoint_path)
        print("Successfully loaded:", checkpoint.model_checkpoint_path)
    else:
        print("Could not find old network weights")
    epsilon = INITIAL_EPSILON
    feed_back=0
    while (True):
        
        
        # choose an action epsilon greedily
        readout_t = current_q.readout.eval(feed_dict={current_q.s : [s_1]})[0]
        a_t = np.zeros([ACTIONS])
        action_index = 0
 
        if random.random() <= epsilon:
           
            action_index = random.randrange(ACTIONS)
            a_t[random.randrange(ACTIONS)] = 1
        else:
            action_index = np.argmax(readout_t)
            a_t[action_index] = 1
        if terminal:
            a_t = np.zeros([ACTIONS])
            a_t[random.randrange(ACTIONS)] = 1
      
        if epsilon > FINAL_EPSILON:
            epsilon -= (INITIAL_EPSILON - FINAL_EPSILON) / EXPLORE
        
        # run the selected action and observe next state and reward
        s_t2,terminal,feed_back= game_state.frame_step(a_t,data,data_2,mutex,mutex2)
        
        s_t2 = cv2.cvtColor(cv2.resize(s_t2.astype(np.uint8), (80, 80)), cv2.COLOR_BGR2GRAY)
        ret, s_t2 = cv2.threshold(s_t2, 1, 255, cv2.THRESH_BINARY)
        s_t2 = np.reshape(s_t2, (80, 80, 1))
        s_2 = np.append(s_t2, s_1[:, :, :3], axis=2)
        s_1=s_2
        if feed_back==1:
        	sock2.send(b'10')
        elif feed_back==2:
        	sock2.send(b'11')
示例#5
0
# -*- coding: utf-8 -*-
"""
Created on Fri Feb  8 15:17:36 2019

@author: Sai Krishna
"""

# Python 2/3 compatibility
import play

gx = 310
gy = 166
gm = 91
stock_fish_path = 'C:\CodeFiles\stockfish-10-win\stockfish-10-win\Windows\stockfish_10_x64'
g = play.game((gx, gy, gm), stock_fish_path)

n_moves = 30
for i in range(n_moves):
    g.update_board()
    g.engine.set_fen_position(g.board.fen())
    mv = g.engine.get_best_move()
    g.move(mv)
示例#6
0
 def main(self):
     play.game()
     play.again()