예제 #1
0
def test_turncard_sequence():
    print(f'\n-------- Test Turncard Sequence ----------\n')
    #computer vs computer
    p1 = players.Computer(difficulty='medium')
    p2 = players.Computer(difficulty='medium')
    g = games.Cribbage(p1, p2)
    g.deck.shuffle()
    g.determine_dealer_sequence()
    g.turncard_sequence()
예제 #2
0
def test_determine_dealer_sequence():
    print(f'\n-------- Test Determine Dealer Sequence ----------\n')
    #computer vs computer
    p1 = players.Computer(difficulty='medium')
    p2 = players.Computer(difficulty='medium')
    g = games.Cribbage(p1, p2)
    g.deck.shuffle()
    g.determine_dealer_sequence()
    print(f'\n-- Is {g.player_one.name} Dealer? {g.player_one.is_dealer}')
    print(f'\n-- Is {g.player_two.name} Dealer? {g.player_two.is_dealer}')
예제 #3
0
def test_deal_sequence():
    print(f'\n-------- Test Deal Sequence ----------\n')
    #computer vs computer
    p1 = players.Computer(difficulty='medium')
    p2 = players.Computer(difficulty='medium')
    g = games.Cribbage(p1, p2)
    g.deck.shuffle()
    g.determine_dealer_sequence()
    g.deal_sequence()
    print(f'-- {g.player_one.name} hand:')
    g.player_one.display_hand()
    print(f'-- {g.player_two.name} hand:')
    g.player_two.display_hand()
예제 #4
0
def test_cut_deck():
    d = deck.Deck()
    c = players.Computer(difficulty='easy')
    print(f"\n---------  TEST cut_deck() method computer -------------\n")
    print(f'\n-- before cut --\n')
    i = 0
    for card in d.deck:
        i += 1
        print(f'{i}) {card.name}')
    c.cut_deck(d)
    print(f'\n-- after cut --\n')
    i = 0
    for card in d.deck:
        i += 1
        print(f'{i}) {card.name}')

    d = deck.Deck()
    username = '******'
    email = '*****@*****.**'
    u = users.User(username=username, email=email)
    h = players.Human(user=u)
    print(f"\n---------  TEST cut_deck() method human -------------\n")
    print(f'\n-- before cut --\n')
    i = 0
    for card in d.deck:
        i += 1
        print(f'{i}) {card.name}')
    h.cut_deck(d)
    print(f'\n-- after cut --\n')
    i = 0
    for card in d.deck:
        i += 1
        print(f'{i}) {card.name}')
예제 #5
0
def test_computer():
    difficulty = 'hard'
    c = players.Computer(difficulty=difficulty)
    print("\n---------  TEST computer constructor  -------------\n")
    print(f'--Player name: {c.name}')
    print(f'--Player score: {str(c.score)}')
    print(f'--Player difficulty: {c.difficulty}')
예제 #6
0
파일: game.py 프로젝트: cgbreeezy/kmaps
 def __init__(self, multiplayer=False):
     self.grid = Grid()
     self.players[0] = players.Human(self.grid, 0)
     if not multiplayer:
         self.players[1] = players.Computer(self.grid, 1)
     else:
         self.players[1] = players.Human(self.grid, 1)
예제 #7
0
def test_match_human():
    #human vs computer
    u = users.sign_in()
    p1 = players.Human(user=u)
    p2 = players.Computer(difficulty='hard')
    g = games.Cribbage(p1, p2)
    g.game_driver()
예제 #8
0
def test_display_hand():
    d = deck.Deck()
    c = players.Computer('easy')
    hand = []
    for i in range(4):
        hand.append(d.deal_one())
    c.cards = hand
    print("\n---------  TEST display_hand() method without numbers  -------------\n")
    c.display_hand(is_numbered=False)
    print("\n---------  TEST display_hand() method with numbers  -------------\n")
    c.display_hand(is_numbered=True)
