Checkers Console App
Basic AI development
using System;
using System.Collections.Generic;

namespace ConsoleApp5
{
    /// <summary>
    /// This is a checkers game Player VS AI. 
    /// </summary>
    class Program
    {
        public static int Line = 0;           // Vertical numbers on the board
        public static string Logic;           // Main Logic for console interactions
        public static bool Turn = true;       // Does it Player or AI turn

        // Collect information about all existing and allowed to play into the game coordinats
        class Coordinate
        {
            public int SetLeft;               // Coordinats for Console.SetCursorPosition
            public int SetTop;                // Coordinats for Console.SetCursorPosition
            public string NameLetter;         // Store Name of the colomn
            public string Name;               // Name as a comand
            

            public void Print()
            {
                Console.WriteLine($"Coordinate {NameLetter}{SetTop} is set ({SetLeft}, {SetTop})");
            }
        }

        // Store Player Pawns information
        class Player
        {            
            public string Coordinates;        // Coordinates as a comand
            public bool King;                 // Does Pawn can go back
        }

        static void Main()
        {
            // Coordinates data to start the game
            List<Coordinate> Coords = new List<Coordinate>()
            { 
                new Coordinate() { Name = "A2", SetLeft = 2, SetTop = 2, NameLetter = "A" },
                new Coordinate() { Name = "B1", SetLeft = 4, SetTop = 1, NameLetter = "B" },
                new Coordinate() { Name = "C2", SetLeft = 6, SetTop = 2, NameLetter = "C" },
                new Coordinate() { Name = "D1", SetLeft = 8, SetTop = 1, NameLetter = "D" },
                new Coordinate() { Name = "E2", SetLeft = 10, SetTop = 2, NameLetter = "E" },
                new Coordinate() { Name = "F1", SetLeft = 12, SetTop = 1, NameLetter = "F" },
                new Coordinate() { Name = "G2", SetLeft = 14, SetTop = 2, NameLetter = "G" },
                new Coordinate() { Name = "H1", SetLeft = 16, SetTop = 1, NameLetter = "H" },
                new Coordinate() { Name = "A4", SetLeft = 2, SetTop = 4, NameLetter = "A" },
                new Coordinate() { Name = "B3", SetLeft = 4, SetTop = 3, NameLetter = "B" },
                new Coordinate() { Name = "C4", SetLeft = 6, SetTop = 4, NameLetter = "C" },
                new Coordinate() { Name = "D3", SetLeft = 8, SetTop = 3, NameLetter = "D" },
                new Coordinate() { Name = "E4", SetLeft = 10, SetTop = 4, NameLetter = "E" },
                new Coordinate() { Name = "F3", SetLeft = 12, SetTop = 3, NameLetter = "F" },
                new Coordinate() { Name = "G4", SetLeft = 14, SetTop = 4, NameLetter = "G" },
                new Coordinate() { Name = "H3", SetLeft = 16, SetTop = 3, NameLetter = "H" },
                new Coordinate() { Name = "A6", SetLeft = 2, SetTop = 6, NameLetter = "A" },
                new Coordinate() { Name = "B5", SetLeft = 4, SetTop = 5, NameLetter = "B" },
                new Coordinate() { Name = "C6", SetLeft = 6, SetTop = 6, NameLetter = "C" },
                new Coordinate() { Name = "D5", SetLeft = 8, SetTop = 5, NameLetter = "D" },
                new Coordinate() { Name = "E6", SetLeft = 10, SetTop = 6, NameLetter = "E" },
                new Coordinate() { Name = "F5", SetLeft = 12, SetTop = 5, NameLetter = "F" },
                new Coordinate() { Name = "G6", SetLeft = 14, SetTop = 6, NameLetter = "G" },
                new Coordinate() { Name = "H5", SetLeft = 16, SetTop = 5, NameLetter = "H" },
                new Coordinate() { Name = "A8", SetLeft = 2, SetTop = 8, NameLetter = "A" },
                new Coordinate() { Name = "B7", SetLeft = 4, SetTop = 7, NameLetter = "B" },
                new Coordinate() { Name = "C8", SetLeft = 6, SetTop = 8, NameLetter = "C" },
                new Coordinate() { Name = "D7", SetLeft = 8, SetTop = 7, NameLetter = "D" },
                new Coordinate() { Name = "E8", SetLeft = 10, SetTop = 8, NameLetter = "E" },
                new Coordinate() { Name = "F7", SetLeft = 12, SetTop = 7, NameLetter = "F" },
                new Coordinate() { Name = "G8", SetLeft = 14, SetTop = 8, NameLetter = "G" },
                new Coordinate() { Name = "H7", SetLeft = 16, SetTop = 7, NameLetter = "H" }
            };

            // Default Pawns information for Player and AI (PlayerPosition1 - Player, PlayerPosition2 - AI)
            List<Player> PlayerPosition1 = new List<Player>()
            {
                new Player() { Coordinates = "A8", King = false},
                new Player() { Coordinates = "C8", King = false},
                new Player() { Coordinates = "E8", King = false},
                new Player() { Coordinates = "G8", King = false},
                new Player() { Coordinates = "B7", King = false},
                new Player() { Coordinates = "D7", King = false},
                new Player() { Coordinates = "F7", King = false},
                new Player() { Coordinates = "H7", King = false},
                new Player() { Coordinates = "A6", King = false},
                new Player() { Coordinates = "C6", King = false},
                new Player() { Coordinates = "E6", King = false},
                new Player() { Coordinates = "G6", King = false}
            };

            List<Player> PlayerPosition2 = new List<Player>()
            {
                new Player() { Coordinates = "B1", King = false},
                new Player() { Coordinates = "D1", King = false},
                new Player() { Coordinates = "F1", King = false},
                new Player() { Coordinates = "H1", King = false},
                new Player() { Coordinates = "A2", King = false},
                new Player() { Coordinates = "C2", King = false},
                new Player() { Coordinates = "E2", King = false},
                new Player() { Coordinates = "G2", King = false},
                new Player() { Coordinates = "B3", King = false}, 
                new Player() { Coordinates = "D3", King = false},
                new Player() { Coordinates = "F3", King = false},
                new Player() { Coordinates = "H3", King = false}
            };
           
            // This function will draw all pawns for player and AI depends on their coordinats
            void Start()
            {
                for (int i = 0; i < 12; i++)
                {                    
                    char[] subs = PlayerPosition1[i].Coordinates.ToCharArray();                    
                    for (int b = 0; b < Coords.Count; b++)
                    {
                        if ((subs[0].ToString() == Coords[b].NameLetter) && (subs[1].ToString() == Coords[b].SetTop.ToString())) // Does Pawns in memory exist on the table coordinats
                        {
                            if (PlayerPosition1[i].King == true)  // Change color of crowned pawn
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.SetCursorPosition(Coords[b].SetLeft, Coords[b].SetTop);
                                Console.WriteLine("()");
                                Console.ForegroundColor = ConsoleColor.Gray;
                            }
                            else if (PlayerPosition1[i].King == false)
                            {
                                Console.SetCursorPosition(Coords[b].SetLeft, Coords[b].SetTop);
                                Console.WriteLine("()");
                            }
                        }
                    }
                }
                for (int i = 0; i < 12; i++)      // same as upper but for AI
                {
                    char[] subs = PlayerPosition2[i].Coordinates.ToCharArray();
                    for (int b = 0; b < Coords.Count; b++)
                    {
                        if ((subs[0].ToString() == Coords[b].NameLetter) && (subs[1].ToString() == Coords[b].SetTop.ToString()))
                        {
                            if (PlayerPosition2[i].King == true)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.SetCursorPosition(Coords[b].SetLeft, Coords[b].SetTop);
                                Console.WriteLine("><");
                                Console.ForegroundColor = ConsoleColor.Gray;
                            }
                            else if (PlayerPosition2[i].King == false)
                            {
                                Console.SetCursorPosition(Coords[b].SetLeft, Coords[b].SetTop);
                                Console.WriteLine("><");
                            }
                        }
                    }
                }
            }
          
