Code Monkey home page Code Monkey logo

chesscore's Introduction

ChessCore

Chess Engine Implemented in .net core

Winboard/Xboard Compatible Chess Engine Written in C#/.NET Core. ChessCore has 2 modes XBoard Protocol which allows you to use Winboard Chess GUI http://hgm.nubati.net or Console mode which shows the current chess board using ASCII.

To Run type in: dotnet ChessCore.dll

About

This project is a product of a rather rash decision in mid 2008 to learn to program my own Chess Game, hence began my journey into the art of computer chess. The main goal of the original project was to learn about how computers play chess while producing a chess engine that is easily understood and well documented. I feel that goal has now been achieved. As the next step I decided to release the full source code for my chess engine under the MIT license to allow other developers to learn and contribute to further improve & extend my chess engine.

The documentation & tutorial on how to build a chess engine can be accessed in the following 2 formats:

PDF

http://www.adamberent.com/wp-content/uploads/2019/02/GuideToProgrammingChessEngine.pdf

Website

http://adamberent.com/home/chess/computer-chess/

chesscore's People

Contributors

3583bytes avatar jminor avatar jskubick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

chesscore's Issues

ChessCore 1.0.1 crashes after installation on Windows 64 bit SP1 and Arena 3.5.1 GUI

Hello 3583Bytes,
cf. Arena debug file:

2019-01-02 14:09:34,165 Arena 3.5.1
2019-01-02 14:09:34,165Font Arena Chess Figurine MISSING

2019-01-02 14:09:34,258**----------New game---2019-01-02 14:09:34,258 Mi -------------
2019-01-02 14:09:34,414**----------New game---2019-01-02 14:09:34,414 Mi -------------
2019-01-02 14:09:34,477screen: 1280x1024
2019-01-02 14:09:34,477
Monitors: 1
2019-01-02 14:09:34,477Monitor0: 1280x1024
2019-01-02 14:09:34,477
FormMonitor: 0
2019-01-02 14:09:34,477**DesktopRect: 0/0 .. 1280/1024
2019-01-02 14:10:36,0231------------------------Starting engine 1 ChessCore-------------------------
2019-01-02 14:10:36,0381Configured Engine 1 Type: WB2
2019-01-02 14:10:36,0381Engine 1 dir: C:\Users\NRL\Downloads\ChessCore-master\ChessCore-master\Releases\ChessCore1.0.1\ChessCore
2019-01-02 14:10:36,0381Engine 1 commandline: C:\Users\NRL\Downloads\ChessCore-master\ChessCore-master\Releases\ChessCore1.0.1\ChessCore\ChessCore.exe
2019-01-02 14:10:36,1471Engine 1 ProcessID: 2152
2019-01-02 14:10:36,1471Engine 1 Prio:32 ThreadPrio:0
2019-01-02 14:10:36,147<--1:Error:
2019-01-02 14:10:36,147<--1: An assembly specified in the application dependencies manifest (ChessCore.deps.json) was not found:
2019-01-02 14:10:36,147-->1:xboard
2019-01-02 14:10:36,147-->1:protover 2
2019-01-02 14:10:36,194<--1: package: 'NUnit', version: '3.11.0'
2019-01-02 14:10:36,210<--1: path: 'lib/netstandard2.0/nunit.framework.dll'
2019-01-02 14:10:37,006-->1:new
2019-01-02 14:10:37,006-->1:random
2019-01-02 14:10:37,006-->1:level 0 5 0
2019-01-02 14:10:37,006-->1:post
2019-01-02 14:10:37,006-->1:hard
2019-01-02 14:10:37,006-->1:easy
2019-01-02 14:11:36,5461
2019-01-02 14:11:36,5461Engine crashed, restarting...
2019-01-02 14:11:36,546-->1:?
2019-01-02 14:11:36,546-->1:force
2019-01-02 14:11:36,546-->1:quit
2019-01-02 14:11:36,9211------------------------Starting engine 1 ChessCore-------------------------
2019-01-02 14:11:36,9211Configured Engine 1 Type: WB2
2019-01-02 14:11:36,9211Engine 1 dir: C:\Users\NRL\Downloads\ChessCore-master\ChessCore-master\Releases\ChessCore1.0.1\ChessCore
2019-01-02 14:11:36,9211Engine 1 commandline: C:\Users\NRL\Downloads\ChessCore-master\ChessCore-master\Releases\ChessCore1.0.1\ChessCore\ChessCore.exe
2019-01-02 14:11:37,0301Engine 1 ProcessID: 3248
2019-01-02 14:11:37,0301Engine 1 Prio:32 ThreadPrio:0
2019-01-02 14:11:37,030<--1:Error:
2019-01-02 14:11:37,030<--1: An assembly specified in the application dependencies manifest (ChessCore.deps.json) was not found:
2019-01-02 14:11:37,030<--1: package: 'NUnit', version: '3.11.0'
2019-01-02 14:11:37,030-->1:xboard
2019-01-02 14:11:37,030-->1:protover 2
2019-01-02 14:11:37,077<--1: path: 'lib/netstandard2.0/nunit.framework.dll'
2019-01-02 14:11:37,859-->1:new
2019-01-02 14:11:37,859-->1:random
2019-01-02 14:11:37,859-->1:level 0 5 0
2019-01-02 14:11:37,859-->1:post
2019-01-02 14:11:37,859-->1:hard
2019-01-02 14:11:37,859-->1:easy
2019-01-02 14:11:38,7331Start calc, move no: 0
2019-01-02 14:11:38,733-->1:level 0 5 0
2019-01-02 14:11:38,733-->1:new
2019-01-02 14:11:38,733-->1:random
2019-01-02 14:11:38,733-->1:level 0 5 0
2019-01-02 14:11:38,733-->1:post
2019-01-02 14:11:38,733-->1:hard
2019-01-02 14:11:38,733-->1:easy
2019-01-02 14:11:38,733-->1:time 30000
2019-01-02 14:11:38,733-->1:otim 30000
2019-01-02 14:11:38,733-->1:white
2019-01-02 14:11:38,733-->1:go
2019-01-02 14:16:40,277-->1:?

