Esempio n. 1
0
    def __init__(self):
        self.game = None
        self.p1 = None
        self.p2 = Human_player()
        self.manual = False
        tk = Tkinter

        root = tk.Tk()
        #cv = tk.Canvas(root, width=800, height=600)
        #cv.pack(side=tk.LEFT)

        #load card images
        c = Card(1, 1)
        self.cards = {}
        for suit in ["Clubs", "Diamonds", "Hearts", "Spades"]:
            for card in range(2, 15):
                #self.cards[card, suit[0]]=tk.PhotoImage(Image.open("D:/Dropbox/CS4780/Project/Machine-Learning/cards/"+suit+"/"+c.getCardOfNum(card)+suit[0]+".eps"))
                self.cards[card, suit[0]] = tk.PhotoImage(
                    file="./cards_gif/" + suit[0].lower() +
                    c.getCardOfNum(card).lower() + ".gif")
        self.unknownCard = tk.PhotoImage(file="./cards_gif/b2fv.gif")
        root.title("Hold'em Poker")
        root.minsize(800, 600)

        #need self.backbround b/c python garbage collects it otherwise
        self.backGround = tk.PhotoImage(file="./bkg.gif")
        backGroundLabel = tk.Label(root, image=self.backGround)
        backGroundLabel.place(x=0, y=0, relwidth=1, relheight=1)

        tpFrame = tk.Frame(root)
        tpFrame.pack(side=tk.TOP, fill=tk.Y)

        self.newGameB = tk.Button(tpFrame,
                                  text="New Game",
                                  command=self.newGame)
        self.newGameB.config(state=DISABLED)
        self.newGameB.pack(side=tk.LEFT)

        loadBotB = tk.Button(tpFrame, text="Load Bot", command=self.loadBot)
        loadBotB.pack(side=tk.LEFT)

        showCardsB = tk.Button(tpFrame,
                               text="Show Hand",
                               command=self.displayPocketCards)
        showCardsB.pack(side=tk.LEFT)

        resetB = tk.Button(tpFrame,
                           text="Reset Buttons",
                           command=self.toggleButtons)
        resetB.pack(side=tk.LEFT)

        manualB = tk.Button(tpFrame,
                            text="Manual Toggle",
                            command=self.toggleManual)
        manualB.pack(side=tk.LEFT)

        p1ActionFrame = tk.Frame(root)
        p1ActionFrame.pack(side=tk.TOP, fill=tk.Y)
        self.p1Action = tk.StringVar()
        p1ALabel = tk.Label(p1ActionFrame, textvariable=self.p1Action)
        p1ALabel.pack(side=tk.LEFT)

        self.p1Money = tk.StringVar()
        p1MLabel = tk.Label(p1ActionFrame,
                            textvariable=self.p1Money,
                            bg="yellow")
        p1MLabel.pack(side=tk.LEFT)

        self.p1Dealer = tk.StringVar()
        p1DLabel = tk.Label(p1ActionFrame, textvariable=self.p1Dealer)
        p1DLabel.pack(side=tk.RIGHT)

        #holds the frames for displaying each player's cards as well as table
        tableFrame = tk.Frame(root, width=800, height=600)
        tableFrame.place(in_=root, anchor="c", relx=.5, rely=.5)

        #tableStatusFrame = tk.Frame(tableFrame, bg="green")
        self.statusMessage = tk.StringVar()
        tableStatusLabel = tk.Label(tableFrame,
                                    bg="green",
                                    textvariable=self.statusMessage)
        tableStatusLabel.pack(side=tk.TOP, fill=tk.Y)

        p1Cust = tk.Frame(tableFrame, width=800, height=100)
        self.p1Cust1 = StringVar()
        p1CustEntry1 = Entry(p1Cust, textvariable=self.p1Cust1)
        p1CustEntry1.pack(side=tk.LEFT, fill=tk.X)
        self.p1Cust2 = StringVar()
        p1CustEntry2 = Entry(p1Cust, textvariable=self.p1Cust2)
        p1CustEntry2.pack(side=tk.LEFT, fill=tk.X)
        #p1Cust.pack(side=tk.TOP)

        #tableFrame.pack(side=tk.TOP, fill=tk.Y)
        p1Frame = tk.Frame(tableFrame, bg="white", width=800, height=100)
        p1Frame.pack(side=tk.TOP)

        self.p1Card1 = Label(p1Frame, text="P1 C1")
        self.p1Card1.pack(side=tk.LEFT, fill=tk.X)
        self.p1Card2 = Label(p1Frame, text="P1 C2")
        self.p1Card2.pack(side=tk.LEFT, fill=tk.X)

        communityCust = tk.Frame(tableFrame, width=800, height=400)
        self.fCust1 = StringVar()
        self.fCust2 = StringVar()
        self.fCust3 = StringVar()
        self.tCust = StringVar()
        self.rCust = StringVar()
        fCust1Entry = Entry(communityCust, textvariable=self.fCust1)
        fCust1Entry.pack(side=tk.LEFT, fill=tk.X)
        fCust2Entry = Entry(communityCust, textvariable=self.fCust2)
        fCust2Entry.pack(side=tk.LEFT, fill=tk.X)
        fCust3Entry = Entry(communityCust, textvariable=self.fCust3)
        fCust3Entry.pack(side=tk.LEFT, fill=tk.X)
        tCustEntry = Entry(communityCust, textvariable=self.tCust)
        tCustEntry.pack(side=tk.LEFT, fill=tk.X)
        rCustEntry = Entry(communityCust, textvariable=self.rCust)
        rCustEntry.pack(side=tk.LEFT, fill=tk.X)
        #communityCust.pack(side=tk.TOP, fill=tk.BOTH)

        communityFrame = tk.Frame(tableFrame, width=800, height=400)
        #labels hold will hold cards
        self.f1Card = Label(communityFrame, text="Flop1")
        self.f1Card.pack(side=tk.LEFT)
        self.f2Card = Label(communityFrame, text="Flop2")
        self.f2Card.pack(side=tk.LEFT)
        self.f3Card = Label(communityFrame, text="Flop3")
        self.f3Card.pack(side=tk.LEFT)
        self.tCard = Label(communityFrame, text="Turn")
        self.tCard.pack(side=tk.LEFT)
        self.rCard = Label(communityFrame, text="River")
        self.rCard.pack(side=tk.LEFT)
        communityFrame.pack(side=tk.TOP)

        p2Frame = tk.Frame(tableFrame, width=800, height=100)
        p2Frame.pack(side=tk.BOTTOM)
        p2Cust = tk.Frame(tableFrame, width=800, height=100)
        self.p2Cust1 = StringVar()
        p2CustEntry1 = Entry(p2Cust, textvariable=self.p2Cust1)
        p2CustEntry1.pack(side=tk.LEFT, fill=tk.X)
        self.p2Cust2 = StringVar()
        p2CustEntry2 = Entry(p2Cust, textvariable=self.p2Cust2)
        p2CustEntry2.pack(side=tk.LEFT, fill=tk.X)
        #p2Cust.pack(side=tk.TOP)

        self.p2Card1 = tk.Label(p2Frame, text="P2 C1", image=None)
        self.p2Card1.pack(side=tk.LEFT)
        self.p2Card2 = Label(p2Frame, text="P2 C2")
        self.p2Card2.pack(side=tk.LEFT)

        #Frame holding player action button
        btFrame = tk.Frame(root)
        btFrame.pack(side=tk.BOTTOM, fill=tk.Y)

        p2ActionFrame = tk.Frame(root)
        p2ActionFrame.pack(side=tk.BOTTOM, fill=tk.Y)

        self.p2Action = tk.StringVar()
        p2ALabel = tk.Label(p2ActionFrame, textvariable=self.p2Action)
        p2ALabel.pack(side=tk.LEFT)

        self.p2Money = tk.StringVar()
        p2MLabel = tk.Label(p2ActionFrame,
                            textvariable=self.p2Money,
                            bg="yellow")
        p2MLabel.pack(side=tk.LEFT)

        self.p2Dealer = tk.StringVar()
        p2DLabel = tk.Label(p2ActionFrame, textvariable=self.p2Dealer)
        p2DLabel.pack(side=tk.RIGHT)

        self.checkB = tk.Button(btFrame, text="Check", command=self.pCheck)
        self.checkB.pack(side=LEFT)
        self.callB = tk.Button(btFrame, text="Call", command=self.pCall)
        self.callB.pack(side=LEFT)
        self.raiseB = tk.Button(btFrame, text="Raise", command=self.pRaise)
        self.raiseB.pack(side=LEFT)
        self.foldB = tk.Button(btFrame, text="Fold", command=self.pFold)
        self.foldB.pack(side=LEFT)
        self.endRoundB = tk.Button(btFrame,
                                   text="End Round",
                                   command=self.pEndRound)
        self.endRoundB.pack(side=LEFT)
Esempio n. 2
0
    CFG.eval_win_rate = arguments.eval_win_rate
    CFG.load_model = arguments.load_model
    CFG.human_play = arguments.human_play
    CFG.resnet_blocks = arguments.resnet_blocks
    CFG.record_loss = arguments.record_loss
    CFG.loss_file = arguments.loss_file
    # CFG.game = arguments.game

    game = BlokusGame()

    net = NeuralNetworkWrapper(game)

    # Initialize the network with the best model.
    if CFG.load_model:
        file_path = CFG.model_directory + "best_model.meta"
        if os.path.exists(file_path):
            net.load_model("best_model")
        else:
            print("Trained model doesn't exist. Starting from scratch.")
    else:
        print("Trained model not loaded. Starting from scratch.")

    # Play vs the AI as a human instead of training.
    # DOESN'T WORK YET
    if CFG.human_play:
        human_player = Human_player(game, net)
        human_player.play()
    else:
        train = Train(game, net)
        train.start()