zmxv / c4

Connect4 AI in obfuscated C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

c4 is a Connect-4 game I wrote in 2005.


Build instructions
==================
gcc -ansi -o c4 c4.c
./c4


Game rules
==========
  Connect Four (a.k.a Four-in-a-Line) is a two-player connection game
	played on a 7x6 board. Players take turns to drop a piece in one of
	the seven columns where the piece falls straight down, occupying the
	lowest empty cell in that column. The first player who connects at
	least four of one's own pieces in a line, either vertically,
	horizontally, or diagonally, wins. The game may also end in a draw
	if the board is full and neither player wins.


User interface
==============
  1 ~ 7 - column indices.
  .     - empty cell.
  X     - AI's piece. (AI always plays first.)
  O     - your piece.


Keys
====
  1 ~ 7 - drop a piece in the corresponding column if it's not full.
  0     - surrender.

  Invalid input will be discarded by the program.


Emoticons
=========
  :D    - You're probably going to lose in a few moves.
  :S    - You're probably going to win in a few moves.
  :)    - Neutral.


AI
==
  The core of the algorithm is traditional alpha-beta pruning plus a tiny
	opening book and a little bit of randomness in move selection. Based on
	some beta-testers' feedback, its strength was tweaked so that an average
	player would find it quite challenging, but not too hard.


Main obfuscation techniques
===========================
- Weave code logic into distracting three-letter words and acronyms
  which are a ternary extension of the "opaque predicate"[1][2][6] concept.
- Dismantle code locality information from the AI algorithm by splitting
  the recursive function, flattening its control flow graph[3][4][5], with a
  further twist of a seemingly incorrect run-time pointer permutation.
- Intertwine data heavily[1][3]; assign multiple meanings to most variables.


References
==========
[1] C. Collberg, C. Thomborson, and D. Low.  A taxonomy of obfuscating
    transformations.  Technical Report 148.  Department of Computer Science,
    University of Auckland, 1997.
[2] C. Collberg, C. Thomborson, and D. Low.  Manufacturing Cheap, Resilient,
    and Stealthy Opaque Constructs.  ACM SIGPLAN-SIGACT Symposium on
    Principles of Programming Languages, 1998.
[3] C. Collberg, C. Thomborson, and D. Low.  Breaking Abstractions and
    Unstructuring Data Structures.  International Conference on Computer
    Languages, 1998.
[4] C. Wang, J. Hill, J. Knight, and J. Davidson. Software Tamper Resistance:
    Obstructing Static Analysis of Programs. Technical Report CS-2000-12,
    University of Virginia, 2000.
[5] C. Wang.  A Security Architecture for Survivability Mechanisms.  PhD
    Dissertation. Department of Computer Science, University of Virginia, 2000
[6] C. Collberg and C. Thomborson.  Watermarking, Tamper-proofing, and
    Obfuscation - Tools for Software Protection.  IEEE Transactions on
    Software Engineering, 2002.

About

Connect4 AI in obfuscated C


Languages

Language:C 100.0%