Beispiel #1
0
        public BenchmarkItem(string[] moves)
        {
            // for now only white color will be supported
            // (when i'll have time later, it will be expanded)
            this.provider = new GameProvider(new MovesArrayAllocator(100, 100));

            Color color = Color.White;

            foreach (var moveStr in moves)
            {
                if (moveStr.Length == 0)
                    continue;

                Move move = new Move(moveStr);

                if (this.provider.PlayerBoards[(int)color].Figures[(int)move.From] == Queem.Core.Figure.King)
                    if (Math.Abs((int)move.From - (int)move.To) == 2)
                        move.Type = MoveType.KingCastle;

                this.provider.ProcessMove(move, color);

                bool needsPromotion = (int)move.Type >= (int)MoveType.Promotion;
                if (needsPromotion)
                    this.provider.PromotePawn(
                        color,
                        move.To,
                        move.Type.GetPromotionFigure());

                color = (Queem.Core.Color)(1 - (int)color);
            }

            solver = new ChessSolver(new DebutGraph());
            this.lastColor = color;
        }
Beispiel #2
0
        public static List<Move> GenerateSituation(int depth)
        {
            int curr_depth = 0;
            Color myColor = Color.White;
            PlayerPosition myPosition = PlayerPosition.Down;

            GameProvider provider = new GameProvider(new MovesArrayAllocator());

            Color color = myColor;
            Random rand = new Random(DateTime.Now.Millisecond);

            while (curr_depth < depth)
            {
                var player = provider.PlayerBoards[(int)color];
                var opponent = provider.PlayerBoards[1 - (int)color];

                var lastMove = new Move(Square.A1, Square.A1);
                if (provider.History.HasItems())
                    lastMove = provider.History.GetLastMove();

                var moves = player.GetMoves(
                    opponent,
                    lastMove,
                    MovesMask.AllMoves);
                provider.FilterMoves(moves, color);

                if (moves.Size == 0)
                {
                    // some checkmate found
                    break;
                }
                int index = rand.Next(moves.Size);
                // just get random move
                var move = new Move(moves.InnerArray[index]);

                provider.ProcessMove(move, color);

                bool needsPromotion = (int)move.Type >= (int)MoveType.Promotion;
                if (needsPromotion)
                    provider.PromotePawn(
                        color,
                        move.To,
                        move.Type.GetPromotionFigure());

                color = (Queem.Core.Color)(1 - (int)color);
                curr_depth += 1;

                provider.Allocator.ReleaseLast();
            }

            return provider.History.Moves;
        }
Beispiel #3
0
        public ChessBoardViewModel(GameProvider gameProvider)
        {
            this.provider = gameProvider;
            this.squareItems = new ObservableCollection<SquareItem>();

            this.InitItems();
            this.lastHighlightedSquares = new List<HighlightedSquare>();

            // TODO remove this in future
            this.CurrentPlayerColor = Color.White;

            this.promotionViewModel = new PawnPromotionViewModel();
            this.showOverlayState = Enums.ShowOverlayState.Nothing;

            this.dispatcher = Dispatcher.CurrentDispatcher;
        }
Beispiel #4
0
        public MainWindow()
        {
            InitializeComponent();

            this.gameProvider = new GameProvider(new MovesArrayAllocator());

            this.chessboardControl.SetupGameProvider(gameProvider);
            this.worker = new BackgroundWorker();

            this.redoMoves = new List<MoveWithDecision>();

            this.worker.DoWork += new DoWorkEventHandler(worker_DoWork);
            this.worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);

            this.maxdepth = 5;
            this.debutsGraph = DebutsReader.ReadDebuts("simple_debut_moves", PlayerPosition.Down);
        }
Beispiel #5
0
        public SortingTests()
        {
            this.provider = new GameProvider(new MovesArrayAllocator(100, 100));
            string path = "chess.game";
            string[] lines = System.IO.File.ReadAllLines(path);
            Queem.Core.Color color = Queem.Core.Color.White;
            foreach (var line in lines)
            {
                var move = new Move(line);

                if (this.provider.PlayerBoards[(int)color].Figures[(int)move.From] == Queem.Core.Figure.King)
                    if (Math.Abs((int)move.From - (int)move.To) == 2)
                        move.Type = MoveType.KingCastle;

                this.provider.ProcessMove(move, color);
                color = (Queem.Core.Color)(1 - (int)color);
            }
        }
Beispiel #6
0
        private void readButton_Click(object sender, RoutedEventArgs e)
        {
            this.gameProvider = new GameProvider(this.gameProvider.Allocator);
            this.chessboardControl.SetupGameProvider(this.gameProvider);
            this.redoMoves = new List<MoveWithDecision>();

            string path = Directory.GetCurrentDirectory() +
                System.IO.Path.DirectorySeparatorChar + "chess.game";

            string[] lines = System.IO.File.ReadAllLines(path);
            Queem.Core.Color color = Queem.Core.Color.White;
            foreach (var line in lines)
            {
                var move = new Move(line);

                if (this.gameProvider.PlayerBoards[(int)color].Figures[(int)move.From] == Queem.Core.Figure.King)
                    if (Math.Abs((int)move.From - (int)move.To) == 2)
                        move.Type = MoveType.KingCastle;

                this.gameProvider.ProcessMove(move, color);
                color = (Queem.Core.Color)(1 - (int)color);
            }

            this.chessboardControl.RedrawAll();
        }
 public void SetupGameProvider(GameProvider provider)
 {
     this.viewModel = new ChessBoardViewModel(provider);
     this.DataContext = this.viewModel;
 }