Skip to content

peetm/Penneys-Game-C

Repository files navigation

================================================================================
  PENNEY'S GAME ANALYZER FOR MICROSOFT WINDOWS
  Version 1.0
  (c) 1988 Style Programming
================================================================================

INTRODUCTION
------------

This program demonstrates Penney's Game, a fascinating coin-flipping game
that exhibits non-transitive properties. The program is written in the
classical style of Charles Petzold's "Programming Windows" (1988), using
pure Win32 API calls and the coding conventions of that era.


WHAT IS PENNEY'S GAME?
----------------------

Penney's Game is a two-player game where each player chooses a sequence of
three coin flips (such as HHT or THT). A coin is then flipped repeatedly
until one player's sequence appears - that player wins.

The remarkable property: For ANY pattern your opponent chooses, you can
always pick a counter-pattern that will beat it approximately 67% of the
time! This makes the game non-transitive - there is no "best" pattern.


FILES IN THIS PACKAGE
---------------------

PENNEYS.C       Main program source code
PENNEYS.H       Header file with constant definitions  
PENNEYS.RC      Resource script (menus and dialogs)
PENNEYS.DEF     Module definition file
PENNEYS.MAK     Makefile for Microsoft C 5.1
README.TXT      This file


BUILDING THE PROGRAM
--------------------

Requirements:
  - Microsoft C Compiler 5.1 (or later)
  - Microsoft Windows SDK 2.x (or later)
  - Microsoft MASM 5.1 (for the linker)

To build:
  1. Ensure CL.EXE, LINK.EXE, and RC.EXE are in your PATH
  2. Type: MAKE PENNEYS.MAK
  3. The executable PENNEYS.EXE will be created

Compiler switches used:
  -c        Compile only, no link
  -AS       Small memory model
  -Gsw      Remove stack probes, Windows prolog/epilog
  -Oas      Optimize for size
  -Zpe      Enable extensions


RUNNING THE PROGRAM
-------------------

Simply type: WIN PENNEYS

Or from the Windows Program Manager, use File/Run and enter PENNEYS.EXE


PROGRAM FEATURES
----------------

The program provides five analysis modes, accessible from the menu:

1. WAITING TIMES
   Shows how many coin flips it takes on average for each pattern to appear.
   Demonstrates that HTT appears faster (~8 flips) than HTH (~10 flips).

2. BEST COUNTERS
   For each pattern, finds which opponent pattern beats it most often.
   Shows that every pattern has a counter winning ~67% of games.

3. DOMINANCE MATRIX  
   Displays a complete 8x8 matrix of win percentages for all matchups.
   Each cell shows the percentage of times the row pattern beats the
   column pattern.

4. OPTIMAL STRATEGY
   Shows the winning strategy: always let your opponent choose first,
   then select the optimal counter-pattern to win ~67% of games.

5. PLAY GAME
   Interactive mode where you can select two patterns and simulate
   1000 games to see which pattern wins more often.


CONFIGURATION
-------------

Default simulation parameters are defined at the top of PENNEYS.C:

  DEFAULT_WAITING_TIME_SIMULATIONS  10000
  DEFAULT_MATCHUP_GAMES             10000  
  DEFAULT_MATRIX_GAMES              10000
  DEFAULT_STRATEGY_GAMES            5000
  DEFAULT_INTERACTIVE_GAMES         1000

You can modify these values and recompile to change the defaults.


PROGRAMMING NOTES
-----------------

This program follows the classical Windows programming style of 1988:

- Pure C with Win32 API (no C++ or MFC)
- Hungarian notation for variable names
- FAR pointers and _export keywords
- Manual resource management
- Dialog boxes for all interactions
- MakeProcInstance/FreeProcInstance for dialog procedures
- Fixed-pitch Courier font for results display
- Message-based architecture

Key Windows API functions used:

  RegisterClass()     - Register the window class
  CreateWindow()      - Create the main window
  GetMessage()        - Retrieve messages from queue
  DialogBox()         - Display modal dialog boxes
  SetDlgItemInt()     - Set dialog control values
  GetDlgItemInt()     - Retrieve dialog control values
  SetWindowText()     - Set text in edit controls
  SendMessage()       - Send messages to controls
  TextOut()           - Display text in window


MEMORY MODEL
------------

The program uses the SMALL memory model:
  - Code:  < 64K (all in one segment)
  - Data:  < 64K (all in one segment)
  - Stack: 8K
  - Heap:  4K

This is appropriate for a program of this size and complexity.


ALGORITHM NOTES
---------------

The simulation uses a simple random number generator (rand()) to simulate
coin flips. For production use in a gambling context, a cryptographically
secure random source would be required.

The pattern matching is done by comparing the last 3 characters of the
accumulated sequence against each player's chosen pattern.

The optimal counter-pattern lookup table is hardcoded based on the
mathematical solution to Penney's Game.


LIMITATIONS
-----------

- Maximum 100,000 simulations per analysis
- Maximum 50,000 games for dominance matrix (to prevent long waits)
- Results displayed in edit controls (limited scrollback)
- No graphical visualization of results
- No file save/load capability
- Single-threaded (UI blocks during simulation)


TECHNICAL SUPPORT
-----------------

This is a demonstration program written in historical 1988 style.
For questions about Windows programming, consult:

  - "Programming Windows" by Charles Petzold (1988)
  - Microsoft Windows SDK Reference Manuals
  - Microsoft Knowledge Base


VERSION HISTORY
---------------

Version 1.0 (1988)  - Initial release


================================================================================
End of README.TXT
================================================================================

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors