Josh Bruce Online

Double or Take - Social Experiment Game Documentation

Overview

“Double or Take” is a fascinating social experiment game that demonstrates human psychology around risk, greed, and altruism. Players face a simple choice: “Take” the current amount (resetting it to $1) or “Double” it for the next person. The game creates a digital prisoner’s dilemma where individual gain conflicts with collective benefit, while tracking all player actions in real-time through Firebase integration.

Technical Architecture

Core Technologies

File Structure

doubletake/
└── index.html    # Complete social experiment application

Dual Firebase Architecture

Primary Game Database

// Main game data storage
const firebaseConfig = {
    apiKey: "AIzaSyCGd5kWto7J4_0e594SpM5JFeXu2-B4GOE",
    authDomain: "joshbruceonline-general.firebaseapp.com",
    databaseURL: "https://joshbruceonline-general-default-rtdb.europe-west1.firebasedatabase.app",
    projectId: "joshbruceonline-general",
    storageBucket: "joshbruceonline-general.appspot.com",
    messagingSenderId: "348797894179",
    appId: "1:348797894179:web:9c8c8c8dcf8f0b06507b96"
};

const dbRef = firebase.database().ref("doubletake");
const mainValueRef = firebase.database().ref("mainValue");

Secondary Control Database

// Page control and redirect system
const switchFirebaseConfig = {
    apiKey: "AIzaSyCRPBjKJfKoLO52TqROpQ3I9X-nEL-0btE",
    databaseURL: "https://joshbruceonline-switch-default-rtdb.europe-west1.firebasedatabase.app/",
    authDomain: "joshbruceonline-switch.firebaseapp.com",
    projectId: "joshbruceonline-switch",
    storageBucket: "joshbruceonline-switch.appspot.com",
    messagingSenderId: "592073701037",
    appId: "1:592073701037:web:309eb7bed49885153a7824"
};

const switchApp = firebase.initializeApp(switchFirebaseConfig, 'switch');
const switchPageRef = switchDb.ref('doubletake');
const redirectLinkRef = switchDb.ref('redirectLink');

Game Mechanics and Psychology

Core Game Rules

// Simple but powerful game mechanics
function handleTake() {
    // Player takes current amount, resets to $1
    dbRef.push({
        action: "take",
        userName: userName,
        time: new Date().toLocaleTimeString(),
        date: new Date().toLocaleDateString(),
        value: 1                    // Always resets to $1
    });
    
    updateMainValue(1);
    currentValue = 1;               // Global reset
}

function handleDouble() {
    // Player doubles amount for next person
    dbRef.push({
        action: "double",
        userName: userName,
        time: new Date().toLocaleTimeString(),
        date: new Date().toLocaleDateString(),
        value: currentValue * 2     // Exponential growth
    });
    
    updateMainValue(currentValue);  // Maintain doubled amount
}

Psychological Dynamics

  1. Individual vs Collective Benefit: Take benefits self, Double benefits others
  2. Risk Assessment: Higher amounts create more temptation to take
  3. Social Pressure: Public attribution creates accountability
  4. Trust Building: Doubling demonstrates faith in others
  5. Exponential Stakes: Each double increases the next person’s dilemma

Real-time Synchronization System

Live Game State Updates

// Real-time listener for latest game action
dbRef.orderByKey().limitToLast(1).on("child_added", (snapshot) => {
    const data = snapshot.val();
    if (data) {
        currentValue = data.value || 1;
        lastAction = data.action || "";
        valueElement.textContent = `$${formatNumberWithCommas(currentValue)}`;
        updateSentence(lastAction, data.userName || "", data.time || "", data.date || "");
    }
});

Action History Tracking

// Comprehensive action logging
const actionRecord = {
    action: "take" | "double",      // Player choice
    userName: "PlayerName",         // Public attribution
    time: "HH:MM:SS AM/PM",        // Local time stamp
    date: "MM/DD/YYYY",            // Date stamp
    value: currentValue            // Amount at time of action
};

User Interface Design

Graffiti-Themed Aesthetic

body {
    font-family: "Helvetica", sans-serif;
    font-weight: bold;
    text-align: center;
    height: 100vh;
    margin: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background-image: url("https://graffitiwallpaper.com/pics/listings/373_portrait.jpg");
    background-size: cover;
    background-position: center;
}

Game Interface Layout

.container {
    background-color: rgba(128, 128, 128, 0.45);  /* Semi-transparent overlay */
    padding: 20px;
    border-radius: 10vh;                          /* Rounded design */
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 25vh;                                 /* Centered positioning */
}

/* Large circular action buttons */
.button {
    padding: 10px;
    font-size: 36px;
    cursor: pointer;
    border-radius: 50%;                           /* Perfect circles */
    width: 20vh;
    height: 20vh;
    margin: 40px;
}

#takeButton {
    background-color: #4CAF50;                    /* Green for "take" */
    color: white;
}

#doubleButton {
    background-color: #008CBA;                    /* Blue for "double" */
    color: white;
}

Value Display System

