Exemplo n.º 1
0
 public Tree(int depth, Context Context)
 {
     Root                = new AiNode();
     Root.Move           = new Move();
     Root.CurrentContext = Context.Clone();  //Pe o copie a contextului fac miscarea posibila
     AddNodes(Root, depth, ColorEnum.Black); //creaza node ul
 }
Exemplo n.º 2
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            CurrentMove.EndPosition = MouseOverCoordinate;
            movement = false;

            if (CurrentMove.piece != null)
            {
                if (Context.CurrentPlayer == CurrentMove.piece.Color)
                {
                    var nextMove = CurrentMove.piece.GetNextLegalMoves(CurrentMove.StartPosition, Context);
                    if (CurrentMove.piece.GetNextLegalMoves(CurrentMove.StartPosition, Context).Contains(CurrentMove.EndPosition))
                    {
                        Context.Update(CurrentMove);
                        this.Refresh();
                        if (CurrentMove.piece.Type == PieceEnum.Pawn && (CurrentMove.EndPosition.Y == 0 || CurrentMove.EndPosition.Y == 9))
                        {
                            Context.Layout.Promote(CurrentMove.EndPosition, CurrentMove.piece.Color);
                            this.Refresh();
                        }
                        Cursor = Cursors.Default;
                        if (VsAI)
                        {
                            AI ai = new AI(Context.Clone());
                            Context.Layout.Update(ai.GetNextMove());
                            Context.ToggleCurrentPlayer();
                            this.Refresh();
                        }
                        if (Context.CheckMating())
                        {
                            winner = CurrentMove.piece.Color;
                            DialogResult res = MessageBox.Show(winner.ToString() + " won! Do you want to play again?! ", "Game over", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                            if (res == DialogResult.Yes)
                            {
                                OnReplay?.Invoke();
                            }
                            else
                            {
                                OnExit?.Invoke();
                            }
                        }
                        if (Context.AlertCheck())
                        {
                            MessageBox.Show("Check! Save your king!");
                            Cursor = Cursors.Default;
                        }
                    }
                    Cursor = Cursors.Default;
                }
                else
                {
                    MessageBox.Show("Not your turn");
                    Cursor = Cursors.Default;
                }
            }
        }