Commit graph

58 commits

Author SHA1 Message Date
Lucas CHOLLET 3f35ffb648 Userland: Prefer _string over _short_string
As `_string` can't fail anymore (since 3434412), there are no real
benefits to use the short variant in most cases.
2023-08-08 07:37:21 +02:00
Andreas Kling ddbe6bd7b4 Userland: Rename Core::Object to Core::EventReceiver
This is a more precise description of what this class actually does.
2023-08-06 20:39:51 +02:00
Lucas CHOLLET 8c34959b53 AK: Add the Input word to input-only buffered streams
This concerns both `BufferedSeekable` and `BufferedFile`.
2023-05-09 11:18:46 +02:00
Ben Wiederhake 449911c286 Chess: Slightly improve error propagation during startup 2023-05-07 14:04:55 +02:00
Ben Wiederhake 0fe29a48ad Chess: Avoid IODevice and DeprecatedFile 2023-05-07 14:04:55 +02:00
Tim Ledbetter ccab25e54e LibChess+Chess: Ensure no pawns have moved when invoking 50 move rule
The 50 and 75 move rules are no longer invoked if a pawn has advanced
in the last 50 or 75 moves respectively.
2023-05-05 16:56:18 +01:00
Tim Ledbetter 56dde3df54 LibChess+ChessEngine: Don't crash on error when reading UCI commands
ChessEngine and the chess GUI will no longer crash on error while
reading UCI commands. ChessEngine will print a message to the standard
output, while the GUI will ignore unknown commands. Both will print
the error to the debug log if the UCI_DEBUG flag is enabled.

Trailing and preceding whitespace is now stripped from commands before
they are parsed. Commands which are just whitespace no longer produce
errors.
2023-05-03 08:31:34 +01:00
Tim Ledbetter 25778d07e9 LibChess: Add optional ponder move to the BestMove command
The BestMove command can now include an optional ponder token, with
the move that the engine would like to ponder on.
2023-05-03 08:31:34 +01:00
Tim Ledbetter c885df98da LibChess: Flesh out InfoCommand implementation
UCI info commands can now be received and parsed. All info types from
the UCI specification are supported.

The info command is not currently used by our engine or GUI, but the GUI
can now receive an info command from a 3rd party engine without
complaining.
2023-05-03 08:31:34 +01:00
Tim Ledbetter 77f3e9710b LibChess: Use the correct command type for InfoCommand 2023-05-03 08:31:34 +01:00
Tim Ledbetter 18735960de LibChess: Add the ucinewgame command
This command is sent from the GUI to tell the engine that the next
position will be from a different game.
2023-04-28 05:55:51 +02:00
Andreas Kling 411d36719e LibCore: Simplify Core::Notifier by only allowing one event type
Not a single client of this API actually used the event mask feature to
listen for readability AND writability.

Let's simplify the API and have only one hook: on_activation.
2023-04-25 14:48:40 +02:00
Sam Atkins 20d517f1da LibChess: Remove use of DeprecatedString in Move::from_algebraic() 2023-04-24 20:58:35 +02:00
Sam Atkins a10cc37ef0 LibChess: Return ErrorOr<String> from to-algebraic/fen methods
Also, avoid creating temporary Strings for numbers, and stop appending
empty StringViews.
2023-04-24 20:58:35 +02:00
Sam Atkins 5f6dd87163 LibChess: Add and use Square::{file,rank}_char() methods
This saves us having to build and allocate a String, just to then use
one character of it.
2023-04-24 20:58:35 +02:00
Sam Atkins c73c697f94 LibChess: Make piece_for_char_promotion() more generally useful
- Rename to make it clear it's not just for promotion
- Understand 'p' for pawns
- Take a char parameter instead of StringView since it's always 1 char
2023-04-24 20:58:35 +02:00
Sam Atkins b111782f18 LibChess: Include pawns in FEN output
Previously, the initial position would look like this:

rnbqkbnr//8/8/8/8//RNBQKBNR w KQkq - 0 1

Now, we correctly give pawns the P/p character in FEN output:

rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1

