Skip to content

Add Command-Line Tic-Tac-Toe Game with Two-Player Support#14

Open
tomcat323 wants to merge 1 commit intomainfrom
tic-tac-toe-game-20251218-205219
Open

Add Command-Line Tic-Tac-Toe Game with Two-Player Support#14
tomcat323 wants to merge 1 commit intomainfrom
tic-tac-toe-game-20251218-205219

Conversation

@tomcat323
Copy link

Description

This PR implements a fully functional command-line tic-tac-toe game that allows two players to play against each other. The game provides an interactive experience with clear instructions and proper game state management.

Features Implemented

Core Game Mechanics

  • Two-Player Support: Players take turns as X and O
  • 3x3 Grid Display: Visual board representation that updates after each move
  • Move Input: Players specify positions (1-9) to place their marks
  • Move Validation: Ensures moves are only made to empty positions
  • Win Detection: Checks for three-in-a-row horizontally, vertically, and diagonally
  • Draw Detection: Identifies when the board is full with no winner

User Experience

  • Clear instructions for players at game start
  • Visual board updates after each move
  • Input validation with error messages for invalid moves
  • Game result announcement (winner or draw)
  • Command-line executable script

Technical Details

Implementation

  • Language: Python
  • File: tic_tac_toe.py
  • Executable: Script is marked as executable for direct command-line use
  • Board Representation: Uses a list-based data structure for efficient game state management
  • Win Patterns: Implements all 8 possible winning combinations (3 horizontal, 3 vertical, 2 diagonal)

Additional Changes

  • Added .gitignore file to exclude Python build artifacts and IDE/OS specific files

How to Use

Run the game from the command line:

python tic_tac_toe.py

Or if executable permissions are set:

./tic_tac_toe.py

Players will be prompted to enter positions (1-9) corresponding to the board layout:

1 | 2 | 3
---------
4 | 5 | 6
---------
7 | 8 | 9

Testing Considerations

The implementation includes:

  • Input validation for move positions
  • Boundary checking for board positions
  • Win condition verification for all possible winning patterns
  • Draw condition detection when board is full

Requirements Met

✅ Command-line tic-tac-toe game script created
✅ Two-player gameplay support
✅ 3x3 grid display with current board state
✅ Turn-based move input system
✅ Move validation for empty positions only
✅ Win condition checking (horizontal, vertical, diagonal)
✅ Draw condition detection
✅ Game result display
✅ Clear player instructions
✅ Command-line executable

Co-authored-by: Tom Zu <138054255+tomcat323@users.noreply.github.com>
@ghostyappzeta ghostyappzeta bot mentioned this pull request Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants