Пример #1
0
        public void PlayAgentMove(string moveDesc)
        {
            this.Dispatcher.Invoke((Action)(() =>
            {
                CheckerPiece checker = null;
                currentTurn = Turn.Black;
                List <string> descs = moveDesc.Split("//".ToArray()).ToList();
                string from = descs[0], to = descs[2];

                int fromx = int.Parse(from.Split(',')[0]),
                fromy = int.Parse(from.Split(',')[1]),
                tox = int.Parse(to.Split(',')[0]),
                toy = int.Parse(to.Split(',')[1]);

                //try black and black king, to find out which one it is
                if (grdBoard.Children.OfType <BlackChecker>()
                    .Where(p => (p.row == fromx) && (p.col == fromy)).SingleOrDefault() != null)
                {
                    currentPiece = grdBoard.Children.OfType <BlackChecker>()
                                   .Where(p => (p.row == fromx) && (p.col == fromy)).SingleOrDefault();

                    if (tox == BLACK_LAST_ROW)
                    {
                        checker = new BlackKingChecker();
                    }
                    else
                    {
                        checker = new BlackChecker();
                    }
                }
                else
                {
                    currentPiece = grdBoard.Children.OfType <BlackKingChecker>()
                                   .Where(p => (p.row == fromx) && (p.col == fromy)).SingleOrDefault();

                    checker = new BlackKingChecker();
                }

                EmptySpace tempEmptySpace = grdBoard.Children.OfType <EmptySpace>()
                                            .Where(p => (p.row == tox) && (p.col == toy)).SingleOrDefault();

                CaptureHumanCellInAgentMoveIfAny(tox, toy, tempEmptySpace);

                sound.Play();
                MoveChecker(tox, toy, checker);
                currentTurn = Turn.Red;
            }));
        }
Пример #2
0
        void RemovePiece(object sender, EventArgs e)
        {
            if (capturedPiece != null)
            {
                capturedPiece.Visibility = Visibility.Hidden;

                if (capturedPiece is RedChecker)
                {
                    RedChecker deadman        = new RedChecker();
                    Storyboard AddToGraveyard =
                        deadman.Resources["AddToGraveyard"] as Storyboard;
                    this.pnlBlackGraveyard.Children.Add(deadman);
                    AddToGraveyard.Begin();
                }
                else if (capturedPiece is BlackChecker)
                {
                    BlackChecker deadman        = new BlackChecker();
                    Storyboard   AddToGraveyard =
                        deadman.Resources["AddToGraveyard"] as Storyboard;
                    this.pnlRedGraveyard.Children.Add(deadman);
                    AddToGraveyard.Begin();
                }
                else if (capturedPiece is RedKingChecker)
                {
                    RedKingChecker deadman        = new RedKingChecker();
                    Storyboard     AddToGraveyard =
                        deadman.Resources["AddToGraveyard"] as Storyboard;
                    this.pnlBlackGraveyard.Children.Add(deadman);
                    AddToGraveyard.Begin();
                }
                else if (capturedPiece is BlackKingChecker)
                {
                    BlackKingChecker deadman        = new BlackKingChecker();
                    Storyboard       AddToGraveyard =
                        deadman.Resources["AddToGraveyard"] as Storyboard;
                    this.pnlRedGraveyard.Children.Add(deadman);
                    AddToGraveyard.Begin();
                }
                grdBoard.Children.Remove(capturedPiece);
            }
        }