            // Make all rule checks for player turn. All game logic which is responsible for the player is here
            void Search()
            {     
                // this command allow to user look at any moment current Player and AI memory information.
                if (Logic == "COORDS")  
                {
                    Console.SetCursorPosition(0, 15);
                    Console.WriteLine("()");
                    for (int i = 0; i < PlayerPosition1.Count; i++)
                    {
                        Console.WriteLine($"{PlayerPosition1[i].Coordinates}{PlayerPosition1[i].King}");
                    }
                    Console.WriteLine("><");
                    for (int i = 0; i < PlayerPosition2.Count; i++)
                    {
                        Console.WriteLine($"{PlayerPosition2[i].Coordinates}{PlayerPosition2[i].King}");
                    }
                }


                int Counter = PlayerPosition1.Count;                             // Counter which will count each main operation, 
                                                                                 // If this operation will repeats the same ammount of times
                                                                                 // us ammount elements in PlayerPosition1 it will stop this loop 
                                                                                 // and show the error message (Line 361)
                for (int i = 0; i < PlayerPosition1.Count; i++)
                {
                    if (PlayerPosition1[i].Coordinates == Logic)                 // Does user enter right input
                    {
                        Console.WriteLine("Now new coordinates");
                        string testLine = Console.ReadLine().ToUpper();
                        char[] subs = testLine.ToCharArray();                    // Create an array where Index 0 will be letter of coorddinats and index 2 will be the number from new coordinats
                        char[] subsOld = Logic.ToCharArray();                    // Same but for old coordinates
                        int calculator = 0;                                      // Will check ammount of elements in to array, should be two

                        foreach (var times in subs)                              // Calculate and check it 
                        {
                            calculator += 1;
                        }

                        if (calculator < 3)
                        {
                            for (int c = 0; c < Coords.Count; c++)
                            {
                                if (Coords[c].Name == testLine)
                                {                                    
                                    for (int b = 0; b < PlayerPosition1.Count; b++)
                                    {
                                        if (PlayerPosition1[b].Coordinates == testLine)   // Check where you can't go
                                        {
                                            Console.WriteLine("You cannnot go there");
                                            Console.ReadLine();
                                            return;
                                        }                                       
                                        if ((subsOld[1] - subs[1]) > 1)
                                        {
                                            Console.WriteLine("You can't jump there");
                                            Console.ReadLine();
                                            return;
                                        }
                                        if ((subsOld[0] - subs[0]) > 1 || (subsOld[0] - subs[0]) < -1)
                                        {
                                            Console.WriteLine("You can't jump by horisontaly");
                                            Console.ReadLine();
                                            return;
                                        }                                        
                                        if (PlayerPosition1[i].King == false) // Cannot go back
                                        {
                                            if (subsOld[1] < subs[1])
                                            {
                                                Console.WriteLine($"You can't go back {subs[1]}");
                                                Console.ReadLine();
                                                return;
                                            }                                            
                                        }                                       
                                    }
                                    for (int d = 0; d < PlayerPosition2.Count; d++)
                                    {
                                        if (PlayerPosition2[d].Coordinates == testLine)
                                        {
                                            if ((Coords[c].SetLeft > 3 && Coords[c].SetLeft < 15) && (Coords[c].SetTop > 1 && Coords[c].SetTop < 8))  // Do check that player cannot eat pawns which 
                                                                                                                                                      // is located near to the edje
                                            {
                                                if (subsOld[0] > subs[0] && subsOld[1] > subs[1])          // diagonal test
                                                {                                                    
                                                    subs[0]--;
                                                    subs[1]--;
                                                    string newEatingCoordinate = $"{subs[0]}{subs[1]}";    // predict new coordinats

                                                    for (int k = 0; k < PlayerPosition2.Count; k++)       
                                                    {
                                                        if (PlayerPosition2[k].Coordinates == newEatingCoordinate) // check if someone behind the eaten pawn
                                                        {
                                                            Console.WriteLine("You cannot eat there, error 1");
                                                            Console.ReadLine();
                                                            return;
                                                        }
                                                    }

                                                    if (subs[1] == '1')                                    // Transform into crawn if rached to the opposite side of the board
                                                    {
                                                        PlayerPosition1[i].King = true;
                                                    }

                                                    PlayerPosition1[i].Coordinates = newEatingCoordinate;  // Assighn new coordinats
                                                    PlayerPosition2[d].Coordinates = "00";                 // Eaten pawn will have 00 coordinats, which will not draw it for next turn
                                                    Turn = false;
                                                    return;                                                    
                                                }
                                                if (subsOld[0] < subs[0] && subsOld[1] > subs[1])          // Eat right up
                                                {                                                    
                                                    subs[0]++;
                                                    subs[1]--;
                                                    string newEatingCoordinate = $"{subs[0]}{subs[1]}";

                                                    for (int l = 0; l < PlayerPosition2.Count; l++)
                                                    {
                                                        if (PlayerPosition2[l].Coordinates == newEatingCoordinate)
                                                        {
                                                            Console.WriteLine("You cannot eat there, error 2");
                                                            Console.ReadLine();
                                                            return;
                                                        }
                                                    }

                                                    if (subs[1] == '1')
                                                    {
                                                        PlayerPosition1[i].King = true;
                                                    }

                                                    PlayerPosition1[i].Coordinates = newEatingCoordinate;
                                                    PlayerPosition2[d].Coordinates = "00";
                                                    Turn = false;
                                                    return;
                                                }
                                                if (subsOld[0] > subs[0] && subsOld[1] < subs[1])     //diagonal test for eating back
                                                {                                                    
                                                    subs[0]--;
                                                    subs[1]++;
                                                    string newEatingCoordinate = $"{subs[0]}{subs[1]}";

                                                    for (int k = 0; k < PlayerPosition2.Count; k++)
                                                    {
                                                        if (PlayerPosition2[k].Coordinates == newEatingCoordinate)
                                                        {
                                                            Console.WriteLine("You cannot eat there, error 3");
                                                            Console.ReadLine();
                                                            return;
                                                        }
                                                    }

                                                    PlayerPosition1[i].Coordinates = newEatingCoordinate;
                                                    PlayerPosition2[d].Coordinates = "00";
                                                    Turn = false;
                                                    return;
                                                }
                                                if (subsOld[0] < subs[0] && subsOld[1] < subs[1])
                                                {                                                    
                                                    subs[0]++;
                                                    subs[1]++;
                                                    string newEatingCoordinate = $"{subs[0]}{subs[1]}";

                                                    for (int l = 0; l < PlayerPosition2.Count; l++)
                                                    {
                                                        if (PlayerPosition2[l].Coordinates == newEatingCoordinate)
                                                        {
                                                            Console.WriteLine("You cannot eat there, error 4");
                                                            Console.ReadLine();
                                                            return;
                                                        }
                                                    }

                                                    PlayerPosition1[i].Coordinates = newEatingCoordinate;
                                                    PlayerPosition2[d].Coordinates = "00";
                                                    Turn = false;
                                                    return;
                                                }
                                            }
                                            else
                                            {
                                                Console.WriteLine("You cannot eat there");  // in any other case
                                                Console.ReadLine();
                                                return;
                                            }
                                        }
                                    }
                                    if (subs[1] == '1')                                     // check does Pawn reached the opposite side of the board
                                    {
                                        Console.WriteLine($"{subs[1]}");
                                        PlayerPosition1[i].King = true;
                                    }
                                    PlayerPosition1[i].Coordinates = testLine;
                                    Turn = false;
                                    return;                                    
                                }
                            }                                                                                 
                        }
                        if (calculator >= 3)
                        {
                            Console.WriteLine("Error, wrong new coordinates");
                            Console.ReadLine();                            
                        }                        
                    }
                    
                    Counter -= 1;
                    if (Counter == 0)
                    {
                        Console.SetCursorPosition(0, 11);
                        Console.WriteLine("I think you did something wrong, try one more time");
                        Console.ReadLine();                        
                    }
                }                
            }

            // Main AI logic, first of all it will check does any of Pawns on the board can eat someone, if yes it will do it. If it cannot eat any it will move random pawn

            void Search2()
            {
                int Counter = PlayerPosition2.Count;           // Take one random pawn and generate all possible variants of movement
                int ranNum = new Random().Next(0, Counter);
                string RandomPawn = PlayerPosition2[ranNum].Coordinates;
                char[] subsOld = RandomPawn.ToCharArray();
                subsOld[0]++;
                subsOld[1]++;
                string newEatingCoordinate1 = $"{subsOld[0]}{subsOld[1]}"; // right down
                char[] subs1 = newEatingCoordinate1.ToCharArray();
                subsOld[0]--;
                subsOld[0]--;
                string newEatingCoordinate2 = $"{subsOld[0]}{subsOld[1]}"; // left down
                char[] subs2 = newEatingCoordinate2.ToCharArray();
                subsOld[1]--; 
                subsOld[1]--;
                string newEatingCoordinate3 = $"{subsOld[0]}{subsOld[1]}"; // left up
                char[] subs3 = newEatingCoordinate1.ToCharArray();
                subsOld[0]++;
                subsOld[0]++;
                string newEatingCoordinate4 = $"{subsOld[0]}{subsOld[1]}"; // right up
                char[] subs4 = newEatingCoordinate2.ToCharArray();
                subsOld[0]--;
                subsOld[1]++;


                for (int p = 0; p < PlayerPosition2.Count; p++)  // Check every pawn on the table and generate every variant for movement
                {
                    char[] newsubsOld = PlayerPosition2[p].Coordinates.ToCharArray();
                    string toEatCoords = $"{newsubsOld[0]}{newsubsOld[1]}";
                    newsubsOld[0]++;
                    newsubsOld[1]++;
                    string realnewEatingCoordinate1 = $"{newsubsOld[0]}{newsubsOld[1]}"; // right down
                    char[] newsubs1 = realnewEatingCoordinate1.ToCharArray();
                    newsubsOld[0]--;
                    newsubsOld[0]--;
                    string realnewEatingCoordinate2 = $"{newsubsOld[0]}{newsubsOld[1]}"; // left down
                    char[] newsubs2 = realnewEatingCoordinate2.ToCharArray();
                    newsubsOld[1]--;
                    newsubsOld[1]--;
                    string realnewEatingCoordinate3 = $"{newsubsOld[0]}{newsubsOld[1]}"; // left up
                    char[] newsubs3 = realnewEatingCoordinate3.ToCharArray();
                    newsubsOld[0]++;
                    newsubsOld[0]++;
                    string realnewEatingCoordinate4 = $"{newsubsOld[0]}{newsubsOld[1]}"; // right up
                    char[] newsubs4 = realnewEatingCoordinate4.ToCharArray();

                    for (int i = 0; i < PlayerPosition1.Count; i++)
                    {
                        if (PlayerPosition1[i].Coordinates == realnewEatingCoordinate1) // try to eat right down
                        {
                            newsubs1[0]++;
                            newsubs1[1]++;
                            string tryToEat1 = $"{newsubs1[0]}{newsubs1[1]}";           // new coordinate to eat
                            for (int k = 0; k < Coords.Count; k++)
                            {
                                if (Coords[k].Name == tryToEat1)
                                {
                                    int counter = PlayerPosition1.Count;
                                    int compere = 0;
                                    int counter2 = PlayerPosition2.Count;
                                    int compere2 = 0;

                                    for (int l = 0; l < PlayerPosition1.Count; l++)
                                    {                                        
                                        if (PlayerPosition1[l].Coordinates != tryToEat1) // Does Player is located behind
                                        {
                                            compere++;                                            
                                        }                                        
                                    }

                                    for (int l = 0; l < PlayerPosition2.Count; l++)
                                    {
                                        if (PlayerPosition2[l].Coordinates != tryToEat1) // Does AI pawn located behind
                                        {
                                            compere2++;
                                        }
                                    }

                                    if (compere == counter && compere2 == counter2)      // Final condition if AI can eat the Player pawn
                                    {
                                        PlayerPosition2[p].Coordinates = tryToEat1;
                                        PlayerPosition1[i].Coordinates = "00";
                                        Turn = true;
                                        if (newsubs1[1] == '8')                          // If reached the end of the board it will be crowned
                                        {                                           
                                            PlayerPosition2[p].King = true;
                                        }                                       
                                        return;
                                    }                                    
                                }
                            }
                        }
                        if (PlayerPosition1[i].Coordinates == realnewEatingCoordinate2) // try to eat left down
                        {
                            newsubs2[0]--;
                            newsubs2[1]++;
                            string tryToEat2 = $"{newsubs2[0]}{newsubs2[1]}";
                            for (int k = 0; k < Coords.Count; k++)
                            {
                                if (Coords[k].Name == tryToEat2)
                                {
                                    int counter = PlayerPosition1.Count;
                                    int compere = 0;
                                    int counter2 = PlayerPosition2.Count;
                                    int compere2 = 0;

                                    for (int l = 0; l < PlayerPosition1.Count; l++)
                                    {
                                        if (PlayerPosition1[l].Coordinates != tryToEat2) // brake
                                        {
                                            compere++;
                                        }
                                    }

                                    for (int l = 0; l < PlayerPosition2.Count; l++)
                                    {
                                        if (PlayerPosition2[l].Coordinates != tryToEat2) // brake
                                        {
                                            compere2++;
                                        }
                                    }

                                    if (compere == counter && compere2 == counter2)
                                    {
                                        PlayerPosition2[p].Coordinates = tryToEat2;
                                        PlayerPosition1[i].Coordinates = "00";
                                        Turn = true;
                                        if (newsubs2[1] == '8')
                                        {                                            
                                            PlayerPosition2[p].King = true;
                                        }                                        
                                        return;
                                    }                                    
                                }
                            }
                        }
                        if (PlayerPosition2[p].King == true)
                        {
                            if (PlayerPosition1[i].Coordinates == realnewEatingCoordinate3) // try to eat left up
                            {
                                newsubs3[0]--;
                                newsubs3[1]--;
                                string tryToEat3 = $"{newsubs3[0]}{newsubs3[1]}";
                                for (int k = 0; k < Coords.Count; k++)
                                {
                                    if (Coords[k].Name == tryToEat3)
                                    {
                                        int counter = PlayerPosition1.Count;
                                        int compere = 0;
                                        int counter2 = PlayerPosition2.Count;
                                        int compere2 = 0;

                                        for (int l = 0; l < PlayerPosition1.Count; l++)
                                        {
                                            if (PlayerPosition1[l].Coordinates != tryToEat3) // brake
                                            {
                                                compere++;
                                            }
                                        }

                                        for (int l = 0; l < PlayerPosition2.Count; l++)
                                        {
                                            if (PlayerPosition2[l].Coordinates != tryToEat3) // brake
                                            {
                                                compere2++;
                                            }
                                        }

                                        if (compere == counter && compere2 == counter2)
                                        {
                                            PlayerPosition2[p].Coordinates = tryToEat3;
                                            PlayerPosition1[i].Coordinates = "00";
                                            Turn = true;                                           
                                            return;
                                        }                                        
                                    }
                                }
                            }
                            if (PlayerPosition1[i].Coordinates == realnewEatingCoordinate4) // try to eat right up
                            {
                                newsubs4[0]++;
                                newsubs4[1]--;
                                string tryToEat4 = $"{newsubs4[0]}{newsubs4[1]}";
                                for (int k = 0; k < Coords.Count; k++)
                                {
                                    if (Coords[k].Name == tryToEat4)
                                    {
                                        int counter = PlayerPosition1.Count;
                                        int compere = 0;
                                        int counter2 = PlayerPosition2.Count;
                                        int compere2 = 0;

                                        for (int l = 0; l < PlayerPosition1.Count; l++)
                                        {
                                            if (PlayerPosition1[l].Coordinates != tryToEat4) // brake
                                            {
                                                compere++;
                                            }
                                        }

                                        for (int l = 0; l < PlayerPosition2.Count; l++)
                                        {
                                            if (PlayerPosition2[l].Coordinates != tryToEat4) // brake
                                            {
                                                compere2++;
                                            }
                                        }

                                        if (compere == counter && compere2 == counter2)
                                        {
                                            PlayerPosition2[p].Coordinates = tryToEat4;
                                            PlayerPosition1[i].Coordinates = "00";
                                            Turn = true;                                            
                                            return;
                                        }                                        
                                    }
                                }
                            }
                        }
                    }
                }

                // if AI cannot eat it will use random choosed pawn to try to make a turn. If this pawn wont able to make a turn, the main logic will call Search2 one more time
                // and it will generate a new Pawn to make a random turn
                for (int t = 0; t < 2; t++) // Depends of that it will go left or right (Now it doesn't really need but don't want to make debug without it, it works rn)
                {
                    if (PlayerPosition2[ranNum].Coordinates == RandomPawn)
                        {
                        for (int i = 0; i < PlayerPosition2.Count; i++)
                        {
                            if (PlayerPosition2[i].Coordinates == newEatingCoordinate1) // Does new coordinate match existing coordinate of AI
                            {                                
                                newEatingCoordinate1 = "00";                                
                            }
                            if (PlayerPosition2[i].Coordinates == newEatingCoordinate2)
                            {
                                newEatingCoordinate2 = "00";
                            }
                            if (PlayerPosition2[i].Coordinates == newEatingCoordinate3) 
                            {
                                newEatingCoordinate3 = "00";
                            }
                            if (PlayerPosition2[i].Coordinates == newEatingCoordinate4)
                            {
                                newEatingCoordinate4 = "00";
                            }
                            if (PlayerPosition2[i].King == false) // Cannot go back (don't use it)
                            {
                                if (subsOld[t] > subs1[t])
                                {                                   
                                    newEatingCoordinate1 = "00";
                                    newEatingCoordinate2 = "00";
                                }
                            }
                            if (PlayerPosition1[i].Coordinates == newEatingCoordinate1) // cannot eat here (double check)
                            {                                
                                newEatingCoordinate1 = "00";                                
                            }
                            if (PlayerPosition1[i].Coordinates == newEatingCoordinate2)
                            {
                                newEatingCoordinate2 = "00";
                            }
                            if (PlayerPosition1[i].Coordinates == newEatingCoordinate3) 
                            {
                                newEatingCoordinate3 = "00";
                            }
                            if (PlayerPosition1[i].Coordinates == newEatingCoordinate4)
                            {
                                newEatingCoordinate4 = "00";
                            }
                        } 
                        for (int i = 0; i < Coords.Count; i++)                                   // If all other conditions are ok AI will make a turn
                        {
                            if (Coords[i].Name == newEatingCoordinate1 && t == 0)
                            {
                                PlayerPosition2[ranNum].Coordinates = newEatingCoordinate1;
                                Turn = true;
                                if (subs1[1] == '8')
                                {                                    
                                    PlayerPosition2[ranNum].King = true;
                                }
                                return;
                            }
                            if (Coords[i].Name == newEatingCoordinate2 && t == 1)
                            {
                                PlayerPosition2[ranNum].Coordinates = newEatingCoordinate2;
                                Turn = true;
                                if (subs2[1] == '8')
                                {                                    
                                    PlayerPosition2[ranNum].King = true;
                                }
                                return;
                            }
                            if (Coords[i].Name == newEatingCoordinate3)                          // Or even go back
                            {
                                if (PlayerPosition2[ranNum].King == true)
                                {
                                    PlayerPosition2[ranNum].Coordinates = newEatingCoordinate3;
                                    Turn = true;                                    
                                    return;
                                }
                            }
                            if (Coords[i].Name == newEatingCoordinate4)
                            {
                                if (PlayerPosition2[ranNum].King == true)
                                {
                                    PlayerPosition2[ranNum].Coordinates = newEatingCoordinate4;
                                    Turn = true;
                                    return;
                                }
                            }
                        }
                    }
                }                
            }