Also, we only ever have 1 or 0 characters for a piece, so let's return
`Optional<char>` instead of `StringView` from `char_for_piece()`.
2023-04-24 20:58:35 +02:00
Sam Atkins 8529e660ca LibChess: Move inputs when creating chess Commands 2023-04-24 20:58:35 +02:00
Sam Atkins 29c41e953b LibChess: Convert Commands to use String and propagate errors 2023-04-24 20:58:35 +02:00
Sam Atkins 6576bbc098 LibChess: Return Commands by pointer from FooCommand::from_string()
This removes this slightly silly pattern:
`make<FooCommand>(FooCommand::from_string(s))`

Also, let's propagate OOM here, even if nobody reacts to it yet.
2023-04-24 20:58:35 +02:00
Sam Atkins b904435866 LibChess: Fix typo that always created DebugCommands as "on" 2023-04-24 20:58:35 +02:00
Tim Ledbetter 680d4e34d5 LibChess: Allow UCIEndpoint to handle unexpected disconnections 2023-04-20 09:59:18 +01:00
Tim Ledbetter 13dbc69c23 LibChess: Add the UCI quit command 2023-04-20 09:59:18 +01:00
Tim Schumacher d43a7eae54 LibCore: Rename File to DeprecatedFile
As usual, this removes many unused includes and moves used includes
further down the chain.
2023-02-13 00:50:07 +00:00
Lucas CHOLLET 597faaff5f LibChess: Factorize the returned StringView for a draw 2023-02-06 10:18:16 +00:00
Lucas CHOLLET 55c5639004 Chess+LibChess: Avoid using DeprecatedString whenever possible 2023-02-06 10:18:16 +00:00
Linus Groh 6e7459322d AK: Remove StringBuilder::build() in favor of to_deprecated_string()
Having an alias function that only wraps another one is silly, and
keeping the more obvious name should flush out more uses of deprecated
strings.
No behavior change.
2023-01-27 20:38:49 +00:00
Linus Groh 57dc179b1f Everywhere: Rename to_{string => deprecated_string}() where applicable
This will make it easier to support both string types at the same time
while we convert code, and tracking down remaining uses.

One big exception is Value::to_string() in LibJS, where the name is
dictated by the ToString AO.
2022-12-06 08:54:33 +01:00
Linus Groh 6e19ab2bbc AK+Everywhere: Rename String to DeprecatedString
We have a new, improved string type coming up in AK (OOM aware, no null
state), and while it's going to use UTF-8, the name UTF8String is a
mouthful - so let's free up the String name by renaming the existing
class.
Making the old one have an annoying name will hopefully also help with
quick adoption :^)
2022-12-06 08:54:33 +01:00
Tim Schumacher ce2f1b845f Everywhere: Mark dependencies of most targets as PRIVATE
Otherwise, we end up propagating those dependencies into targets that
link against that library, which creates unnecessary link-time
dependencies.

Also included are changes to readd now missing dependencies to tools
that actually need them.
2022-11-01 14:49:09 +00:00
Tim Schumacher 7834e26ddb Everywhere: Explicitly link all binaries against the LibC target
Even though the toolchain implicitly links against -lc, it does not know
where it should get LibC from except for the sysroot. In the case of
Clang this causes it to pick up the LibC stub instead, which might be
slightly outdated and feature missing symbols.

This is currently not an issue that manifests because we pass through
the dependency on LibC and other libraries by accident, which causes
CMake to link against the LibC target (instead of just the library),
and thus points the linker at the build output directory.

Since we are looking to fix that in the upcoming commits, let's make
sure that everything will still be able to find the proper LibC first.
2022-11-01 14:49:09 +00:00
Lucas CHOLLET 351fc0cce2 ChessEngine: Use reduced Board objects in MCTSTree
Monte-Carlo methods are known to intensively create nodes and in our
case each leaf of the tree stores a board. However, for this use case,
we don't need a full board object that also contains game information.

