- TL;DR
- Compile
- Introduction
- Differences from Traditional Tic Tac Toe
- File Descriptions
- Challenges and Issues
- Technology Choices
- Code Structure
- Tools
Infinity Tic Tac Toe is an modified version of Tic Tac Toe that can be played by 2 or more players, where the board size determines the number of pieces each player has. For example, on a 3x3 board, each player has 3 pieces.
To compile your ts code into js code you will need to run the npm run watch
command in your terminal
Infinity Tic Tac Toe is a new take on the classic game, adding strategic depth and complexity. Players need to think ahead not just about placing their pieces but also about managing those already on the board. This version offers a more challenging and engaging experience compared to the traditional game.
Unlike traditional Tic Tac Toe, Infinity Tic Tac Toe offers:
- A variable number of pieces based on board size. For example, a 3x3 board allows for 3 pieces per player, while a 4x4 board allows for 4 pieces per player.
- Enhanced strategic planning and resource management. When all pieces are placed, players must move the piece that has been on the board the longest.
Handles the ai logic for the game, including move generation and strategy.
Handles click events, cursor changes and mouse movements within the game.
Contains environment variables that is used throughout the project.
Serves as the entry point of the application, initializing the game and rendering the main components.
Stores game settings and configurations, allowing customization of game parameters.
Provides utility functions that are used by multiple parts of the application to avoid code duplication.
Determines the winning conditions and checks if a player has won the game.
When I tried to develop the AI for my game, I initially attempted to utilize the minimax algorithm. However, it didn't work well with the unique rules of my version of Tic Tac Toe. After extensive research, I discovered heuristic algorithms, which proved to be highly effective in this scenario. This approach allowed the AI to handle the game's complexity and provide a challenging opponent.
TypeScript was chosen for its strong typing capabilities, which enhance code reliability and maintainability. By catching potential errors at compile-time rather than at runtime.
The JS Canvas API was chosen for rendering the game due to its performance and flexibility. The familiarity and ease of use from previous projects also contributed to its selection.
JSDocs provides comprehensive documentation, making the codebase easier to understand and contribute to.
Use PascalCase
for both classes and functions.
Use camelCase
for variables
Use comments to explain the "why" and not the "what". Comments should be used sparingly to avoid cluttering the code, focusing on explaining complex or non-obvious parts of the implementation.
Maintain up-to-date JSDocs for all functions and classes.
Install the Prettier extension so everyone can utilize the same code styling settings (.prettierrc). Prettier automatically formats the code according to predefined rules, ensuring that all developers follow the same style guidelines.
Place code in the "src" directory and place images, SVGs, and other assets in the "assets" directory. This separation ensures a well-structured project that is easy to navigate.
Avoid using magic numbers and strings directly in the code. Instead, define them as constants with meaningful names. This practice enhances code readability and makes it easier to update.
Strive for DRY (Don't Repeat Yourself) principles by abstracting reusable code into classes, functions, or variables.
- Code Spell Checker - Helps in identifying and correcting spelling errors in the code.
- Live Server - Provides a local development server with live reload capability.
- Prettier - Ensures consistent code formatting across the project.
- Auto Rename Tag - Automatically renames paired HTML tags.
- Better Comments - Enhances comment readability with color-coded annotations.
- Class Collapse - Allows for easy navigation and collapsing of class definitions.
- CSS Peek - Provides quick access to CSS definitions directly from HTML files.
- GitLens — Git supercharged - Enhances the Git capabilities within VSCode, making it easier to manage version control.