Exemplo n.º 1
0
        private void MakeMove()
        {
            if (_moves.Count <= 1) ResetMove();
            else
            {
                var pos = new BoardPosition[_moves.Count];
                _moves.CopyTo(0, pos, 0, _moves.Count);
                bool eatMove = CheckersMove.IsEatMove(this.MyBoard, pos);

                var move = new CheckersMove(pos, eatMove);
                _lastMoveOk = true;
                ((HumanCheckersPlayer)CurrentPlayer).MakeAMove(move);

                if (_lastMoveOk) _lastMove = move;
                else _lastMove = null;

                CheckStatus();
                ResetMove();
            }
        }
Exemplo n.º 2
0
 bool IsPrefix(List<BoardPosition> path, CheckersMove move)
 {
     if (path.Count > move.MovePath.Length)
         return false;
     for (int i = 0; i < path.Count; i++)
         if (path[i].X != move.MovePath[i].X || path[i].Y != move.MovePath[i].Y)
             return false;
     return true;
 }
Exemplo n.º 3
0
        protected double SelectMove(CheckersBoard board, PieceColor color, int currentSearchDepth, double alpha, double beta)
        {
            var moves=board.RightMoves(color);

            if(currentSearchDepth==0 || moves.Count==0)
                return _boardEvaluator.Eval(board, currentSearchDepth,Color);
            else
            {
                //if have only one oportunnity the return this one and save time
                if (currentSearchDepth == MaxSearchDepth && (moves.Count == 1)) {
                    selectedMove = moves[0];
                    return 0;
                }

                double max=(this.Color==color)? double.MinValue: double.MaxValue;
                for(int i=0;i<moves.Count;i++)
                {
                    var move = moves[i];

                    CheckersBoard newBoard=PerformMove(board, move);

                    double eval=SelectMove(newBoard, color == PieceColor.White ? PieceColor.Black : PieceColor.White, currentSearchDepth-1,alpha,beta);

                    if(color==this.Color) {
                        if(max<eval)
                        {
                            max=eval;

                            if(currentSearchDepth==MaxSearchDepth)
                            {
                                selectedMove=move;
                                //System.Windows.Forms.MessageBox.Show("Got a move "+selectedMove + " currentSearchDepth :"+MaxSearchDepth);
                            }

                            if (beta<=max) break;
                            else alpha = Math.Max(alpha,max);
                        }
                        else if(max==eval)
                            {
                                if((currentSearchDepth==MaxSearchDepth) && (r.Next(9)%2==0))
                                {
                                    selectedMove=move;
                                    //System.Windows.Forms.MessageBox.Show("Got a move "+selectedMove + " currentSearchDepth :"+MaxSearchDepth);
                                }
                            }
                    }
                    else {
                        if(max>eval) max=eval;

                        if (alpha>=max) break;
                        else beta = Math.Min(beta,max);

                    }
                    //System.Windows.Forms.MessageBox.Show(newBoard.ToString()+'\n'+"Level "+currentSearchDepth+" Color "+color+" Max "+max+" eval "+eval);
                }
                return max;
            }
        }
Exemplo n.º 4
0
 public void MakeAMove(CheckersMove move)
 {
     if (OnPerformMove!=null) OnPerformMove(this,move);
 }
Exemplo n.º 5
0
        protected CheckersBoard PerformMove(CheckersBoard board, CheckersMove move)
        {
            CheckersBoard newBoard=(CheckersBoard)board.Clone();

            int x1=move.MovePath[0].X;
            int y1=move.MovePath[0].Y;

            CheckersPiece movingPiece=(CheckersPiece)newBoard.GetPieceAt(x1, y1);

            for(int i=0; i<move.MovePath.Length-1; i++)
            {
                int x2=move.MovePath[i+1].X;
                int y2=move.MovePath[i+1].Y;
                int incX=Inc(x1, x2);
                int incY=Inc(y1, y2);

                while(x1!=x2 || y1!=y2)
                {
                    CheckersPiece piece=newBoard.GetPieceAt(x1, y1) as CheckersPiece;
                    if(piece!=null)
                    {
                        newBoard.RemovePiece(piece);
                    }
                    x1+=incX;
                    y1+=incY;
                }
            }

            //White queen
            if(y1==0 && movingPiece.Color==PieceColor.White)
            {
                newBoard.PutPieceAt(x1, y1, new Queen(newBoard, x1, y1, PieceColor.White));
            }
            else if(y1==7 && movingPiece.Color==PieceColor.Black) //black queen
                {
                    newBoard.PutPieceAt(x1, y1, new Queen(newBoard, x1, y1, PieceColor.Black));
                }
            else //simply move piece
                newBoard.PutPieceAt(x1, y1, movingPiece);

            return newBoard;
        }