Example #1
0
        public override ChessMove CalculateMove()
        {
            string line;
            var    notFirst = false;

            do
            {
                if (notFirst)
                {
                    Output.Out.Text = "Format: a1-a2";
                }
                Console.SetCursorPosition(0, 18);
                ConsoleFontHelper.ClearCurrentConsoleLine();
                Console.Write($"{RoundManager.CurrentRound}. Zug {(Color == PlayerColor.White ? "weiß" : "schwarz")}: ");
                line     = Console.ReadLine()?.Trim();
                notFirst = true;
            } while (line == null || !_r.IsMatch(line));
            Output.Out.Text = "";
            var splits = line.Split('-');
            var from   = new ChessPosition((byte)(splits[0][0] - 96), byte.Parse("" + splits[0][1]));
            var to     = new ChessPosition((byte)(splits[1][0] - 96), byte.Parse("" + splits[1][1]));

            return(new ChessMove(from, to));
        }
Example #2
0
        private static void Main()
        {
            switch (AskUserForNumber(@"White/Black
(1) Player vs Player
(2) Player vs AI
(3) AI vs Player
(4) AI vs AI", 1, 4))
            {
            case 1:
                PlayerW = new HumanActor(PlayerColor.White);
                PlayerB = new HumanActor(PlayerColor.Black);
                break;

            case 2:
                PlayerW = new HumanActor(PlayerColor.White);
                var input = AskUserForNumber("AI depth (0 for random)", 0, 5);
                if (input == 0)
                {
                    PlayerB = new RandomAiActor(PlayerColor.Black);
                }
                else
                {
                    PlayerB = new MiniMaxAiActor(PlayerColor.Black, input);
                }
                break;

            case 3:
                PlayerB = new HumanActor(PlayerColor.Black);
                var input3 = AskUserForNumber("AI depth (0 for random)", 0, 5);
                if (input3 == 0)
                {
                    PlayerW = new RandomAiActor(PlayerColor.White);
                }
                else
                {
                    PlayerW = new MiniMaxAiActor(PlayerColor.White, input3);
                }
                break;

            case 4:
                var input1 = AskUserForNumber("AI 1 depth (0 for random)", 0, 5);
                var input2 = AskUserForNumber("AI 2 depth (0 for random)", 0, 5);

                if (input1 == 0)
                {
                    PlayerW = new RandomAiActor(PlayerColor.White);
                }
                else
                {
                    PlayerW = new MiniMaxAiActor(PlayerColor.White, input1);
                }
                if (input2 == 0)
                {
                    PlayerB = new RandomAiActor(PlayerColor.Black);
                }
                else
                {
                    PlayerB = new MiniMaxAiActor(PlayerColor.Black, input2);
                }
                break;
            }


            ConsoleFontHelper.Init();
            ChessBoard.CurrentBoard.Render();
            ChessBoard.CurrentBoard.Pieces.ForEach(p => p.Render());
            while (true)
            {
                try
                {
                    var b = ChessBoard.CurrentBoard;
                    RoundManager.MakeRound(ref b);
                    Output.Out.Text = "";
                } catch (RoundEndingException ex)
                {
                    Output.Out.Text = ex.Message;
                    ChessBoard.CurrentBoard.Render();
                    ChessBoard.CurrentBoard.Pieces.ForEach(p => p.Render());
                    break;
                }
                catch (Exception ex)
                {
                    if (RoundManager.CurrentActor.ShowErrors)
                    {
                        Output.Out.Text = ex.Message;
                    }
                }
            }
        }
Example #3
0
 protected void PrintLoading()
 {
     Console.SetCursorPosition(0, 18);
     ConsoleFontHelper.ClearCurrentConsoleLine();
     Console.Write("Calculating...");
 }