            // visual part
            void BoardLine1()
            {
                Console.BackgroundColor = ConsoleColor.Gray;                
                Console.Write($" {Line}");
                Console.BackgroundColor = ConsoleColor.White;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.White;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.White;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.White;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.Gray;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.Black;
                Line += 1;
            }

            //visual part #2
            void BoardLine2()
            {
                Console.BackgroundColor = ConsoleColor.Gray;
                Console.Write($" {Line}");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.White;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.White;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.White;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.White;
                Console.Write("  ");               
                Console.BackgroundColor = ConsoleColor.Gray;
                Console.Write("  ");
                Console.BackgroundColor = ConsoleColor.Black;
                Line += 1;
            }

            // Draw the board
            void Board()
            {
                Line = 1;
                Console.SetCursorPosition(0, 0);
                Console.BackgroundColor = ConsoleColor.Gray;
                Console.ForegroundColor = ConsoleColor.DarkBlue;
                Console.WriteLine("   a b c d e f g h  ");                

                for (int i = 0; i < 4; i++)
                {                    
                    BoardLine1();
                    Console.WriteLine();
                    BoardLine2();
                    Console.WriteLine();
                }

                Console.BackgroundColor = ConsoleColor.Gray;
                Console.WriteLine("                    ");
                Console.BackgroundColor = ConsoleColor.Black;
                Console.ForegroundColor = ConsoleColor.Gray;
            }

            // Clear chat below the board
            void Clear()
            {
                Console.SetCursorPosition(0, 10);
                Console.WriteLine("                                                                    ");
                Console.WriteLine("                                                                    ");
                Console.WriteLine("                                                                    ");
                Console.WriteLine("                                                                    ");
                Console.WriteLine("                                                                    ");
            }

            int MainCounter;

            // Main Game logic here
            void Game()
            {
                while (true)
                {                    
                    while (Turn == true)
                    {
                        Board();
                        Start();
                        Clear();
                        void oneMoreTime()
                        {
                            MainCounter = 0;
                            for (int i = 0; i < PlayerPosition1.Count; i++)
                            {
                                if (PlayerPosition1[i].Coordinates == "00")
                                {
                                    MainCounter++;
                                }
                            }
                            if (MainCounter == 12)
                            {
                                Console.SetCursorPosition(0, 10);
                                Console.WriteLine("You loose the game...");
                                Console.WriteLine("One more time? Yes or No");
                                Console.WriteLine("                         ");
                                Console.SetCursorPosition(0, 12);
                                string neLogic = Console.ReadLine().ToUpper();
                                if (neLogic == "YES")
                                {
                                    Main();
                                }
                                if (neLogic == "NO")
                                {
                                    Environment.Exit(0);
                                }
                                if (neLogic != "YES" && neLogic != "NO")
                                {
                                    oneMoreTime();
                                }

                            }
                        }
                        oneMoreTime();
                        if (MainCounter < 12)
                        {
                            Console.SetCursorPosition(0, 10);
                            Console.WriteLine("Now your turn...");
                            Logic = Console.ReadLine().ToUpper();
                        }
                        Search();
                        Clear();
                        Board();
                        Start();
                    }
                                      
                    Console.SetCursorPosition(0, 11);
                    Console.WriteLine("It is computer turn...");
                    while (Turn == false)
                    {
                        Board();
                        Start();
                        Clear();
                        void oneMoreTime2()
                        {
                            MainCounter = 0;
                            for (int i = 0; i < PlayerPosition2.Count; i++)
                            {
                                if (PlayerPosition2[i].Coordinates == "00")
                                {
                                    MainCounter++;
                                }
                            }
                            if (MainCounter == 12)
                            {
                                Console.SetCursorPosition(0, 10);
                                Console.WriteLine("You win the game...");
                                Console.WriteLine("One more time? Yes or No");
                                Console.WriteLine("                         ");
                                Console.SetCursorPosition(0, 12);
                                string neLogic = Console.ReadLine().ToUpper();
                                if (neLogic == "YES")
                                {
                                    Main();
                                }
                                if (neLogic == "NO")
                                {
                                    Environment.Exit(0);
                                }
                                if (neLogic != "YES" && neLogic != "NO")
                                {
                                    oneMoreTime2();
                                }
                            }
                        }
                        oneMoreTime2();
                        Search2();
                        if (Turn == true && MainCounter < 12)
                        {
                            Console.SetCursorPosition(0, 10);
                            Console.WriteLine("Press 'Enter'");
                            Logic = Console.ReadLine().ToUpper();
                        }
                        Clear();
                        Board();
                        Start();
                    }
                }
            }
            Game();    // Everything starts here
        }
    }
}
This site was made on Tilda — a website builder that helps to create a website without any code
Create a website