Python Poker Game (In the works)


Hello all,

I have here for you a text based Texas Holdem’ style poker game, written in Python 2.7, that I have been working on slowly but surely for a little while. It ended up being a lot more complex than I wanted it to be, and as such, I have limited the game to two people currently. Even with not much game to be played currently, I have most of the framework done, and much more can be implemented. I have gotten to a point where I would like to share this with you all, for any enjoyment that may come from it.

Where this could go from here, could be; fixing the issue where the player’s hands must dynamically change based on the number of players, extending the game passed the single first round of hands, and if the second player is the dealer, I haven’t written much there yet, but you could!

Anyways, I will quit my rambling and post the code for you here.

Thank you guys. enjoy!

# -*- coding: utf-8 -*-
# created by nick grimes, 2/20/18

import sys
import time
import os
from random import *
from termcolor import *

# idea for a poker game program
# deal between you and a couple people
# texas holdem rules
# just play like that

# ---

# Update: This may have to be a simple 1-2 hand game lol because
# now that I think about that, that would be a lot more in depth
# than I had previously accounted for haha. May not have the time.

# ---
# if you need to test something, do it here

# ---

def space():
  print ('')
  # because i have organization issues

def show_hands():
  hands_shown = 0
  player_num = 0
  # ----------
  card_one = 0 # this is where I would calculate for more than two players
  card_two = 2 # to dynamically change but that would be for a later time..
  # ----------
  while hands_shown < len(players) - 1: # added '-1' for anon of other hand
  # wasn't thinking about that lol
    print(colored('%s\'s hand is: [%s %s, %s %s]', 'cyan') % (players[player_num], hands[card_one], suit_hands[card_one], hands[card_two], suit_hands[card_two]))
    print(colored('%s\'s hand is: [?,?]', 'cyan') % players[1])
    hands_shown += 1
    player_num += 1
    card_one += 1
    card_two += 1
    # i still need to implement the use of 
    # suites matched with card numbers
    # do not forget this (kinda important lol)

#def blink_once():
	#b = ("Loading")
#def blink(number):
	#for x in range(0, number):

# blind functions -------
#def small_blind_p1():   #
	#player_one_chips -= 1 #
#def small_blind_p2():   #
	#player_two_chips -= 1 #
#def big_blind_p1():     #
	#player_one_chips -= 2 #
#def big_blind_p2():     #
	#player_two_chips -= 2 #
# -----------------------

def poker():
	# inital player chip information
  # -------------------
  global player_one_chips
  player_one_chips = 50
  global player_two_chips
  player_two_chips = 50
  # -------------------
  print(colored('Welcome to Texas Holdem!', 'cyan'))
  print(colored('Enjoy your game! Good Luck!', 'cyan'))
  # def number of players first
  #player_amt = int(raw_input(colored('How many players? (Pick 2 for now): ', 'magenta')))
  print(colored('I was going to allow for the user to pick the amount of players, but two players is the limit that I can do for right now... Sorry :(', 'red', 'on_grey'))
  player_amt = 2
  # initialize player number variable
  player = 1
  # create a list for players to be in
  global players
  players = []
  # loop logic: to pull player names and assign a player number
  # for as many players as specified above! 
  while player <= player_amt:
    # gather player names
    player_name = raw_input(colored('Enter player number %s\'s name: ', 'magenta') % player)
    # adding players to the list
    # to see the list being appended
    # print players
    # basic incremental counter
    player += 1
  # now that players are in order, let's begin!
  print(colored('You start with 50 chips.', 'cyan'))
  print(colored('Blinds are 1 & 2 chips.', 'cyan'))
  print(colored('Let\'s begin!', 'cyan'))
  print(colored('Selecting the first dealer by random...', 'cyan'))
  # i've given up on trying to get this to
  # work. i still don't understand why termcolor
  # doesn't support blinking for a specified 
  # amount of time, I feel like that could be a subatrib

  # ---
  # trying to find a working cls for 2.7
  # might just have to do the old print to clear lol
  # ---
  # randomly decide the dealer
  dealer_value = randint(0, len(players) - 1)
  dealer = players[dealer_value]
  print('{} {} {}'.format(colored('The first dealer is:', 'cyan'), 																	colored(dealer, 'magenta', 'on_grey'),
  												colored('!', 'cyan'	)))
  #print(colored('The first dealer is','cyan'))
  #print(colored('%s', 'magenta') % dealer)
  #print(colored('!', 'cyan'))
  print ('Dealing...')

  # okay even if this doesn't logically make sense from this
  # point on, i really just want to make a functioning
  # system of playing, so we shall see how this goes lol

  # deal 'cards'
  cards = ['2','3','4','5','6','7','8','9','10','J','Q','K','A']
  suits = ['♥', '♠', '♣', '♦']
  cards_delt = 0
  global hands
  global suit_hands
  hands = []
  suit_hands = []
  while cards_delt < (len(players) * 2):
    # cards
    card_delt_value = randint(0, len(cards) - 1)
    card_delt = cards[card_delt_value]
    #print card_delt
    # suits
    suit_delt_value = randint(0, len(suits) - 1)
    suit_delt = suits[suit_delt_value]
    #print suit_delt
    cards_delt += 1
    #print hands
    # print nick = hands[0,3] k[1,4] d[3,5]
  # i was going to use a dictionary for suits,
  # but i tried looking in on how to access indexes
  # of the dictionary but thats looking like more 
  # work than reward at this point...
  # hands must dynamically change based on number of people -_-

  # -------------------
  # collect blinds
  print(colored('%s is the dealer, so they have the small blind to begin.', 'cyan') % dealer)
  print(colored('Collecting blinds...', 'cyan'))
  # i tried having the blind functions
  # on their own, but something in the scope of 
  # the player's chips got fucked up so nevermind.
  # again, i am having to write everything in the simplistic
  # matter of only two players playing, so if this ever were
  # to be updated, the logic for that would have to be written
  # from scratch.
  # checks to see who the dealer is, and 
  # then dishes out blinds based on this
  if dealer == players[0]:
    player_one_chips -= 1
    player_two_chips -= 2
    print ('%s\'s chips: %s') % (players[0], player_one_chips)
    print ('%s\'s chips: %s') % (players[1], player_two_chips)
    next_move = raw_input('Would you like to call, raise, or fold?: ')
    if next_move == 'call':
    	player_one_chips -= 1
    	print ('%s\'s remaining chips: %s') % (players[0], player_one_chips)
    if next_move == 'raise':
    	print ('You have %s chips, you may not raise higher than this amount!' % player_one_chips)
    	raise_amt = int(raw_input('Enter the raise amount: '))
    	player_one_chips -= raise_amt
    	print ('%s raised by %s chips!') % (players[0], raise_amt)
    	print ('%s\'s remaining chips: %s') % (players[0], player_one_chips)
    if next_move == 'fold':
    	print ('%s folds') % (players[0])
    	print ('%s\'s remaining chips: %s') % (players[0], player_one_chips)
  elif dealer == players[1]:
  	player_two_chips -= 1
  	player_one_chips -= 2
  	print ('%s\'s chips: %s') % (players[0], player_one_chips)
  	print ('%s\'s chips: %s') % (players[1], player_two_chips)
  	print ('Would you like to check, raise, or fold?')