This patch adds a `clone_cleared()` method that return a clone without
game information and uses it when constructing the tree.
It allows the ChessEngine much more possibility before getting out of
memory.
2022-08-22 21:20:41 +02:00
sin-ack c8585b77d2 Everywhere: Replace single-char StringView op. arguments with chars
This prevents us from needing a sv suffix, and potentially reduces the
need to run generic code for a single character (as contains,
starts_with, ends_with etc. for a char will be just a length and
equality check).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack 3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack 6c46383e23 LibChess: Add convenience constructor for Chess::Square
It didn't feel right to add sv suffixes to 2-character strings, so I
added this convenience constructor.
2022-07-12 23:11:35 +02:00
Lenny Maiorani 35af46ee62 LibChess: Change UCI::Command::Type to enum class 2022-04-03 17:36:48 +01:00
Idan Horowitz 086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Simon Danner 90fc28152b Chess: On pgn import avoid losing piece promotion info
Fixes #13268
2022-03-26 18:30:12 +00:00
Lenny Maiorani 7030a9b496 Libraries: Use default constructors/destructors in LibChess
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-10 18:04:26 -08:00
Daniel Bertalan 4a81b33c07 Everywhere: Fix -Winconsistent-missing-override warnings from Clang
This option is already enabled when building Lagom, so let's enable it
for the main build too. We will no longer be surprised by Lagom Clang
CI builds failing while everything compiles locally.

Furthermore, the stronger `-Wsuggest-override` warning is enabled in
this commit, which enforces the use of the `override` keyword in all
classes, not just those which already have some methods marked as
`override`. This works with both GCC and Clang.
2021-12-11 13:14:15 -08:00
Andreas Kling 8b1108e485 Everywhere: Pass AK::StringView by value 2021-11-11 01:27:46 +01:00
Ben Wiederhake b3e9a4e603 Libraries: Fix visibility of Object-derivative constructors
Derivatives of Core::Object should be constructed through
ClassName::construct(), to avoid handling ref-counted objects with
refcount zero. Fixing the visibility means that misuses like this are
more difficult.
2021-11-02 22:56:53 +01:00
Ben Wiederhake 6b75a4dfc3 Everywhere: Mark overridden methods 'override'
This is good practice, and fixes some IDE warnings.
2021-11-02 22:56:53 +01:00
Martin Blicha add3a02ddd LibChess: Fix hashing of the chess board
The hash function should take the board by reference, not by value.
Also, the fact whether black can castle kingside or not was included
twice in the hash, unnecesarily.
2021-07-30 20:49:18 +02:00
Martin Blicha 0505a815f7 LibChess: Early check of legal move
One of the conditions for legal move is that the target square is not
occupied by a piece of the same color as the moving piece.

Instead of checking this for each piece separately at the end, we can
check this at the beginning and avoid more expensive checks.
2021-07-26 23:53:41 +02:00
Peter Elliott 34433f5dc4 LibChess: Compact the Defenitions of various chess related types
before:
sizeof(Board)=344, sizeof(Move)=36, sizeof(Piece)=4, sizeof(Square)=8

after:
sizeof(Board)=108, sizeof(Move)=9, sizeof(Piece)=1, sizeof(Square)=2
2021-06-22 23:09:42 +02:00
Peter Elliott 57bb4d1aec LibChess: Only save hash of board state for repetition checking
This more than doubles the number of nodes that MCTS can search for a
given time limit, and greatly reduces memory usage.
2021-06-22 23:09:42 +02:00
Josh Perry c46ab4fbb9
LibChess: Fixed PGN export bug (#7300)
In cases with ambiguous captures involving pawns (where multiple pieces
could have made the capture), we were exporting invalid syntax for
the move:

`1. e4 e5 2. Bb5 c6 3. Bxc6 ddxc6`

Move 3 should be `Bxc6 dxc6`, but we were duplicating the d on the pawn
move.
2021-05-20 08:32:19 +02:00
Jean-Baptiste Boric 0262a99a1f Chess: Fix signed/unsigned issues
Make everything signed so that we don't have to deal with silly casting
issues thoughout the Chess code. I am unsure if this affects the chess
AI negatively, it seems just as "intelligent" before and after this
change :^)
2021-05-17 18:14:05 +01:00
Gunnar Beutner 6cf59b6ae9 Everywhere: Turn #if *_DEBUG into dbgln_if/if constexpr 2021-05-01 21:25:06 +02:00