Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Engine work #61

Open
wants to merge 119 commits into
base: master
Choose a base branch
from
Open

Engine work #61

wants to merge 119 commits into from

Conversation

rudzen
Copy link
Owner

@rudzen rudzen commented Mar 24, 2023

Stabilization towards better support for creating a chess engine with ChessLib

- Better use of MemoryMarshal
- Replaces some home-brew functionality with new dotnet 7 equivalent
- Fixed a few sonar warnings
- Added [SkipLocalsInit] where appropriate
- Updated dependencies:
 - Microsoft.Extensions.ObjectPool 6.0.10 -> 7.0.0
 - ZString 2.4.4 -> 2.5.0
 - DryIoc 5.2.2 -> 5.3.1
 - Microsoft.Extensions.Caching.Memory 6.0.1 -> 7.0.0
 - Microsoft.Extensions.Configuration 6.0.1 -> 7.0.0
 - Microsoft.Extensions.Configuration.EnvironmentVariables 6.0.1 -> 7.0.0
 - Microsoft.Extensions.Configuration.Json 6.0.0 -> 7.0.0
- Added some more helper functions to IPosition
- Fixed a UCI bug with options in regards to bool values
- Updated dependencies
- Added some static Create() factory methods to Score
- Updated SearchParameters slightly
- Minor update to HashTable<T>
- Clarified some methods in KpkBitBase
- Renamed some TT related stuff
- Fixed minor issue with Player ToString(....)
- Added Position.Set() tests for code - to be used with endgame setup
- ExtMove -> ValMove
- Added RootMove to act as easy use of list of moves
- IPieceValue -> IValues
- PieceValues -> DefaultPieceValues
- Move struct now readonly
- Added AddChessLib() IServiceCollection extension
- More types are now more friendly towards IoC in general
- Any other developmental changes can be observed through the unit tests
- Improved use of PolyglotBook, Blockage
- Added IOptions usage for TT
- Added PolyglotBook injectable factory with IOptions injected for base path
- Perft tests that takes a long time is now disabled in debug mode
- Perft time improved.. from ~3.2-3.4 seconds to ~3.0 seconds for start pos d=6
- Updated WebApi demo app
- Fixed a few nullable things
- Corrected a few var names
@rudzen rudzen self-assigned this Mar 25, 2023
@rudzen rudzen added the enhancement New feature or request label Mar 25, 2023
rudzen added 15 commits March 2, 2024 17:54
- added PieceType struct
- fixed a validation bug which would allow a fen to be detected as faulty
- renamed some "Castleling" stuff to "Castle"
- removed some redundant stuff for project files
- removed build timestamp from perft app
- updated appsettings.json for perft app
- Player -> Color (to eliminate confusing semantics)
- Added CPM
- Update PGN parsing
- Add PieceType type
- Add CastleSide type
- Fix a couple of variable namings
- Added a zobrist hash test
- Expanded HashKey a bit to be more flexible

public IEnumerable<string> GenerateMoves(MoveQuery parameters)
{
_logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, parameters.Types, parameters.Mode);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.

Copilot Autofix AI about 1 month ago

To fix the problem, we need to sanitize the parameters.Fen input before logging it. This can be done by removing any new line characters from the input to prevent log forging. We can use the String.Replace method to achieve this. The best way to fix the problem without changing existing functionality is to modify the logging statement to sanitize the parameters.Fen input.

Suggested changeset 1
src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs b/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs
--- a/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs
+++ b/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs
@@ -11,3 +11,4 @@
     {
-        _logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, parameters.Types, parameters.Mode);
+        var sanitizedFen = parameters.Fen.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
+        _logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", sanitizedFen, parameters.Types, parameters.Mode);
 
EOF
@@ -11,3 +11,4 @@
{
_logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, parameters.Types, parameters.Mode);
var sanitizedFen = parameters.Fen.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
_logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", sanitizedFen, parameters.Types, parameters.Mode);

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

public IEnumerable<string> GenerateMoves(MoveQuery parameters)
{
_logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, parameters.Types, parameters.Mode);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.

Copilot Autofix AI about 1 month ago

To fix the problem, we need to sanitize the user input before logging it. Specifically, we should remove any new line characters from the user input to prevent log forging. This can be done using the String.Replace method to replace new line characters with an empty string. We will apply this sanitization to the parameters.Types before it is logged.

Suggested changeset 1
src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs b/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs
--- a/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs
+++ b/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs
@@ -11,3 +11,4 @@
     {
-        _logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, parameters.Types, parameters.Mode);
+        var sanitizedTypes = parameters.Types.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
+        _logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, sanitizedTypes, parameters.Mode);
 
EOF
@@ -11,3 +11,4 @@
{
_logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, parameters.Types, parameters.Mode);
var sanitizedTypes = parameters.Types.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
_logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, sanitizedTypes, parameters.Mode);

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

public IEnumerable<string> GenerateMoves(MoveQuery parameters)
{
_logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, parameters.Types, parameters.Mode);

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.

Copilot Autofix AI about 1 month ago

To fix the problem, we need to sanitize the user input before logging it. Since the log entries are plain text, we should remove any new line characters from the user input to prevent log forging. This can be done using the String.Replace method to replace new line characters with an empty string.

We will modify the GenerateMoves method in the MoveGeneratorService class to sanitize the parameters.Fen, parameters.Types, and parameters.Mode before logging them.

Suggested changeset 1
src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs b/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs
--- a/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs
+++ b/src/web-api/Rudzoft.ChessLib.WebApi/Services/MoveGeneratorService.cs
@@ -11,3 +11,6 @@
     {
-        _logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, parameters.Types, parameters.Mode);
+        var sanitizedFen = parameters.Fen.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
+        var sanitizedTypes = parameters.Types.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
+        var sanitizedMode = parameters.Mode.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
+        _logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", sanitizedFen, sanitizedTypes, sanitizedMode);
 
EOF
@@ -11,3 +11,6 @@
{
_logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", parameters.Fen, parameters.Types, parameters.Mode);
var sanitizedFen = parameters.Fen.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
var sanitizedTypes = parameters.Types.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
var sanitizedMode = parameters.Mode.Replace(Environment.NewLine, "").Replace("\n", "").Replace("\r", "");
_logger.LogInformation("Generating moves. fen={Fen},type={Type},mode={Mode}", sanitizedFen, sanitizedTypes, sanitizedMode);

Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant