示例#1
0
 public FigureOnSquare(Figure figure, Square square)
 {
     this.figure = figure;
     this.square = square;
 }
示例#2
0
文件: Player.cs 项目: Coolxer/chess
        //fourth level of ai
        public int calcBestMove(int depth, int alpha, int beta, bool own)
        {
            if (depth == 0)
            {
                return(-evaluateBoard());
            }

            generate();

            int bestMoveValue;

            if (own)
            {
                bestMoveValue = Int32.MinValue;
            }
            else
            {
                bestMoveValue = Int32.MaxValue;
            }

            foreach (String s in availablesMoves)
            {
                lastPickedFigurePosition = new Point(s[0], s[1]);

                Figure f = board.fields[lastPickedFigurePosition.X, lastPickedFigurePosition.Y];

                Point p = new Point(s[2], s[3]);

                if (board.fields[p.X, p.Y] != null && board.fields[p.X, p.Y].color != color)
                {
                    lastPickedFigure       = board.fields[p.X, p.Y];
                    board.fields[p.X, p.Y] = f;

                    board.fields[lastPickedFigurePosition.X, lastPickedFigurePosition.Y] = null;

                    changed = true;
                }

                value = calcBestMove(depth - 1, alpha, beta, !own);

                if (own)
                {
                    if (value > bestMoveValue)
                    {
                        bestMove      = s;
                        bestMoveValue = value;
                    }
                }
                else
                {
                    if (value < bestMoveValue)
                    {
                        bestMove      = s;
                        bestMoveValue = value;
                    }

                    beta = Math.Min(beta, value);
                }

                if (beta <= alpha)
                {
                    break;
                }
            }

            return(value);
        }
示例#3
0
        public int rating(String request)
        {
            Point fp = new Point(request[0].ToString() + request[1].ToString());
            Point mp = new Point(request[2].ToString() + request[3].ToString());

            current = board.fields[fp.X, fp.Y];
            target  = board.fields[mp.X, mp.Y];

            if (!ai || turn == 'w')
            {
                //if user chose no figure (empty field)
                if (current == null)
                {
                    return(0);
                }

                //if user chose no its own figure (opponent figure chosen)
                if (current.color != c.color)
                {
                    return(0);
                }

                //if user want to move its own figure above its own figure w to w, b to b
                if (target != null && target.color == current.color)
                {
                    return(0);
                }

                current.generateAllowedMoves();

                if (!current.matrix[mp.X, mp.Y])
                {
                    return(0);
                }
            }

            //removed hit figure
            if (target != null)
            {
                nc.figures.Remove(target);
                board.fields[mp.X, mp.Y] = null;
            }

            current.move(mp);
            board.fields[mp.X, mp.Y] = current;

            board.fields[fp.X, fp.Y] = null;

            c.movements++;

            if (checkForMate())
            {
                return(2);
            }

            int n = (c.color == 'w') ? 0 : 7;

            if (current.type == 'P' && current.pos.X == n)
            {
                int z = c.figures.IndexOf(current);
                c.figures[z] = new Queen(ref board, current.pos, c.color);
            }

            Player p = c;

            c  = nc;
            nc = p;

            turn = c.color;

            System.Threading.Thread.Sleep(350);

            return(1);
        }