예제 #9
0
def test_Classic_constructor():
    print('\n--------- Test Board constructor -------------\n')
    u1 = users.User(username='******', email='*****@*****.**')
    u2 = users.User(username='******', email='*****@*****.**')
    p1 = players.Human(name='Jon', user=u1, lane=1)
    #p2 = players.Human(name='Rick', user=u2, lane=2)
    p2 = players.Computer(difficulty='hard', lane=2)
    b = board.Classic(player_one=p1, player_two=p2)
    print(f'- Player 1 name:     {b.player_one.name}')
    print(f'- Player 2 name:     {b.player_two.name}\n')
    b.display_board()
예제 #10
0
def test_discard_sequence():
    print(f'\n-------- Test Discard Sequence ----------\n')
    #computer vs computer
    p1 = players.Computer(difficulty='medium')
    p2 = players.Computer(difficulty='medium')
    g = games.Cribbage(p1, p2)
    g.deck.shuffle()
    g.determine_dealer_sequence()
    g.deal_sequence()
    print(f'-- {g.player_one.name} hand:')
    g.player_one.display_hand()
    print(f'-- {g.player_two.name} hand:')
    g.player_two.display_hand()
    g.discard_sequence()
    print(f'-- {g.player_one.name} hand:')
    g.player_one.display_hand()
    print(f'-- {g.player_two.name} hand:')
    g.player_two.display_hand()
    print('\n----------- The crib --------------')
    for card in g.crib:
        print(f'|| {card.name}')
예제 #11
0
def main():
    human = players.Human()
    computer = players.Computer()
    while human.score < 10 and computer.score < 10:
        print('Human: {} ... '
              'Computer: {}'.format(human.score, computer.score))
        print('====================================================')
        showdown(human.user_output(), computer.get_random(), human, computer)
    if human.score > computer.score:
        print('Human wins by score '
              'of {} to {}'.format(human.score, computer.score))
    else:
        print('Computer wins by score '
              'of {} to {}'.format(computer.score, human.score))
예제 #12
0
def test_peg_one_computer():
    print(f"\n---------  TEST peg_one() computer -------------\n")
    difficulty = 'easy'
    count = 10
    d = deck.Deck()
    d.shuffle()
    c = players.Computer(difficulty=difficulty)
    hand = []
    stack = []
    for i in range(2):
        hand.append(d.deal_one())
        stack.append(d.deal_one())
    c.cards = hand
    c.display_hand()
    selected = c.peg_one(count=count, stack=stack)
    print(f'Peg selection: {selected.name}')
예제 #13
0
def test_discard_computer():
    difficulty = 'medium'
    num_discards = 2
    d = deck.Deck()
    d.shuffle()
    c = players.Computer(difficulty=difficulty)
    hand = []
    discards = []
    for i in range(6):
        hand.append(d.deal_one())
    c.cards = hand
    print(f"\n---------  TEST discard() method computer -- {difficulty}  -------------\n")
    print('---hand before discards---')
    c.display_hand(False)
    discards = c.discard(num_discards=num_discards, is_dealer=True)
    print('---hand after discards---')
    c.display_hand(False)
    c.cards = discards
    print('---Discard choices---')
    c.display_hand(False)
예제 #14
0
파일: game.py 프로젝트: cgbreeezy/kmaps
 def __init__(self, multiplayer=False):
     self.grid = Grid_Gui()
     self.computer = players.Computer(self.grid, 1)
예제 #15
0
def test_game_driver():
    #computer vs computer
    p1 = players.Computer(difficulty='hard')
    p2 = players.Computer(difficulty='medium')
    g = games.Cribbage(p1, p2)
    g.game_driver()
