Python3 program to implement FLAMES game

Introduction to the FLAMES Game
The FLAMES game is a popular icebreaker and relationship prediction game that has been enjoyed by people of all ages for decades. The game‘s name is an acronym that stands for Friends, Lovers, Affectionate, Marriage, Enemies, and Siblings, and it is used to determine the potential relationship between two individuals based on their names.

The FLAMES game is known for its simplicity and fun factor, making it a popular choice for parties, social gatherings, and even educational settings. Despite its lighthearted nature, the game has captured the imagination of people worldwide, and its enduring popularity has led to the development of various programming implementations across different languages.

In this comprehensive guide, we will explore the mechanics of the FLAMES game, dive into the implementation of the game in various programming languages, and discuss the practical applications and potential enhancements of this captivating relationship predictor.

Understanding the FLAMES Game Mechanics
The FLAMES game is played by following a simple set of steps:

  1. Take the Names: The first step is to obtain the names of the two individuals involved in the game.

  2. Remove Common Characters: The next step is to remove any common characters that appear in both names, along with their respective occurrences.

  3. Count the Remaining Characters: After removing the common characters, the total number of remaining characters in both names is counted.

  4. Apply the FLAMES Acronym: The FLAMES acronym (Friends, Lovers, Affectionate, Marriage, Enemies, Siblings) is then used to determine the relationship between the two individuals. The count of the remaining characters is used to navigate through the FLAMES letters, and the final letter that remains is the result.

To illustrate the process, let‘s consider an example:

Example: Implementing the FLAMES Game

Input:
Player 1: AJAY
Player 2: PRIYA

Step 1: Remove Common Characters
In the given names, the common characters are ‘A‘ and ‘Y‘, which occur once in each name.

After removing the common characters, the remaining characters are:
Player 1: J
Player 2: PRI

Step 2: Count the Remaining Characters
The total number of remaining characters is 5 (1 from Player 1 and 4 from Player 2).

Step 3: Apply the FLAMES Acronym
The count of the remaining characters (5) is used to navigate through the FLAMES letters in an anti-clockwise circular fashion. The letter that remains at the end of the process is the result.

FLAMES
Counting starts from F, and the 5th letter is E, which is removed.
FLAMS
Counting starts from S, and the 5th letter is M, which is removed.
FLASM
Counting starts from M, and the 5th letter is S, which is removed.
FLAM
Counting starts from M, and the 5th letter is L, which is removed.
FAA
Counting starts from A, and the 5th letter is A, which is removed.
F

Therefore, the relationship between AJAY and PRIYA is Friends.

Implementing the FLAMES Game in Programming

Now that we have a solid understanding of the FLAMES game mechanics, let‘s explore how to implement this game in various programming languages. We‘ll provide code snippets and explanations for Python, JavaScript, C++, and C#, showcasing the different approaches and highlighting the key steps involved.

Python Implementation

# Python3 program to implement FLAMES game
def flame(a, b):
    l, sc = 1, 0
    rc, fc = 0, 5
    f = "flames"
    f = [i for i in f]
    q = "".join(a)
    w = "".join(b)
    n = len(a)
    m = len(b)
    tc = n + m
    for i in range(n):
        c = a[i]
        for j in range(m):
            if (c == b[j]):
                a[i] = -1
                b[j] = -1
                sc = sc + 2
                break
    rc = tc - sc
    i = 0
    while (i):
        if (l == (rc)):
            for k in range(i, len(f)):
                f[k] = f[k + 1]
            f[k + 1] = ‘\x00‘
            fc = fc - 1
            i = i - 1
            l = 0
        if (i == fc):
            i = -1
        if (fc == 0):
            break
        l += 1
        i += 1
    # Print the results
    if (f[0] == ‘e‘):
        print(q, "is ENEMY to", w)
    elif (f[0] == ‘f‘):
        print(q, "is FRIEND to", w)
    elif (f[0] == ‘m‘):
        print(q, "is going to MARRY", w)
    elif (f[0] == ‘l‘):
        print(q, "is in LOVE with", w)
    elif (f[0] == ‘a‘):
        print(q, "has more AFFECTION on", w)
    else:
        print(q, "and", w, "are SISTERS/BROTHERS ")

# Driver code
a = "AJAY"
b = "PRIYA"
a = [i for i in a]
b = [j for j in b]
flame(a, b)

The Python implementation of the FLAMES game follows the same core logic as the game mechanics described earlier. It uses lists to represent the names and the FLAMES acronym, and it employs a series of loops and conditional statements to perform the character removal, counting, and result determination.

JavaScript Implementation

// JavaScript program to implement FLAMES game
function flame(a, b) {
    let i, j, k, l = 1, n, m, sc = 0, tc, rc = 0, fc = 5;
    let c;
    let f = "flames";
    let q = a.join("");
    let w = b.join("");
    n = a.length;
    m = b.length;
    tc = n + m;

    for (i = 0; i < n; i++) {
        c = a[i];
        for (j = 0; j < m; j++) {
            if (c == b[j]) {
                a[i] = -1;
                b[j] = -1;
                sc = sc + 2;
                break;
            }
        }
    }

    rc = tc - sc;

    for (i = 0;; i++) {
        if (l == (rc)) {
            for (k = i; k < f.length; k++) {
                f[k] = f[k + 1];
            }
            f[k + 1] = ‘\0‘;
            fc = fc - 1;
            i = i - 1;
            l = 0;
        }
        if (i == fc) {
            i = -1;
        }
        if (fc == 0) {
            break;
        }
        l++;
    }

    // Print the results
    if (f[0] == ‘e‘)
        document.write(q + " is ENEMY to " + w);
    else if (f[0] == ‘f‘)
        document.write(q + " is FRIEND to " + w);
    else if (f[0] == ‘m‘)
        document.write(q + " is going to MARRY " + w);
    else if (f[0] == ‘l‘)
        document.write(q + " is in LOVE with " + w);
    else if (f[0] == ‘a‘)
        document.write(q + " has more AFFECTION on " + w);
    else
        document.write(q + " and " + w + " are SISTERS/BROTHERS ");
}

// Driver code
let a = "AJAY".split("");
let b = "PRIYA".split("");
flame(a, b);

The JavaScript implementation follows a similar approach to the Python version, using arrays to represent the names and the FLAMES acronym. The key differences lie in the syntax and the way the output is displayed (using document.write() instead of print()).

C++ Implementation

// C++ program to implement FLAMES game
#include <bits/stdc++.h>
using namespace std;

// Function to find out the flames result
void flame(char* a, char* b) {
    int i, j, k, l = 1, n, m, sc = 0, tc, rc = 0, fc = 5;
    char q[25], w[25], c;
    char f[] = "flames";
    strcpy(q, a);
    strcpy(w, b);
    n = strlen(a);
    m = strlen(b);
    tc = n + m;
    for (i = 0; i < n; i++) {
        c = a[i];
        for (j = 0; j < m; j++) {
            if (c == b[j]) {
                a[i] = -1;
                b[j] = -1;
                sc = sc + 2;
                break;
            }
        }
    }
    rc = tc - sc;
    for (i = 0;; i++) {
        if (l == (rc)) {
            for (k = i; f[k] != ‘\0‘; k++) {
                f[k] = f[k + 1];
            }
            f[k + 1] = ‘\0‘;
            fc = fc - 1;
            i = i - 1;
            l = 0;
        }
        if (i == fc) {
            i = -1;
        }
        if (fc == 0) {
            break;
        }
        l++;
    }
    // Print the results
    if (f[0] == ‘e‘)
        cout << q << " is ENEMY to " << w;
    else if (f[0] == ‘f‘)
        cout << q << " is FRIEND to " << w;
    else if (f[0] == ‘m‘)
        cout << q << " is going to MARRY " << w;
    else if (f[0] == ‘l‘)
        cout << q << " is in LOVE with " << w;
    else if (f[0] == ‘a‘)
        cout << q << " has more AFFECTION on " << w;
    else
        cout << q << " and " << w << " are SISTERS/BROTHERS ";
}

// Driver code
int main() {
    char a[] = "AJAY";
    char b[] = "PRIYA";
    flame(a, b);
}

The C++ implementation utilizes character arrays to represent the names and the FLAMES acronym. It employs a similar logic to the previous examples, with the main differences being the syntax and the use of C-style strings instead of modern string objects.

C# Implementation


// C# program for the above approach
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

class HelloWorld {
    // Function to find out the flames result
    public static void flame(char[] a, char[] b) {
        int l = 1, sc = 0, rc = 0, fc = 5;
        string f = "flames";
        char[] flames = f.ToCharArray();
        string q = new string(a);
        string w = new string(b);
        int n = a.Length;
        int m = b.Length;
        int tc = n + m;
        for (int indx = 0; indx < n; indx++) {
            char c = a[indx];
            for (int j = 0; j < m; j++) {
                if (c == b[j]) {
                    a[indx] = b[j] = ‘-‘; // mark the matched characters with ‘-‘
                    sc += 2;
                    break;
                }
            }
        }
        rc = tc - sc;
        int i = 0;
        while (i >= 0) {
            if (l == rc) {
                for (int k = i; k < f.Length - 1; k++) {
                    flames[k] = flames[k + 1];
                }
                flames[flames.Length - 1] = ‘0‘;
                fc--;
                i--;
                l = 0;
            }
            if (i == fc) {
                i = -1;
            }
            if (fc == 0) {
                break;
            }
            l++;
            i++;
        }
        // Print the results
        char result = flames[0];
        switch (result) {
            case ‘e‘:
                Console.WriteLine(q + " is ENEMY to " + w);
                break;
            case ‘f‘:
                Console.WriteLine(q + " is FRIEND to " + w);
                break;
            case ‘m‘:
                Console.WriteLine(q + " is going to MARRY " + w);
                break;
            case ‘l‘:
                Console.WriteLine(q + " is in LOVE with " + w);
                break;
            case ‘a‘:
                Console

Did you like this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.