Giter Site home page Giter Site logo

zhukovdm / congo Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 833 KB

๐Ÿฆ Multiplatform engine for playing a chess-like strategy game

License: MIT License

C# 100.00%
strategy-game artificial-intelligence netherlands chess-variant negamax board-game wpf game-server grpc-dotnet

congo's Introduction

Congo

The project implements a platform for playing the board game Congo locally or over the network.

Documentation

Read Installation Instruction to find out how to install the application on different operating systems (currently Windows and Linux are supported) or build and run it from source code.

See detailed User's Manual for rules, gameplay and user interface, both graphical and terminal-based.

Consult Programmer's Guide to learn more about application architecture, algorithms and data structures used throughout the Congo project.

Credits

Special thanks to Demian Freeling for inventing the game and to Ihardlythinkso for drawings published on Wikipedia.

congo's People

Contributors

zhukovdm avatar

Stargazers

 avatar

Watchers

 avatar  avatar

congo's Issues

Move generation shall not be interrupted

Lion might not be properly found.

if (piece.IsMonkey()) {
    var monkey = (Monkey)piece;
 
    allMoves.AddRange(monkey.ContinueJump(color, board, e.Current));
    break; // there is only one monkey
}

show and exit commands

Good to have. The current player could easily get full overview at any time or exit if got sick of the command line.

Implement simplified FEN parser

Might be needed soon for network version.

8x [row format] 1x [color format] 1x [monkey format]
row format      -> 1p1Pp2p
color format    -> white | black | -
monkey format   -> m | -

Wrong user move is not properly reported

 > show moves

 (a2,a3) (a2,b3) (b2,a3) (b2,b3) (b2,c3)
 (c2,b3) (c2,c3) (c2,d3) (d2,c3) (d2,d3)
 (d2,e3) (e2,d3) (e2,e3) (e2,f3) (f2,e3)
 (f2,f3) (f2,g3) (g2,f3) (g2,g3) (a1,a3)
 (a1,c3) (c1,c3) (e1,e3) (g1,f3)

 > move d3 g4

 > 

Create doxygen documentation

  • Add meaningful comments.
  • Add Doxyfile for doc generation.
  • Remove file assets/api.txt once generated doc is OK.

Isolate instances of Algorithm

Currently, Algorithm.cs implement

public static class Algorithm

Algorithm should be synchronized with the user interface via Disable and Enable methods. The application logic becomes less transparent with a space for bugs. The solution will be to instantiate proper algorithm each time. If cancellation comes first, there will be no GUI update.

Accept/visit pattern for getting user input

The goal is to eliminate branching.

do {
    var command = userInterface.GetUserCommand();
    if (command is AdviseCommand) {
        var advice = (AdviseCommand)command;
        move = Algorithm.GetMove(this, advice.Heuristic);
        userInterface.ReportAdvice(move, advice.Heuristic);
        move = null;
    } else if (command is ExitCommand) {
        throw new Exception(" The game has suddenly ended.");
    } else if (command is MoveCommand) {
        var unpack = (MoveCommand)command;
        move = new CongoMove(unpack.Fr, unpack.To);
        if (!isValid(move)) move = null;
    } else if (command is ShowCommand) {
        userInterface.Show(board);
    } else {
        /* do nothing */
    }
} while (move == null);

Method player.GetValidMove() is not general enough

Consider the game main loop from Program.cs.

while (!game.HasEnded()) {
    move = game.ActivePlayer.GetValidMove(ui, game); // <--- this row
    game = game.Transition(move);
    ui.ShowBoard(game);
    game = ui.WaitResponse(game);
}

Currently, two scenarios are possible.

  • The user plays via command-line interface.
  • The user is an artificial intelligence, decides moves based on an algorithm.

Due to a nature of the terminal-based applications, obtaining next move is a blocking operation. The player opposite to current player should wait until the move is decided and performed.

In the future version of game engine, we implement possibility to play locally and via network, play with terminal-based and WPF-based GUI. Waiting for the move can no longer be blocking. We want GUI to be responding, but with limited capabilities (e.g. user cannot make move before the opponent).

The approach of getting next move shall be redesigned.

Failing reset of ai/ai game

Reset sets game to null. We should follow the strategy:

  • signalize stop to the algorithm run,
  • wait until worker signalizes it is done,
  • remove game and stop timer.

The stopping event ends here. In some next event worker finishes its post processing on null game.

Things are getting messy on waiting and interrupting worker threads. Probably, we should reconsider how to access elements in sync.

Unify interface for auto-generated gRPC `Client` routines

Both terminal-based and graphical interfaces instantiate gRPC interface via referencing congo.proto file. Code is auto-generated and can be used within only one project. This implies that different implementations of wrappers for gRPC calls exist in both Congo.CLI and Congo.GUI projects. Wrappers are easier to work with and hide implementation details.

private CongoGame getLatestGame()
=> CongoFen.FromFen(client.GetLatestFen(new GetLatestFenRequest() { GameId = gameId }).Fen);

public static CongoGame GetLatestGame(CongoGrpc.CongoGrpcClient client, long gameId)
=> CongoFen.FromFen(getLatestFen(client, gameId));

The goal of this issue is to follow DRY principle. My previous attempts failed.

Fen format contains player information

Fen should describe only current board / position and should not describe players in any way. Players shall be a part of user interface. Fen for standard board would look like:

gmelecz/ppppppp/7/7/7/PPPPPPP/GMELECZ/w/-1

Rewrite data access layer

Old data access layer uses SQLite with very weird and unsafe approach to access data. New implementation should use Entity Framework Core and store data in a PostgreSQL instance running on the background.

It should be noted, that EF Core is an advanced dependency and the initial intent of the application was to implement a simple game engine and store data somehow.

Board.Without() does not reset piece bank

Might be a problem later (overload on board == and != static methods).

public CongoBoard Without(int position) {
    var newOccupied = occupied;
    for (int i = 0; i < 2; i++) {
        newOccupied = newOccupied.SetItem(i, setBitToValue(occupied[i], position, false));
    }
    return new CongoBoard(newOccupied, pieces);
}

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.