-
-
Notifications
You must be signed in to change notification settings - Fork 3
Options.md
This page explains how to configure MicroChess using the options_t class, defined in options.h and options.cpp. The options system allows users to customize gameplay settings, such as search depth, time limits, and output verbosity, while maintaining compatibility with Arduino’s resource constraints (less than 2K RAM).
The options_t class provides a centralized way to manage game settings, enabling users to adjust the chess engine’s behavior without modifying core logic. These settings control aspects like the strength of the AI, the speed of move selection, and the level of detail in outputs, making MicroChess adaptable to different use cases.
The options_t class, defined in options.h and implemented in options.cpp, stores configuration parameters and provides methods to access or modify them. Key attributes include:
- Search Depth: The number of plies (half-moves) the minimax algorithm explores.
- Time Limit: The maximum time (in milliseconds) allowed per move.
- Verbosity Level: Controls the amount of information printed to the Serial Monitor.
-
Opening Book Usage: Toggles the use of a predefined opening book (defined in
MicroChess.hasbook_t). - Randomization: Introduces slight randomness in move selection to avoid repetitive play.
- Constructor: Initializes default settings (e.g., depth=4, time_limit=1000ms).
-
setDepth(depth): Sets the search depth (e.g., 3-5 plies for Arduino compatibility). -
getDepth(): Returns the current search depth. -
setTimeLimit(ms): Sets the maximum time per move. -
setVerbosity(level): Adjusts output detail (e.g., minimal, normal, debug). -
enableOpeningBook(enable): Toggles the opening book on or off.
The following settings can be adjusted in options.h or via code modifications:
-
Search Depth:
- Default: 4 plies.
- Range: 1-6 (higher values increase strength but slow down the engine).
- Impact: Deeper searches improve move quality but require more memory and time.
-
Time Limit:
- Default: 1000ms (1 second) per move.
- Range: 100ms to 5000ms.
- Impact: Shorter limits speed up play but may reduce move quality.
-
Verbosity Level:
- Levels: Minimal (board and moves only), Normal (includes game state), Debug (detailedවිදිත්තුවිති: Verbosity Level:
- Default: Normal.
- Options:
MINIMAL,NORMAL,DEBUG. - Impact: Higher verbosity provides more debugging information (e.g., evaluation scores, nodes searched) but may slow down performance.
- Levels: Minimal (board and moves only), Normal (includes game state), Debug (detailedවිදිත්තුවිති: Verbosity Level:
-
Opening Book:
- Default: Enabled.
- Impact: Uses a predefined set of opening moves (
book_tinMicroChess.h) to start games with standard openings, improving early-game play.
-
Randomization:
- Default: Disabled.
- Impact: Adds slight score variations to equal-valued moves, creating varied gameplay.
To customize settings:
-
Edit
options.h:- Open
options.hin the Arduino IDE. - Modify default values (e.g.,
default_depth = 4,default_time_limit = 1000). - Example:
static const int default_depth = 3; // Change to 3 plies static const int default_time_limit = 500; // Change to 500ms
- Open
-
Recompile and Upload:
- Save changes and upload the sketch to the Arduino (see Installation).
-
Dynamic Changes (Advanced):
- Modify
MicroChess.inoto accept Serial Monitor commands for changing settings (e.g., "depth 5" to set depth to 5). - Requires adding parsing logic to handle input.
- Modify
The options_t class is designed for efficiency:
- Compact Storage: Uses minimal memory for settings (e.g., integers and booleans).
- Default Values: Chosen to balance performance and play quality on Arduino (e.g., 4-ply depth, 1-second limit).
- Configurability: Allows tuning without altering core logic, preserving code stability.
The options_t class interacts with:
-
Search Algorithm (
MicroChess.ino): Uses depth and time limit to control the minimax search. -
Visuals (
MicroChess.ino,led_strip.cpp): Verbosity level determines the detail of Serial Monitor output. -
Game Logic (
game.h/cpp): Opening book influences early move selection. -
Statistics (
stats.h/cpp): Tracks performance metrics affected by search settings (e.g., nodes searched).
To make the engine faster but less strategic:
- Set
default_depth = 2anddefault_time_limit = 500inoptions.h. - Upload the sketch.
- The engine will play quicker but may miss deeper tactics.
Options affect output:
- LED Strip: Unaffected by most settings, but verbosity may log related data (see MicroChessSmall.gif).
- Serial Console: Higher verbosity shows more details (e.g., evaluation scores) (see MicroChessConsole2.gif). More details are in the Visuals page.
- See Statistics for performance metrics influenced by options.
- Explore Search Algorithm for how depth and time limits are used.
- Check Code Structure for an overview of all files.
MicroChess | GitHub Repository | License: MIT | Contributing
© 2025 Trent M. Wyatt. All rights reserved.