A minimal console-based Connect-Four implementation used for course exercises.
- Patrick Casseus
- Dante Hurr
- Jaksh Patel
Board.java— board state and win/draw logicGame.java— game loop and user command handlingHint.java— simple two-ply hint engine classifying safe/unsafe movesMain.java— application entry pointMove.java— immutable move record (row/col/token)MoveStack.java— LIFO stack used for undo functionalityMyLinkedList.java— tiny linked list used by the hint enginePlayer.java— player descriptor (name and token)TurnQueue.java— circular queue to manage player turnsAIPlayer.java— abstract superclass for AI implementations (easy, medium, hard)AVLTree.java— self-balancing tree storing tournament standings sorted by wins and nameEasyAI.java— basic AI that selects random valid columnsHardAI.java— advanced AI using recursive minimax search with scoringMatch.java— stores metadata and outcome for a single tournament matchMediumAI.java— intermediate AI that blocks wins, favors center, avoids trapsPlayerManager.java— handles login, registration, profile lookup, and data persistencePlayerProfile.java— persistent stats for a registered player, including rolling historyTournament.java— manages round-robin scheduling, match queue, and match executionTournamentEntry.java— wrapper for a player's tournament stats (wins, losses, name)TournamentStats.java— node wrapper used by AVLTree for sorting and output
- Java 11+ (javac and java on PATH)
- macOS / Linux / Windows terminal
From the project directory (where the .java files live) run:
javac connectfour/*.javaThis will produce .class files next to each source file.
Start the game:
java connectfour.MainThe game runs interactively in the terminal. Prompts are displayed for the current player.
Available commands (type at the prompt):
<column number>— type a number between 0 and 6 to drop your tokenundo— undo the last move (restores the board and the turn order)hint— compute and print a simple hint: recommended, safe and unsafe movesboard— reprint the current board snapshotrestart— clear the board and start a new game (player order is preserved)help— show the help menuquit— exit the game
Newer Commands (type at the prompt):
register <name>— create a new player accountlogin <name>— login as an existing playerlogout— logout of the current sessionwhoami— show the current logged-in userprofile <name>— show stats and history for a userleaderboard top N— show top N players by win countgame start human [X O]— start human vs humangame start ai <level>— start human vs AI (easy, med, hard)tournament create <id> <p1,p2,...>— create a tournamenttournament start <id>— schedule all matchesnext— play the next match in the queue (AI vs AI)tournament standings <id>— show AVL-based standings
- Two players are configured by default: Player 1 uses
X, Player 2 usesO. - The board default is 6 rows x 7 columns and connect-4 win condition.
- The hint engine is a shallow two-ply simulation that detects immediate opponent wins after your candidate move (it does not perform deep search).
- The undo feature reverses the last move(s); in AI games, both the player and AI moves are undone.
- The hint engine avoids unsafe moves that allow immediate losses on the opponent’s next turn.
AI difficulty levels include:
- Easy — selects random valid columns.
- Medium — blocks wins, prefers center, avoids traps.
- Hard — uses recursive minimax search with a static evaluation function.
- Player accounts persist stats across sessions, including total and AI-specific win/draw/loss counts.
- Each player profile keeps a rolling history of their last 10 game outcomes.
- Tournaments simulate round-robin play between players using AI.
- Tournament standings are stored in an AVL tree and ranked by win count (descending), then player name (ascending).