Comments (5)
Steps to reproduce:
Adding this line in the move loop of the default EvilBot
incorrectly increases the token count from 142 to 151.
Adding it to the MoveIsCheckmate
function instead correctly increases the token count to 153.
from chess-challenge.
This appears to have something to do with 'syntax trivia'.
If you add this code to line 57 inside the foreach
loop:
var a = token.ToString().Replace("\n", "\\n");
var b = token.TrailingTrivia.ToString().Replace("\n", "\\n");
Console.WriteLine($"'{a}' has trailing trivia '{b}'");
and then run it on this code:
using ChessChallenge.API;
public class MyBot : IChessBot
{
public Move Think(Board board, Timer timer)
{
bool tokenTest = Move.NullMove is { TargetSquare.Rank: 1 };
return default;
}
}
you can observe that somehow, it causes the line after the pattern match to count as "syntax trivia":
'}' has trailing trivia ''
';' has trailing trivia '\n return default;\n'
'}' has trailing trivia '\n}'
'' has trailing trivia ''
which https://learn.microsoft.com/en-us/dotnet/csharp/roslyn-sdk/work-with-syntax#syntax-trivia defines as
Syntax trivia represent the parts of the source text that are largely insignificant for normal understanding of the code, such as white space, comments, and preprocessor directives.
In this case, the return statement is very much significant to understanding the code, and it isn't whitespace, a comment, or a preprocessor directive, so I'm inclined to believe this is a bug in the parser. This should be somewhat mitigated by adding descendIntoTrivia: true
to the DescendantTokens
call, which should make it visit trivia tokens.
from chess-challenge.
I think it is a bug in the parser too.
The returned tokens also differ in other places that should not have changed.
See the images below; Left original source, mid in the move loop, right in the MoveIsCheckmate
You can see tokens are missing in mid compared to the original.
Here you can see tokens are inserted and missing in right compared to the original.
from chess-challenge.
Thanks for reporting, that's really strange! I will investigate (and will look into descendintotrivia as a potential solution @Algorhythm-sxv)
from chess-challenge.
In case anyone is still wondering, it turns out the issue is because I accidentally used an outdated version of Roslyn. Updating to 4.7 fixes the problem. Sorry about the blunder!
from chess-challenge.
Related Issues (20)
- Canβt open board HOT 5
- board.cs has an error. HOT 4
- Significant performance boost to IsDraw method HOT 3
- Copying boards/overriding fen strings HOT 2
- Each character in string counts as token HOT 3
- Please select a valid startup item
- Black pawn appearing on h4
- Build errors when trying to run MyBot without changing anything from when downloading it. HOT 1
- Bot Brain Capacity change. HOT 2
- SquareIsAttackedByOpponent is returning true, although the square isn't attacked HOT 1
- Game over every time, even when MyBot won the round. HOT 6
- Final knockout tournament clarification HOT 2
- HOw to set custom Chess position to test bot HOT 2
- Run codes from strings in C# HOT 8
- Submission Deadline Clarification HOT 1
- bot submission size limit issue HOT 1
- Is there any update on competition? HOT 14
- PGN parser
- Segmentation fault (core dumped) when launching Chess-Challenge v1.20 on Ubuntu 20.04 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chess-challenge.