Home Blog Creating a Teen Patti Game using Circular Linked List in Python
Cricket Top Blogs

Creating a Teen Patti Game using Circular Linked List in Python

Teen Patti, also known as Indian Poker, is a popular game played in many parts of the world, especially in South Asia. The game can involve various strategies and approaches to shine, and its coding can allow you to understand both Python and data structures such as circular linked lists. In this article, we will explore how to create a simple Teen Patti game using a circular linked list in Python. Let's dive into the world of gaming and programming!

Understanding Circular Linked Lists

A circular linked list is a variation of a regular linked list where all nodes are connected in a circular fashion. This means that the last node points back to the first node instead of pointing to null. This structure can be particularly advantageous for games where players take turns in a loop until a specific condition is met.

Why Use Circular Linked Lists for Teen Patti?

In Teen Patti, players take turns to play, and the circular linked list is a perfect fit for representing this cyclic gameplay. It allows us to easily traverse through players, manage gameplay sequences, and efficiently handle player actions. Using a circular linked list can also help manage the deck of cards, where the last card can link back to the first card, creating a smooth flow of play.

Setting Up the Python Environment

Before we delve into coding, ensure that you have Python installed on your system. If you haven't, you can download the latest version from the official Python website. Once you have Python set up, we can start coding our Teen Patti game.

Defining Node Class for Circular Linked List

To represent each player in our game, we first need to create a Node class that contains information about the player. Here’s how the Node class can be defined:

class Node:
    def __init__(self, player_name):
        self.player_name = player_name
        self.next = None

In this code snippet, the Node class has two attributes: player_name, which will hold the name of the player, and next, which points to the next player in the game.

Creating the Circular Linked List class

Now that we have our Node defined, we can create a CircularLinkedList class to manage the players:

class CircularLinkedList:
    def __init__(self):
        self.head = None

    def append(self, player_name):
        new_node = Node(player_name)
        if not self.head:
            self.head = new_node
            new_node.next = self.head
        else:
            current = self.head
            while current.next != self.head:
                current = current.next
            current.next = new_node
            new_node.next = self.head

In this class, the append method adds a new player to the circular list. If the list is empty (indicated by self.head being None), the new node becomes the head and points to itself. Otherwise, it traverses to the last node and updates the next pointers accordingly.

Implementing Player Turns

In Teen Patti, players take turns. We can manage player turns using a method that iterates through the circular linked list:

def play_game(self):
        current = self.head
        while True:
            print(f"It's {current.player_name}'s turn.")
            action = input("Enter 'play' to play, 'quit' to exit: ")
            if action == "quit":
                print(f"{current.player_name} has exited the game.")
                break
            current = current.next

The play_game method iteratively goes through each player, allowing them to take their turn. The loop continues until a player decides to quit the game.

Card Management in Teen Patti

In addition to the players, we also need to manage a deck of cards. Let's create a simple class to represent a deck:

import random

class Deck:
    def __init__(self):
        self.cards = [f"{rank} of {suit}" for rank in ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A'] 
                               for suit in ['Hearts', 'Diamonds', 'Clubs', 'Spades']]
        random.shuffle(self.cards)

    def draw_card(self):
        return self.cards.pop() if self.cards else None

The Deck class initializes a standard set of playing cards and has a method to draw cards. This simulates the action of dealing cards to players in Teen Patti.

Integrating the Deck with Players

Let's modify the play_game method to allow players to draw cards:

def play_game(self):
        current = self.head
        deck = Deck()  # Initialize deck
        while True:
            print(f"It's {current.player_name}'s turn.")
            action = input("Enter 'draw' to draw a card, 'quit' to exit: ")
            if action == "draw":
                card = deck.draw_card()
                if card:
                    print(f"{current.player_name} drew the {card}.")
                else:
                    print("No more cards in the deck.")
                    break
            elif action == "quit":
                print(f"{current.player_name} has exited the game.")
                break
            current = current.next

This updated play_game method allows players to draw a card during their turn. If cards are available, the drawn card is displayed to the player.

Finalizing our Teen Patti Game

Now, we can combine all the pieces into a simple game loop. Below is how the entire structure comes together:

if __name__ == "__main__":
    game = CircularLinkedList()
    players = ['Alice', 'Bob', 'Charlie', 'Diana']

    for player in players:
        game.append(player)

    game.play_game()

Running this code will create a new Teen Patti game with the specified players, allowing them to take turns drawing cards from the deck until they choose to exit the game.

Extending the Game

This setup provides a foundational structure for a Teen Patti game. You can extend the game with additional features like betting, scoring, or a graphical user interface (GUI). Libraries like Tkinter or Pygame can be used for a more interactive experience, allowing you to create a fully-fledged gaming application.

Learning Outcomes

By creating a Teen Patti game using circular linked lists in Python, you deepen your understanding of both the game and the underlying data structures. This endeavor not only enhances your programming skills but also provides an entertaining way to learn!

Final Thoughts

Embarking on a project like this can be an excellent way to practice programming and logic skills while engaging with a game that many love. The concepts and techniques you learn can also be applied to a variety of other projects.


India’s Favourite Card Game Lives On in Teen Patti Master

🪔 Teen Patti Master Brings the Classic Teen Patti Table to Your Screen
Feel like you're at a Diwali game night every time you open Teen Patti Master.
🎲 All Original Modes Are in Teen Patti Master
Joker, Muflis, AK47—Teen Patti Master preserves the authentic ways India loves to play.
💵 Win Like in the Old Days — Only on Teen Patti Master
Compete for real chips, climb ranks, and win money just like traditional card games, now in Teen Patti Master.
🌐 Teen Patti Master Connects Millions of Indian Card Lovers
Join crores of players who’ve made Teen Patti Master their go-to online poker room.

Latest Blog

How Much Can You Collect in Teen Patti?

Teen Patti, often referred to as Indian Poker, has gained immense popularity not just as a social gaming experience but also as a means to earn money....

Unlocking Fun: The Latest Modded Version of Teen Patti Gold

Do you want to elevate your gaming experience? Look no further than the latest modded version of Teen Patti Gold. This popular card game, revered not ...

The Ultimate Guide to Playing Teen Patti Online for Real Money

Teen Patti, often referred to as Indian Poker, is a popular card game that combines strategy, skill, and a bit of luck. With the rise of online gaming...

Winning Big: The Ultimate Guide to Playing Online Teen Patti with Real Money

Teen Patti, often referred to as Indian Poker, is one of the fastest-growing card games today, especially with the rise of online platforms enabling p...

Unlocking the Fun: Exploring Teen Patti Gold Mod APK

Teen Patti Gold is a popular card game that has captured the hearts of many players across India and beyond. This game, often referred to as Indian Po...

Teen Patti Gold Hack: Unlock Winning Strategies from RevDL Blog

Teen Patti, often referred to as Indian Poker, is a beloved card game that has captivated players globally, particularly among teenagers and young adu...

FAQs - Teen Patti Master

Q1: What is Teen Patti Master?
It’s an exciting online card game based on Indian Teen Patti. Play against real players and win cash!
Q2: Is Teen Patti Master free?
Yes, it’s free to play! But you can also buy chips for more fun.
Q3: Can I play with friends?
Of course! Create private tables & invite your friends.
Q4: What’s Teen Patti Speed?
A faster version of Teen Patti for those who like quick games.
Q5: What’s the minimum age to play?
You must be at least 18 years old to play. Some places require 21+.
Q6: How do I start playing Slots Meta?
Download Slots Meta, create an account, and start spinning!
DOWNLOAD NOW