#valueContainer {
    font-size: 100px;                            /* Prominent money display */
    color: white;
    margin: 0px;
}

#sentence {
    background-color: rgba(128, 128, 128, 0.5);
    padding: 20px;
    border-radius: 5vh;
    margin-top: 10px;
    font-size: 36px;
    color: white;
}

Data Formatting and Display

Number Formatting System

// Professional number formatting with commas
function formatNumberWithCommas(number) {
    return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}

// Display with currency formatting
valueElement.textContent = `$${formatNumberWithCommas(currentValue)}`;

Dynamic Status Messages

function updateSentence(action, userName, time, date) {
    if (action === "take") {
        sentenceElement.textContent = `The amount was last taken by ${userName} at ${time} on ${date}.`;
    } else if (action === "double") {
        sentenceElement.textContent = `The amount was last doubled and given by ${userName} at ${time} on ${date}.`;
    }
}

Administrative Control System

Remote Page Control

// Listen for administrative page control
switchPageRef.on('value', (snapshot) => {
    const isPageActive = snapshot.val();
    if (isPageActive === false) {
        // Page has been remotely disabled
        redirectLinkRef.once('value', (snapshot) => {
            const redirectLink = snapshot.val();
            if (redirectLink) {
                window.location.href = redirectLink;    // Custom redirect
            } else {
                window.location.href = 'https://joshbruce.online/backrooms';  // Default fallback
            }
        });
    }
});

Administrative Features

  1. Remote Shutdown: Disable page access instantly
  2. Custom Redirects: Send users to specific destinations
  3. Fallback System: Default redirect if custom link unavailable
  4. Real-time Control: Immediate effect across all connected users

Social Experiment Design

Behavioral Economics Elements

  1. Public Attribution: Names recorded create social accountability
  2. Temporal Pressure: Real-time nature prevents extensive deliberation
  3. Exponential Stakes: Growing amounts increase decision difficulty
  4. Social Proof: Previous actions influence subsequent behavior
  5. Altruism vs Greed: Direct conflict between personal and collective benefit

Game Theory Applications

User Interaction Flow

Player Decision Process

  1. Arrival: Player sees current amount and last action
  2. Context: Understanding who last acted and when
  3. Decision: Choose between personal gain (Take) or collective benefit (Double)
  4. Attribution: Enter name for public record
  5. Consequence: Action immediately affects all subsequent players

Input Validation and Handling

function handleTake() {
    const userName = prompt("Enter your name:");
    if (userName) {                              // Basic validation
        // Record action with full attribution
        dbRef.push({...actionData});
        // Update display immediately
        valueElement.textContent = `$${formatNumberWithCommas(currentValue)}`;
    }
    // No action if user cancels prompt
}

Performance and Scalability

Real-time Database Efficiency

Memory Management

Security and Data Integrity

Input Validation

// Basic user input handling
const userName = prompt("Enter your name:");
if (userName) {
    // Proceed with action
}
// Implicit validation: empty/null names prevent action

Data Protection Considerations

Mathematical Progression Analysis

Exponential Growth Pattern

// Each "double" action follows: new_value = current_value × 2
// Progression examples:
// Start: $1
// After 1 double: $2
// After 2 doubles: $4
// After 3 doubles: $8
// After 10 doubles: $1,024
// After 20 doubles: $1,048,576
// After 30 doubles: $1,073,741,824 (over $1 billion)

Psychological Threshold Analysis

Browser Compatibility and Performance

Universal Compatibility

Mobile Optimization

/* Responsive design considerations */
.button {
    width: 20vh;                    /* Viewport-based sizing */
    height: 20vh;
    font-size: 36px;                /* Large touch targets */
}

#valueContainer {
    font-size: 100px;               /* Readable on small screens */
}

Future Enhancement Opportunities

Gameplay Features

  1. Game History Visualization: Chart showing value progression over time
  2. Player Statistics: Track individual player patterns and contributions
  3. Achievement System: Badges for various milestones and behaviors
  4. Time-based Events: Special rounds or multipliers
  5. Regional Variants: Different starting amounts or rules by location

Social Features

  1. Player Profiles: Optional accounts for tracking personal history
  2. Leaderboards: Most generous doublers vs biggest takers
  3. Social Sharing: Share interesting moments or high values
  4. Community Comments: Allow reactions to significant actions
  5. Team Challenges: Group-based cooperation experiments

Research Applications

  1. A/B Testing: Experiment with different UI designs or rules
  2. Behavioral Analysis: Study decision patterns and triggers
  3. Economic Research: Test various economic theories
  4. Psychology Studies: Examine social influence and peer pressure
  5. Game Theory Validation: Test theoretical predictions

Code Quality Assessment

Strengths

Areas for Enhancement

Conclusion

Double or Take represents a masterfully designed social experiment that transforms abstract game theory concepts into an engaging, real-time interactive experience. The application successfully creates a digital environment for studying human behavior around risk, trust, and social cooperation.

Technical Rating: 8.6/10

The application serves as both an entertaining game and a valuable tool for understanding human psychology, making complex economic and social concepts accessible through interactive gameplay.