예제 #16
0
def learning_by_hands(intelligent=True, alternate=True):
    #Function initializations: setup players, deck, turncard, local variables, determine dealer
    p1 = players.Computer(difficulty="medium")
    p2 = players.Computer(difficulty="medium")
    d = deck.Deck()
    d.shuffle()
    crib = []
    turncard = d.deal_one()
    if alternate:
        is_dealer_p1 = True
    else:
        is_dealer_p1 = False

    #Allows learning Function to focus either on random configurations or heuristically influenced configurations
    if not intelligent:
        for i in range(4):
            p1.cards.append(d.deal_one())
            p2.cards.append(d.deal_one())
            crib.append(d.deal_one())
            p1_discards = crib[0:2]
            p2_discards = crib[2:4]
    else:
        p1_dealt_hand = []
        p2_dealt_hand = []
        for i in range(6):
            p1_dealt_hand.append(d.deal_one())
            p2_dealt_hand.append(d.deal_one())
        h1 = hand.Hand(p1_dealt_hand)
        h2 = hand.Hand(p2_dealt_hand)
        #For heuristically influenced hand selection
        h1_selects = h1.optimize_by_points(2)
        h2_selects = h2.optimize_by_points(2)
        p1.cards = list(h1_selects)
        p2.cards = list(h2_selects)
        p1_discards = []
        p2_discards = []

        for cp1, cp2 in zip(p1_dealt_hand, p2_dealt_hand):
            if cp1 not in h1_selects:
                p1_discards.append(cp1)
            if cp2 not in h2_selects:
                p2_discards.append(cp2)

        crib.extend(p1_discards)
        crib.extend(p2_discards)
        """
        h1_combos = combinations(p1_dealt_hand, 4)
        h2_combos = combinations(p2_dealt_hand, 4)
        for h1h, h2h in zip(h1_combos, h2_combos):
            if len(h1h) == 4 and len(h2h) == 4:
                p1.cards = h1h
                p2.cards = h2h
                h1_disc = []
                h2_disc = []
                for card in p1_dealt_hand:
                    if card not in p1.cards:
                        h1_disc.append(card)
                for card in p2_dealt_hand:
                    if card not in p2.cards:
                        h2_disc.append(card)
                crib.extend(h1_disc)
                crib.extend(h2_disc)
                is_dealer_p1 = True
                peg_sequence(is_dealer_p1, turncard, p1, p2)
                p1_peg = p1.score
                p2_peg = p2.score
                show_sequence(turncard, p1, p2)
                crib_pts = crib_sequence(turncard, crib)
                if len(p1.cards) == 4 and len(p2.cards) == 4:
                    memorize_results(p1, p2, p1_peg, p2_peg, is_dealer_p1)
                if len(h1_disc) == 2 and len (h2_disc) == 2:
                    memorize_discards(h1_disc, h2_disc, crib_pts, is_dealer_p1)
                p1.score = 0
                p2.score = 0
                is_dealer_p1 = False
                peg_sequence(is_dealer_p1, turncard, p1, p2)
                p1_peg = p1.score
                p2_peg = p2.score
                show_sequence(turncard, p1, p2)
                crib_pts = crib_sequence(turncard, crib)
                if len(p1.cards) == 4 and len(p2.cards) == 4:
                    memorize_results(p1, p2, p1_peg, p2_peg, is_dealer_p1)
                if len(h1_disc) == 2 and len (h2_disc) == 2:
                    memorize_discards(h1_disc, h2_disc, crib_pts, is_dealer_p1)
                """

        #Main driver block: peg sequence updates player scores; scores stored before updated again in show_sequence
    peg_sequence(is_dealer_p1, turncard, p1, p2)
    p1_peg = p1.score
    p2_peg = p2.score
    show_sequence(turncard, p1, p2)
    crib_pts = crib_sequence(turncard, crib)
    if is_dealer_p1:
        p1.score += crib_pts
    else:
        p2.score += crib_pts
    #Memorize the results, check for occasionally memory corruption
    #if len(p1.cards) == 4 and len(p2.cards) == 4:
    #memorize_results(p1, p2, p1_peg, p2_peg, is_dealer_p1)
    #memorize_discards(p1_discards, p2_discards, crib_pts, is_dealer_p1)
    return [p1.score, p2.score]