Bot for drafts (part 1)

    After reading a post on the “Chess Bot” hubr , I wanted to make my own, but since I thought that chess would not work right away, I decided to practice drafts (so that the famous “Russian strip checkers” took more motivation).
    Unlike the above mentioned post, where there are only a few screenshots and a video, I will try to tell in more detail ...

    Probably more censorship would not allow more pictures.

    Description

    The goal is a program that instead of us will play (and preferably win) drafts against the computer (mode "Girls") or the player (mode "Duel"). In principle, you can even run two programs and let them play.
    To begin with, we will figure out what functional parts we will have (associations are given with a real player, in the spoiler - more specifically):
    • Eyes - to see the field what figures are on it;
      First, the idea was to implement field recognition based on OpenCV.
      Abandoned through resource requirements, and redundancy. Theoretically, it was possible to check several pixels and get a more or less true result.
      But, we stopped at the fact that we sort the field into separate squares
      and compare the "photographed" with these.
      After that, we transfer all the information to the brain.
    • Player (with Brains) - starts the game, looks at what moves are available (according to the rules);

      Here, on the basis of the information we see, we are looking for all available moves, sorting out all the checkers of our color and checking whether it is possible to make a move to the neighboring diagonally cells.
      If the next one is empty - you can make a move there, if it is occupied by the opponent’s piece, and the next one after it (diagonally) is free - then you can make a blow. After that, the possibility of this move is recorded in the list of available ones, and if you need to “hit”, then this move is marked as a priority.
    • Logic - makes decisions on choosing one move from the list of available;
      Now, the logic is implemented only to select first priority moves (where you must hit), and then from all the others. The choice is made arbitrarily. If you need to hit two or more, just call the method again. In the second part, I implement a more suitable algorithm. This was enough to demonstrate and to play in this version of the game.
    • Hands - in fact, to make a move.
      Here, probably, the simplest functionality. After the move has been selected, the cursor moves to the position where to get the piece from, click, move where to put it, and click again. If you needed to hit two, three or more, it is simply called several times.

    Result


    It turned out a program that can play checkers in almost any environment: an online game in a browser, a program like in the photo, or something else. Only before starting it will need to be taught how the figures and the field look. Much more needs to be added, for example:
    • The ability to process the ladies so that they can walk not only like regular checkers.
    • Add logic to choose the most successful moves.
    • Better handle the completion of the game.
    • Automatically learn where the field is and how it looks.

    Afterword

    The program was written with a friend (wait soon on the hub), for 3 hours. Please do not throw shoes, as they wrote after the working day and “just4fun”. Comments, comments, suggestions are welcome ...
    Tomorrow I will add a video of the game process.
    The program is written in Java (the first thing that came to hand and basically came up).
    Result on GitHub
    There is a game here, with Friday all!

    Also popular now: