This assignment involved implementing a tree-based game system with three distinct problems, completed over 2 weeks and 4 days. The project demonstrates advanced tree data structures, game state management, and minimax algorithm implementation.
Duration: 7 days
Focus: Core infrastructure and first problem solution
- Data Structures: Created all necessary tree structures and processing functions
- File I/O: Implemented input processing using
while(fgets(..)) - Problem 1: Successfully solved the first assignment problem
- Algorithm Development: Created a position counting/tracking algorithm using counters
- Memory Management: Extensive Valgrind errors within the
addfunction - Algorithm Design: 3-4 days spent developing the position tracking algorithm
- Debugging: Initial memory leak issues requiring careful pointer management
Duration: 7 days
Focus: Tree processing and complex memory management
- Core Function: Developed
Prelucrare_Arbore_TFfunction - Code Reuse: Utilized portions of the
addfunction from Week 1 - Data Storage: Implemented stack-based node storage system
- Segmentation Faults: Extensive SIGSEGV errors requiring GDB debugging
- Memory Management: Required triple pointer usage for proper memory deallocation
- Debugging Phase: 2-3 days dedicated to error resolution
- Valgrind: Primary tool for memory error detection
- GDB: Essential for segmentation fault debugging
- Memory Architecture: Triple pointer implementation for complex memory cleanup
- Stack Implementation: Used for saving tree nodes
- Node Information: Stack stores
GenericTree*data field information - Memory Strategy: Complex but necessary approach for proper cleanup
Duration: 4 days
Focus: Minimax algorithm and final integration
- Algorithm Research: Studied the minimax algorithm from Lab 06 Algorithms Programming
- Implementation: Straightforward max/min value calculation at each function call
- Integration: Main solution logic implemented in
mainfunction
- String Processing: Used
strtokfor parsing sequences like'(num1) (num2) [num3]..' - Tree Construction:
Tree_Buildvariable for dynamic tree building - Edge Formation:
Tree_Auxvariable handles:- Edge creation for round parentheses
- Numeric value storage for square brackets
- Memory Issues: Continued Valgrind problems requiring 3-4 days resolution
- Output Formatting: Implemented indentation using
\tcharacters - Resource Cleanup: Extensive variable management for memory deallocation
The system models game progression through a tree structure:
We start with O in the input file -> X moves.
X O X
O X X
O X O
^
/
X O X
O X X
O X -
^
/
- O X
O X X
O X -
\
v
- O X
O X X
O X X
Initial_State
/ \
v v
Stare1_Level1 Stare2_Level1
\
v
Stare1_Level2
character: Character to be placed ('X'/'O' or 'T'/'F')edge: Number of outgoing edges from the nodeval: Numeric value stored in the nodeNext_Node: Array of pointers to child nodesgametable: Game board stored aschar**
Initial_State->Next_Node[1]→Stare2_Level1Stare2_Level1->Next_Node[1]->gametable→ Access to game boardStare1_Level2->Next_Node[1]→NULL(leaf node)
- Algorithm: Counter-based position detection
- Implementation: Custom tracking system for game positions
- Challenges: Memory management in the add function
- Core Function:
Prelucrare_Arbore_TF - Architecture: Stack-based node management
- Innovation: Triple pointer memory management
- Integration: Reused components from Problem 1
- Algorithm: Standard minimax with max/min value calculation
- Parsing:
strtok-based sequence processing - Tree Building: Dynamic construction using
Tree_Build - Output: Properly indented tree representation
- Variables Used:
- String variables:
sir1,sir2,sir3 - Integer counters:
14,17,2, etc. - Cleanup variables:
Tree_Aux_Free1,Tree_Aux_Free2
- String variables:
- Approach: Systematic deallocation of all dynamic memory
- Challenge: Complex pointer relationships requiring careful cleanup
- Input Format: Mixed parentheses notation
'(num1) (num2) [num3]..' - Strategy:
strtok-based tokenization - Logic:
- Round parentheses → Edge formation
- Square brackets → Value storage
- Indentation: Tab character (
\t) for proper tree visualization - Structure: Hierarchical representation of game states
- Readability: Clear formatting for debugging and analysis
- Week 1: Initial memory management challenges
- Week 2: Complex segmentation fault resolution
- Final Days: Valgrind compliance and memory cleanup
- Valgrind: Essential for memory error detection
- GDB: Critical for runtime debugging
- Systematic Approach: Week-by-week problem solving
- Memory Management: Triple pointers are necessary for complex structures
- Algorithm Research: External resources valuable for implementation
- Incremental Development: Problem-by-problem approach managed complexity
- Data Structure Complexity: Multi-level tree with game state storage
- Memory Management: Advanced pointer manipulation required
- Algorithm Integration: Multiple algorithmic approaches combined
- Debugging Intensity: Significant time investment in error resolution
- Systematic Approach: Problem-by-problem implementation
- Thorough Debugging: Extensive use of debugging tools
- Research Integration: External algorithm study
- Memory Discipline: Careful resource management
- Game State Tree: Hierarchical game progression representation
- Memory Management: Advanced pointer-based cleanup system
- Minimax Engine: Optimal move calculation
- I/O Processing: File-based input parsing
- Output System: Formatted tree visualization
- Dynamic tree construction
- Game state tracking
- Optimal move calculation
- Memory-safe operations
- Formatted output generation
This implementation demonstrates sophisticated tree data structure usage, advanced memory management techniques, and algorithmic problem-solving. The multi-week development process provided extensive experience in debugging complex pointer-based systems and integrating multiple algorithmic approaches into a cohesive solution.