• Stars
    star
    1,780
  • Rank 26,144 (Top 0.6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 1 year ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create your own tiny chess bot!

Chess Coding Challenge (C#)

Welcome to the chess coding challenge! This is a friendly competition in which your goal is to create a small chess bot (in C#) using the framework provided in this repository. Once submissions close, these bots will battle it out to discover which bot is best!

I will then create a video exploring the implementations of the best and most unique/interesting bots. I also plan to make a small game that features these most interesting/challenging entries, so that everyone can try playing against them.

Submissions are now closed

Thank you so much to everyone who participated -- in total, 636 chess bots were submitted. Also, a huge extra thanks to everyone who contributed code, reported bugs in the framework (sorry about those!), and gave their time to help others getting started with the intricacies of chess programming.

The results video is now out over here. And the tournament data can be found here.

Change Log

It has been necessary to make some bug fixes to the original project, and I've also been tempted (by some great suggestions from the community) into making a few non-breaking improvements/additions to the API. I realize that changes can be frustrating during a challenge though, and so will commit to freezing the API from August 1st.

  • V1.1 Fixed major bug affecting board.GetPiece() and PieceList functions. Added Board.CreateBoardFromFEN().
  • V1.11 UI changes: Added coordinate names to board UI and fixed human player input bug.
  • V1.12 Small fixes to board.IsDraw(): Fifty move counter is now updated properly during search, and insufficient material is now detected for lone bishops on the same square colour.
  • V1.13 Fixed issue with board.ZobristKey where value would sometimes be different after making and undoing a move. Added an alternative function for getting moves board.GetLegalMovesNonAlloc() (see docs for more info).
  • V1.14 A handful of additions to the Board API: board.IsInsufficientMaterial(), board.IsRepeatedPosition(), board.GameRepetitionHistory, board.FiftyMoveCounter, board.GameMoveHistory, board.GameStartFenString.
  • V1.15 Fixed incorrect move.CapturePieceType for en-passant moves and moves in board.GameMoveHistory. Added BitboardHelper.VisualizeBitboard() to help with debugging bitboards.
  • V1.16 Added timer.GameStartTimeMilliseconds, timer.OpponentMillisecondsRemaining, board.ForceSkipTurn().
  • V1.17 Added BitboardHelper.GetPieceAttacks() and optimized board.SquareIsAttackedByOponent(). Writing #DEBUG in a comment will now exclude code in that line from counting towards the token limit (for testing only of course).
  • V1.18 Added timer.IncrementMilliseconds (this will be 0 for the main tournament, but a small increment may be used in the final playoff games). Fixed a bug in the repetition handling, and optimized check/stalemate detection.
  • V1.19 Fixed potential out of bounds exception. Fixed bug in stalemate detection.
  • V1.20 Fixed (another) bug in the repetition detection.

[There will be no API changes after August 1]

How to Participate

  • Install an IDE such as Visual Studio.
  • Install .NET 6.0
  • Download this repository and open the Chess-Challenge project in your IDE.
  • Try building and running the project.
    • If a window with a chess board appears โ€” great!
    • If it doesn't work, take a look at the FAQ/troubleshooting section at the bottom of the page. You can also search the issues page to see if anyone is having a similar issue. If not, post about it there with any details such as error messages, operating system etc.
  • Open the MyBot.cs file (located in src/MyBot) and write some code!
    • You might want to take a look at the Documentation first, and the Rules too!
  • Build and run the program again to test your changes.
    • For testing, you have three options in the program:
      • You can play against the bot yourself (Human vs Bot)
      • The bot can play a match against itself (MyBot vs MyBot)
      • The bot can play a match against a simple example bot (MyBot vs EvilBot).
        You could also replace the EvilBot code with your own code, to test two different versions of your bot against one another.
  • Once you're happy with your chess bot, head over to the Submission Page to enter it into the competition.
    • You will be able to edit your entry up until the competition closes.

Rules

  • You may participate alone, or in a group of any size.
  • You may submit a maximum of two entries.
    • Please only submit a second entry if it is significantly different from your first bot (not just a minor tweak).
    • Note: you will need to log in with a second Google account if you want submit a second entry.
  • Only the following namespaces are allowed:
    • ChessChallenge.API
    • System
    • System.Numerics
    • System.Collections.Generic
    • System.Linq
      • You may not use the AsParallel() function
  • As implied by the allowed namespaces, you may not read data from a file or access the internet, nor may you create any new threads or tasks to run code in parallel/in the background.
  • You may not use the unsafe keyword.
  • You may not store data inside the name of a variable/function/class etc (to be extracted with nameof(), GetType().ToString(), Environment.StackTrace and so on). Thank you to #12 and #24.
  • If your bot makes an illegal move or runs out of time, it will lose the game.
    • Games are played with 1 minute per side by default (this can be changed in the settings class). The final tournament time control is TBD, so your bot should not assume a particular time control, and instead respect the amount of time left on the timer (given in the Think function).
  • Your bot may not use more than 256mb of memory for creating look-up tables (such as a transposition table).
  • If you have added a constructor to MyBot (for generating look up tables, etc.) it may not take longer than 5 seconds to complete.
  • All of your code/data must be contained within the MyBot.cs file.
    • Note: you may create additional scripts for testing/training your bot, but only the MyBot.cs file will be submitted, so it must be able to run without them.
    • You may not rename the MyBot struct or Think function contained in the MyBot.cs file.
    • The code in MyBot.cs may not exceed the bot brain capacity of 1024 (see below).

Bot Brain Capacity

There is a size limit on the code you create called the bot brain capacity. This is measured in โ€˜tokensโ€™ and may not exceed 1024. The number of tokens you have used so far is displayed on the bottom of the screen when running the program.

All names (variables, functions, etc.) are counted as a single token, regardless of length. This means that both lines of code: bool a = true; and bool myObscenelyLongVariableName = true; count the same. Additionally, the following things do not count towards the limit: white space, new lines, comments, access modifiers, commas, and semicolons.

FAQ and Troubleshooting

  • What is the format of the tournament?
    • The format may change depending on the number of entries, but the current plan is to run two tournaments, with the first being a large Swiss tournament in which all bots are able to receive a ranking. These games will be played from the standard starting position. Some percengtage of the top bots will then be promoted to a second knock-out tournament, which will use a selection of different opening positions. The exact number of rounds/games and time-control are TBD.
  • Unable to build/run the project from my IDE/Code editor
    • After downloading the project and installing .Net 6.0, open a terminal / command prompt window.
    • Navigate to the folder where Chess-Challenge.csproj is located using the cd command.
      • For example: cd C:\Users\MyName\Desktop\Chess-Challenge\Chess-Challenge
    • Now use the command: dotnet run
    • This should launch the project. If not, open an issue with any error messages and relevant info.
  • Running on Linux
  • Issues with illegal moves or errors when making/undoing a move
    • Make sure that you are making and undoing moves in the correct order, and that you don't forget to undo a move when exiting early from a function for example.
  • How to tell what colour MyBot is playing
    • You can look at board.IsWhiteToMove when the Think function is called
  • GetPiece() function is giving a null piece after making a move
    • Please make sure you are using the latest version of the project, there was a bug with this function in the original version
  • There is a community-run discord server over here.
  • There is also an unofficial live leaderboard created by a member of the community (source code available here).

More Repositories

1

Digital-Logic-Sim

C#
3,440
star
2

Geographical-Adventures

C#
3,384
star
3

Path-Creator

Path creation asset for Unity game development
C#
1,775
star
4

Chess-Coding-Adventure

A work-in-progress chess bot written in C#
C#
1,405
star
5

Slime-Simulation

C#
1,386
star
6

Solar-System

Simple solar system experiment
C#
1,144
star
7

Procedural-Landmass-Generation

Procedural Landmass Generation in Unity
C#
1,081
star
8

Ray-Marching

C#
1,046
star
9

Marching-Cubes

Coding Adventure
C#
1,020
star
10

Hydraulic-Erosion

C#
943
star
11

Clouds

Cloud rendering test
C#
845
star
12

Boids

C#
843
star
13

Portals

Portals in Unity
C#
777
star
14

Pathfinding

C#
663
star
15

2DPlatformer-Tutorial

A 2D Platform Controller in Unity
C#
651
star
16

Procedural-Planets

C#
594
star
17

Fluid-Sim

A simple 2D and 3D fluid simulation
C#
575
star
18

Ecosystem-2

C#
522
star
19

Procedural-Cave-Generation

C#
431
star
20

Neural-Network-Experiments

ShaderLab
428
star
21

Terraforming

C#
421
star
22

Ray-Tracing

C#
349
star
23

Field-of-View

C#
296
star
24

Create-a-Game-Source

Source code from my Create a Game tutorial series.
C#
267
star
25

Ant-Simulation

https://youtu.be/X-iSQQgOd1A
C#
203
star
26

Super-Chore-Man

C#
189
star
27

Cloth-and-IK-Test

Simple 2D cloth simulation test + FABRIK (inverse kinematics) test
C#
173
star
28

Curve-Editor

C#
171
star
29

Coding-Game

C#
170
star
30

Spherical-Gravity

C#
156
star
31

Sphere-Pathfinding

C#
116
star
32

Intro-to-Gamedev

Tutorial series for gamedev with C# in Unity
C#
115
star
33

Text-Rendering

C#
113
star
34

Godot-Marching-Cubes

GDScript
107
star
35

Tiny-Chess-Bot-Challenge-Results

Results of the Tiny Chess Bot Challenge
C#
100
star
36

Erosion-Demo

Demo of hydraulic erosion
C#
100
star
37

SebLague.github.io

JavaScript
94
star
38

Visual-Debug

C#
92
star
39

VidTools

C#
90
star
40

Poisson-Disc-Sampling

C#
87
star
41

Ear-Clipping-Triangulation

C#
79
star
42

Blender-to-Unity-Character-Creation

C#
77
star
43

Tiny-Chess-Godot

Play against a selection of increasingly difficult chess bots
C#
70
star
44

Blender-Shortcuts

Keyboard shortcut listing for some of my Blender tutorials
70
star
45

Spirit-Rover

Entry to xkcd game jam
C#
66
star
46

Runtime-CSharp-Test

C#
65
star
47

Pathfinding-2D

C#
64
star
48

Shape-Editor-Tool

C#
62
star
49

Reaction-Diffusion

C#
62
star
50

MN-Cellular-Automata

C#
59
star
51

Gamedev-Maths

Sourcecode for gamedev maths playlist on youtube
C#
59
star
52

Kinematic-Equation-Problems

C#
57
star
53

Create-a-Game-Project

GLSL
55
star
54

Neural-Network-python

Python
53
star
55

Gradient-Editor

C#
50
star
56

Monster-Console

C#
47
star
57

Object-Placement-with-Physics

C#
47
star
58

LD43-The-Resistance

Scripts for LD43 entry
C#
39
star
59

Object-Pooling

C#
38
star
60

Swordfish

Source for moviegamejam entry https://sebastian.itch.io/swordfish
C#
35
star
61

Camera-Shake

C#
34
star
62

Mate-In-One

JavaScript
30
star
63

MonoDevelop-Theme

30
star
64

Procedural-Landmass-Textures

Textures for the procedural landmass series
29
star
65

Misc-Project-Info

27
star
66

Dreamlo-Highscores

C#
26
star
67

Our-First-Game

25
star
68

First-person-controller

Basic first person controller using Character Controller
C#
25
star
69

This-Little-Piggy

C#
23
star
70

BASIC-Snake

23
star
71

Ludum-Dare-38

C#
23
star
72

Grid

C#
21
star
73

Mnist-data-numpy-format

20
star
74

Shader-Base

ShaderLab
19
star
75

Programming-Practice

C#
16
star
76

Images

16
star
77

Fourier-Transform

C#
14
star
78

Knight-Jump-Visualization

Visualize number of jumps to move knight to another square on chessboard.
C#
12
star
79

Circular-Gravity

C#
12
star
80

Chess-Pixi

Mate-in-one chess trainer
JavaScript
12
star
81

controller-challenge

C#
10
star
82

Mate-in-one-Generator

C#
9
star
83

Point-in-triangle-test-visualization

Testing github pages with this point in tri vizualization
JavaScript
7
star
84

Miscellaneous

GLSL
6
star
85

Calendar

Captures calendar image for each month in specified year.
C#
6
star