示例#1
0
文件: MainUI.xaml.cs 项目: RL-BB/WGPM
        private void MoveBinding(Vehicle car, UserControl control, double marginLeft, double defaultTop)
        {
            Binding myBinding = new Binding();

            myBinding.Source = car;
            myBinding.Path   = new PropertyPath("RoomNum");
            MoveConverter move = new MoveConverter();

            move.CarNum         = car.CarNum;
            move.DefalutLeft    = marginLeft;
            move.DefaultTop     = defaultTop;
            myBinding.Converter = move;
            control.SetBinding(MarginProperty, myBinding);
        }
示例#2
0
        private static void MainGame()
        {
            var depth = 6;
            var state = new State("r1b1k1nr/ppp1qppp/8/3p4/1b6/2NB1Q2/PPPB1PPP/R3K2R w KQkq - 1 9");

            var moveConverter = new MoveConverter();
            var moves         = state.GetAllStates().Select(p => moveConverter.MoveToString(p.LastMove)).ToList();
            var evaluator     = new Evaluator();
            var ai            = new AI(evaluator);
            var eval          = ai.Minimax(state, depth--, Int32.MinValue, Int32.MaxValue, state.WhiteToMove);

            Console.WriteLine(moveConverter.MoveToString(eval.Item2.LastMove) + " " + eval.Item1);

            while (depth >= 0)
            {
                state = eval.Item2;
                Console.WriteLine(moveConverter.MoveToString(eval.Item2.LastMove) + " " + eval.Item1);
                eval = ai.Minimax(state, depth--, Int32.MinValue, Int32.MaxValue, state.WhiteToMove);
            }
        }
示例#3
0
        private static void RealGame()
        {
            Console.WriteLine("Enter 1 if you want to play as white or 2 if you want to play as black");
            var player       = Console.ReadLine();
            var playersWhite = player.Contains('1') ? true : false;
            var playerSide   = playersWhite ? "White" : "Black";

            Console.WriteLine("You're playing as " + playerSide);

            var state         = new State();
            var evaluator     = new Evaluator();
            var ai            = new AI(evaluator);
            var moveConverter = new MoveConverter();
            var depth         = 4;
            var moveCounter   = 0;

            while (true)
            {
                if (state.WhiteToMove == playersWhite)
                {
                    State nextState = null;
                    var   m         = Console.ReadLine();
                    if (m.Contains("res"))
                    {
                        break;
                    }
                    var move      = moveConverter.StringToMove(m);
                    var allStates = state.GetAllStates();
                    var x         = allStates.Select(x => x.LastMove).ToList();
                    if (move.WasLongCastling)
                    {
                        nextState = allStates.FirstOrDefault(s => s.LastMove.WasLongCastling);
                    }
                    if (move.WasShortCastling)
                    {
                        nextState = allStates.FirstOrDefault(s => s.LastMove.WasShortCastling);
                    }
                    else
                    {
                        nextState = allStates.FirstOrDefault(s => s.LastMove.DestinationFile == move.DestinationFile && s.LastMove.DestinationLine == move.DestinationLine &&
                                                             s.LastMove.StartingLine == move.StartingLine && s.LastMove.StartingFile == move.StartingFile);
                    }
                    if (nextState == null)
                    {
                        Console.WriteLine("You've entered an incorrect move. Try again or type 'res' if you want to quit");
                        continue;
                    }
                    else
                    {
                        state = nextState;
                    }
                }
                else
                {
                    var eval = ai.Minimax(state, depth, Int32.MinValue, Int32.MaxValue, state.WhiteToMove);
                    Console.WriteLine("Your opponent has played the move " + moveConverter.MoveToString(eval.Item2.LastMove) + " and the score is " + (double)eval.Item1 / 100);
                    state = eval.Item2;
                }
                moveCounter++;
                if (moveCounter > 18)
                {
                    depth = 5;
                }
            }
        }
        private static void TypeRobotMoves()
        {
            string maxCoordinateX, maxCoordinateY;
            var    marsGrid = BuildMarsGrid(out maxCoordinateX, out maxCoordinateY);

            var    positionMoves      = new List <PositionMove>();
            int    robotNumber        = 1;
            string defaultOrientation = "N";

            while (true)
            {
                var robotPosition = new Position();
                do
                {
                    Console.WriteLine($"Type position X of the Robot {robotNumber} and press enter");
                    string positionX = Console.ReadLine();
                    Console.WriteLine($"Type position Y of the Robot {robotNumber} and press enter");
                    string positionY = Console.ReadLine();
                    Console.WriteLine($"Type Orientation N, S, E, W of the Robot {robotNumber} press enter");
                    string orientation = Console.ReadLine();

                    robotPosition.PositionX = int.Parse(positionX);
                    robotPosition.PositionY = int.Parse(positionY);

                    if (!Enum.IsDefined(typeof(Orientation), orientation))
                    {
                        orientation = defaultOrientation;
                    }
                    robotPosition.Orientation = (Orientation)Enum.Parse(typeof(Orientation), orientation, true);
                } while (!robotPosition.IsValid(marsGrid));

                Console.WriteLine($"Type set of robot moves R L or F (for example FFRLFFL) of the Robot {robotNumber} and press enter");
                string moves = Console.ReadLine();

                var moveCommands = new MoveConverter().Convert(moves);
                positionMoves.Add(new PositionMove {
                    InitialPosition = robotPosition, Movements = moveCommands
                });

                Console.WriteLine($"Moves: {moves}");

                robotNumber++;

                Console.WriteLine($"More robots?? Press any key. If you want to finish press ESC");

                ConsoleKeyInfo info = Console.ReadKey();
                if (info.Key == ConsoleKey.Escape)
                {
                    break;
                }
                Console.WriteLine("--------------------------------------------");
            }

            var finalPositions = new MarsBoardService().GetOutput(marsGrid, positionMoves);

            Console.WriteLine("--------------------------------------------");
            Console.WriteLine("FINAL OUTPUT:");
            Console.WriteLine("--------------------------------------------");
            foreach (var finalPosition in finalPositions)
            {
                Console.WriteLine(finalPosition.ToString());
            }
        }