Fixed bug that caused engine to prematurely declare checkmate against computer

If you're interested, I found and fixed a bug that caused the engine to prematurely declare checkmate against the computer (it's in my fork of ChessCore, specifically near the start of Engine.AiPonderMove()).

It took me a while to track down the problem, but basically the issue is that WhiteAttackBoard[] gets regenerated BEFORE the player's move gets executed, and only moves that were viable prior to that move are considered when AiPonderMove() goes to look for escape routes for a king in check.

Board to illustrate the problem:

r4r2/pppb1p1k/8/3p2Q1/q4P2/2np4/6PP/5RK1/ w - 0 27

then... move the white queen from G5 to H5.

Without my fix, the engine declares checkmate against black & the game is over.

With my fix, the engine correctly moves the computer's black king to G8, and proceeds to win a few moves later.

Since the performance cost of running PieceValidMoves.GenerateValidMoves(ChessBoard) is nontrivial on Android, I added an extra bit of logic so that it ALWAYS executes whenever either king is in check, but otherwise executes every turn ONLY at the two hardest difficulty levels, on the rationale that a premature declaration of checkmate is going to be noticed & confusing even to inexperienced players, but if the computer insidiously overlooks opportunities to save OTHER pieces, it's either a minor concern relative to performance, or a welcome way to make the engine slightly easier to play against.

Engine.GetValidMoves missing valid moves

First off, thank you for releasing the code. Very educational and useful.
Code should demonstrate the problem. which is caused by attack boards not being regenerated after every ply. Maybe this is your design intention. Not sure.

Consider the following method:
`

    static void TestValidMoves()
    {
        string startFen = "8/8/8/2k5/2P5/2N5/2N3Q1/3K4 w - - 0 1";
        ChessEngine.Engine.Engine e = new ChessEngine.Engine.Engine();
        e.InitiateBoard(startFen);

        // 1. Qg7
        e.MovePiece(54, 14);

        // returns "8/6Q1/8/2k5/2P5/2N5/2N5/3K4 w - - 2 2"
        // (I've modified 50 move logic to increment after every ply, so this may look different to you
        // but should not interfere with GetValidMoves)

        var fen1 = e.FEN;
        
        // c6
        byte square = 26;
        var pieceType = e.GetPieceTypeAt(square);
        var pieceColor = e.GetPieceColorAt(square);

        int c = square % 8;
        int r = square / 8;
        
        //  Returns { 1, 2 } { 3, 2 } and { 2, 4 } (squares 17, 19 and 34 ) square 18 not in list, even though valid.
        var vm = e.GetValidMoves((byte)c, (byte)r);
        
        // 1...Kc6  but engine allows move
        e.MovePiece(26, 18);

        // returns "8/6Q1/2k5/8/2P5/2N5/2N5/3K4 w - - 2 2"
        var fen2 = e.FEN;

        e.InitiateBoard(fen1);
        // now square 18 is included in list
        vm = e.GetValidMoves((byte)c, (byte)r);

    }

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.