Ejemplo n.º 1
0
        public void tryMove(int x, int y)
        {
            if (checkmate)
            {
                return;
            }

            if (posIsPlayer(x, y))
            {
                ismarked = false;
            }

            if (ismarked)
            {
                for (int i = 0; i < possiblePos.Count; i++)
                {
                    if (possiblePos[i].x == x && possiblePos[i].y == y)
                    {
                        board.move(new Move(marked, new Position(y, x)), true);
                        whiteTurn = !whiteTurn;
                        if (playerBoth)
                        {
                            playerWhite = !playerWhite;
                        }
                        possibleMoves = Rules.checkMoves(board, whiteTurn, true);
                        if (playerWhite != whiteTurn && possibleMoves.Count > 0)
                        {
                            Opponent.move(board, possibleMoves, whiteTurn, difficulty);
                            whiteTurn     = !whiteTurn;
                            possibleMoves = Rules.checkMoves(board, whiteTurn, true);
                        }
                        checkCheck();
                        break;
                    }
                }
                ismarked = false;
            }
            else
            {
                int start = 7;
                if (playerWhite)
                {
                    start = 1;
                }
                if ((int)board.pieces[y, x] >= start && (int)board.pieces[y, x] < start + 6)
                {
                    possiblePos.Clear();
                    for (int i = 0; i < possibleMoves.Count; i++)
                    {
                        if (possibleMoves[i].source.x == x && possibleMoves[i].source.y == y)
                        {
                            possiblePos.Add(possibleMoves[i].target);
                        }
                    }
                    if (possiblePos.Count > 0)
                    {
                        ismarked = true;
                        marked.x = x;
                        marked.y = y;
                    }
                }
            }
        }
Ejemplo n.º 2
0
 private void checkCheck()
 {
     check     = !Rules.checkFieldSave(board, whiteTurn, Rules.getKingPos(board, whiteTurn));
     checkmate = possibleMoves.Count == 0 && check;
     draw      = possibleMoves.Count == 0 && !check;
 }