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

Add chess game #230

Merged
merged 20 commits into from
Aug 12, 2021
Merged

Add chess game #230

merged 20 commits into from
Aug 12, 2021

Conversation

vinc
Copy link
Owner

@vinc vinc commented Aug 7, 2021

I have been waiting for months for this one, running my chess engine inside my own OS!

This will provide a game to MOROS but also a way to benchmark performance in the OS.

See vinc/littlewing#81

@vinc
Copy link
Owner Author

vinc commented Aug 7, 2021

Starting a game of chess:
chess

And after a few moves:
chess2

@vinc
Copy link
Owner Author

vinc commented Aug 7, 2021

Next step: add a perft command to the cli and avoid panicking when parsing a wrong move.

@vinc
Copy link
Owner Author

vinc commented Aug 8, 2021

The perft command test the moves generation of a chess engine by counting the number of moves that can be done from a position at different depths. For example from the starting position there is 20 possible moves for the white pieces, then 400 replies from the black pieces and so on. It can be used as a benchmark if we count how long it takes to count all the pieces at a given depth.

This is what we get on the host system:

> perft
perft 1 -> 20 (0.00 s, 5.28e5 nps)
perft 2 -> 400 (0.00 s, 9.96e5 nps)
perft 3 -> 8902 (0.01 s, 1.38e6 nps)
perft 4 -> 197281 (0.04 s, 5.19e6 nps)
perft 5 -> 4865609 (0.86 s, 5.65e6 nps)
perft 6 -> 119060324 (21.18 s, 5.62e6 nps)

And this is in MOROS with QEMU:

> perft
perft 1 -> 20 (0.00 s, 6.67e3 nps)
perft 2 -> 400 (0.00 s, 2.00e5 nps)
perft 3 -> 8902 (0.05 s, 1.78e5 nps)
perft 4 -> 197281 (0.97 s, 2.04e5 nps)
perft 5 -> 4865609 (24.14 s, 2.02e5 nps)
^C

On VirtualBox it's faster, we get this:

perft 1 -> 20 (0.00 s, 2.00e4 nps)
perft 2 -> 400 (0.00 s, 4.00e5 nps)
perft 3 -> 8902 (0.00 s, 2.23e6 nps)
perft 4 -> 197281 (0.08 s, 2.38e6 nps)
perft 5 -> 4865609 (1.38 s, 3.53e6 nps)
perft 6 -> 119060324 (28.62 s, 4.16e6 nps)

Which is pretty good!

And finally on baremetal we get this:

perft 1 -> 20 (0.00 s, inf nps)
perft 2 -> 400 (0.00 s, inf nps)
perft 3 -> 8902 (0.00 s, 2.97e6 nps)
perft 4 -> 197281 (0.07 s, 2.98e6 nps)
perft 5 -> 4865609 (1.67 s, 2.91e6 nps)
perft 6 -> 119060324 (41.13 s, 2.89e6 nps)

Which is worse, probably because the kernel has some optimizations disabled at compile time and there's no hypervisor to add them back.

@vinc
Copy link
Owner Author

vinc commented Aug 10, 2021

The game experience is starting to look good enough for now, just need to implement what happen at the end of a game.

chess3

@vinc
Copy link
Owner Author

vinc commented Aug 11, 2021

With endgame support:
chess4

And the help command:
chess5

The first iteration is more or less done.

@vinc vinc marked this pull request as ready for review August 12, 2021 21:15
@vinc vinc merged commit e5a7b63 into trunk Aug 12, 2021
@vinc vinc deleted the feature/add-chess-game branch August 12, 2021 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant