Exemplo n.º 1
0
        public override void OnResponse(Server.Network.NetState sender, RelayInfo info)
        {
            switch (info.ButtonID)
            {
            case 0: return;

            case 1:
                sender.Mobile.SendGump(new ChessSetGump(m_User, m_Game, m_IsOwner, m_AllowSpectators, --m_Page));
                break;

            case 2:
                sender.Mobile.SendGump(new ChessSetGump(m_User, m_Game, m_IsOwner, m_AllowSpectators, ++m_Page));
                break;

            case 3:
                m_Game.CancelGameStart(sender.Mobile);
                break;

            default:
                int index = info.ButtonID - 10;

                ChessSet s = (ChessSet)Enum.Parse(typeof(Arya.Chess.ChessSet), Sets[index], false);
                m_Game.SetChessSet(s);

                sender.Mobile.SendGump(new StartGameGump(sender.Mobile, m_Game, m_IsOwner, m_AllowSpectators));
                sender.Mobile.Target = new ChessTarget(m_Game, sender.Mobile, "Please select your parnter...",
                                                       new ChessTargetCallback(m_Game.ChooseOpponent));
                break;
            }
        }
Exemplo n.º 2
0
    private bool IsItRemi()
    {
        if (!hasGameEnded)
        {
            ChessSet mySet      = activePiece.GetMyChessSet();
            ChessSet myEnemySet = mySet.GetMyEnemyChessSet();

            if (IsItStalemate())
            {
                terminationString = "Draw by stalemate";
                return(true);
            }
            if (IsItADeadPosition(mySet, myEnemySet, false))
            {
                terminationString = "Draw by insufficient material";
                return(true);
            }
            if (Is50MoveRuleApplicable())
            {
                terminationString = "Draw by enforcing a 50 move rule";
                return(true);
            }
            if (IsItThreeFoldRepetition())
            {
                terminationString = "Draw by threefold repetition";
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 3
0
    private bool IsItADrawByTimeoutVsInsufficientMaterial()
    {
        ChessSet mySet      = myLastMovedPiece.GetMyChessSet();
        ChessSet myEnemySet = mySet.GetMyEnemyChessSet();

        return(myGame.IsItADeadPosition(mySet, myEnemySet, true));
    }
Exemplo n.º 4
0
        public BChessboard(Mobile black, Mobile white, int z, Rectangle2D bounds, ChessGame game, ChessSet chessSet, int whiteHue, int blackHue, int whiteMinorHue, int blackMinorHue, bool overrideMinorHue)
        {
            m_Game  = game;
            m_Black = black;
            m_White = white;

            m_ChessSet         = chessSet;
            m_WhiteHue         = whiteHue;
            m_BlackHue         = blackHue;
            m_WhiteMinorHue    = whiteMinorHue;
            m_BlackMinorHue    = blackMinorHue;
            m_Orientation      = m_Game.Orientation;
            m_OverrideMinorHue = overrideMinorHue;

            m_Map = m_Black.Map;
            m_Z   = z;

            m_Table          = new Hashtable();
            m_CapturedPieces = new ArrayList();

            m_Bounds = bounds;
            m_Step   = bounds.Width / 8;
            m_Offset = m_Step / 2;

            PlacePieces();
        }
Exemplo n.º 5
0
        public static ChessSet CreateDefaultSet()
        {
            var set = new ChessSet();

            set.whiteHalf = ChessHalfSet.CreateDefaultHalfSet(PieceColor.White);
            set.blackHalf = ChessHalfSet.CreateDefaultHalfSet(PieceColor.Black);
            return(set);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Changes the board's chess set
 /// </summary>
 public void SetChessSet(ChessSet chessset)
 {
     if (m_Board != null)
     {
         m_Board.ChessSet = chessset;
     }
     else
     {
         m_Parent.SetChessSet(chessset);                    // This allows players to choose their own set
     }
 }
Exemplo n.º 7
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.ReadInt();

            switch (version)
            {
            case 5:

                SafeZone = reader.ReadBool();
                goto case 4;

            case 4:

                m_BoardWhiteHue    = reader.ReadInt();
                m_BoardBlackHue    = reader.ReadInt();
                m_BoardStairsHue   = reader.ReadInt();
                m_BoardWhiteTiles  = reader.ReadStrongItemList();
                m_BoardBlackTiles  = reader.ReadStrongItemList();
                m_BoardStairsTiles = reader.ReadStrongItemList();
                goto case 3;

            case 3:

                m_OverrideMinorHue = reader.ReadBool();
                m_AllowSpectators  = reader.ReadBool();
                goto case 2;

            case 2:

                m_Orientation   = (BoardOrientation)reader.ReadByte();
                m_BlackMinorHue = reader.ReadInt();
                m_WhiteMinorHue = reader.ReadInt();
                goto case 1;

            case 1:

                m_ChessSet      = ( ChessSet )reader.ReadInt();
                m_WhiteHue      = reader.ReadInt();
                m_BlackHue      = reader.ReadInt();
                m_AttackEffect  = reader.ReadInt();
                m_CaptureEffect = reader.ReadInt();
                m_BoltOnDeath   = reader.ReadBool();
                goto case 0;

            case 0:

                m_Bounds      = reader.ReadRect2D();
                m_SquareWidth = reader.ReadInt();
                m_BoardHeight = reader.ReadInt();
                break;
            }
        }
Exemplo n.º 8
0
    public bool IsItADeadPosition(ChessSet mySet, ChessSet myEnemySet, bool isItTimeout)
    {
        List <string> myAlivePieces    = mySet.GetListOfAllLivingPieces();
        List <string> enemyAlivePieces = myEnemySet.GetListOfAllLivingPieces();

        if (myAlivePieces.Count == 1 && enemyAlivePieces.Count == 1)
        {
            terminationString = isItTimeout ? "Draw by timeout vs insufficient material" : "";
            return(true);
        }
        else if (myAlivePieces.Count == 1 && enemyAlivePieces.Count == 2)
        {
            if (enemyAlivePieces.Contains("King") && (enemyAlivePieces.Contains("Knight") || enemyAlivePieces.Contains("Bishop")))
            {
                terminationString = isItTimeout ? "Draw by timeout vs insufficient material" : "";

                return(true);
            }
        }
        else if (enemyAlivePieces.Count == 1 && myAlivePieces.Count == 2)
        {
            if (myAlivePieces.Contains("King") && (myAlivePieces.Contains("Knight") || myAlivePieces.Contains("Bishop")))
            {
                terminationString = isItTimeout ? "Draw by timeout vs insufficient material" : "";

                return(true);
            }
        }
        else if (myAlivePieces.Count == 2 && enemyAlivePieces.Count == 2)
        {
            if (myAlivePieces.Contains("King") && myAlivePieces.Contains("Bishop") && enemyAlivePieces.Contains("King") && enemyAlivePieces.Contains("Bishop"))
            {
                string myBishopSquareColor    = mySet.GetPieceByTag("Bishop").GetCurrentSquare().tag;
                string enemyBishopSquareColor = mySet.GetPieceByTag("Bishop").GetCurrentSquare().tag;

                if (myBishopSquareColor == enemyBishopSquareColor)
                {
                    terminationString = isItTimeout ? "Draw by timeout vs insufficient material" : "";

                    return(true);
                }
            }
        }
        else if (enemyAlivePieces.Count == 1 && myAlivePieces.Count >= 3 && isItTimeout)
        {
            terminationString = isItTimeout ? "Draw by timeout vs insufficient material" : "";

            return(true);
        }

        return(false);
    }
Exemplo n.º 9
0
    private bool IsItStalemate()
    {
        ChessSet myEnemySet = activePiece.GetMyChessSet().GetMyEnemyChessSet();

        bool isCheck = IsItCheck();

        if (isCheck)
        {
            return(false);
        }

        return(!myEnemySet.AreThereAnyPotentialMoves());
    }
Exemplo n.º 10
0
    private bool IsItCheckmate(ChessSet enemySet, ChessPiece enemyKing)
    {
        if (enemySet.CheckIfAnyOfMyPiecesCanProtectKing())
        {
            return(false);
        }
        else if (enemyKing.GetPotentialMoves().Count == 0)
        {
            return(true);
        }

        return(false);
    }
Exemplo n.º 11
0
        public Task <MatchEntity> PerformMatchmaking(bool usePhoton)
        {
            if (matchmakingPromise != null)
            {
                throw new InvalidOperationException(
                          "Already performing matchmaking"
                          );
            }

            matchmakingPromise = new TaskCompletionSource <MatchEntity>();

            StartWaitingForMatch(new MatchmakerTicket {
                UsePhoton = usePhoton,
                ChessSet  = ChessSet.CreateDefaultSet()
            });

            return(matchmakingPromise.Task);
        }
Exemplo n.º 12
0
    public bool IsSquareSafeForKing(Square desiredMove)
    {
        ChessSet   enemySet           = myChessSet.GetMyEnemyChessSet();
        ChessPiece pieceOnDesiredMove = desiredMove.GetContainedPiece();

        if (enemySet.IsSquareAttackedByMyPieces(desiredMove, currentSquare))
        {
            return(false);
        }
        else if (enemySet.IsSquareAttackedByMyKing(desiredMove))
        {
            return(false);
        }
        else if (pieceOnDesiredMove)
        {
            if (pieceOnDesiredMove.GetMyColorTag() != myPlayerColorTag && pieceOnDesiredMove.AmIProtectedByMyPieces())
            {
                return(false);
            }
        }

        return(true);
    }
Exemplo n.º 13
0
    public void CreatePieceSet(ChessBoard chessBoard, ChessPlayer chessPlayer, int setIndex, ChessSet opponent, Color32[] pieceSetColors, SpritePieceSet spriteSet)
    {
        myBoard           = chessBoard;
        myPlayer          = chessPlayer;
        myColorTag        = myPlayer.GetMyChosenColor();
        mySetIndex        = setIndex;
        enemyChessSet     = opponent;
        amIPromotingAPawn = false;

        if (myColorTag == "Dark")
        {
            for (int row = 0; row <= 1; row++)
            {
                for (int column = 0; column < 8; column++)
                {
                    Square currentSquare;
                    currentSquare = myBoard.board[row, column];
                    SetPiece(currentSquare, row, column, myColorTag, pieceSetColors[1], spriteSet);
                }
            }

            transform.name = "Dark Colored ChessSet";
        }
        else
        {
            for (int row = 7; row >= 6; row--)
            {
                for (int column = 0; column < 8; column++)
                {
                    Square currentSquare;
                    currentSquare = myBoard.board[row, column];
                    SetPiece(currentSquare, 7 - row, column, myColorTag, pieceSetColors[0], spriteSet);
                }
            }
            transform.name = "Light Colored ChessSet";
        }
    }
Exemplo n.º 14
0
    public void InitializePiece(Square boardPosition, string playerColorTag, ChessBoard chessBoard, ChessSet playerChessSet, Color32 pieceSetColor, SpritePieceSet spriteSet)
    {
        myPlayerColorTag        = playerColorTag;
        pieceState              = "Alive";
        iMoved                  = false;
        iCapturedEnemyPiece     = false;
        justBeenPromoted        = false;
        isPromotionModalBoxOpen = false;
        kingSideCastling        = false;
        queenSideCastling       = false;
        moveCounter             = 0;
        attackingEnemyKing      = false;
        defendingMyKing         = false;
        amIBlocked              = false;
        amIProtectedByMyPieces  = false;

        myChessSet     = playerChessSet;
        myBoard        = chessBoard;
        initialSquare  = boardPosition;
        currentSquare  = boardPosition;
        previousSquare = boardPosition;

        boardPosition.SetContainedPiece(this);

        SetInitialPieceTag();
        spritePieceSet = spriteSet;
        SetPieceSprite();

        pieceColor = pieceSetColor;
        GetComponent <SpriteRenderer>().color = pieceColor;

        //SetPieceColor();
        SetPieceSortingLayer();

        CreatePieceShadow();
    }
Exemplo n.º 15
0
		/// <summary>
		/// Changes the board's chess set
		/// </summary>
		public void SetChessSet( ChessSet chessset )
		{
			if ( m_Board != null )
				m_Board.ChessSet = chessset;
			else
				m_Parent.SetChessSet( chessset );  // This allows players to choose their own set
		}
Exemplo n.º 16
0
		public BChessboard( Mobile black, Mobile white, int z, Rectangle2D bounds, ChessGame game, ChessSet chessSet, int whiteHue, int blackHue, int whiteMinorHue, int blackMinorHue, bool overrideMinorHue )
		{
			m_Game = game;
			m_Black = black;
			m_White = white;

			m_ChessSet = chessSet;
			m_WhiteHue = whiteHue;
			m_BlackHue = blackHue;
			m_WhiteMinorHue = whiteMinorHue;
			m_BlackMinorHue = blackMinorHue;
			m_Orientation = m_Game.Orientation;
			m_OverrideMinorHue = overrideMinorHue;

			m_Map = m_Black.Map;
			m_Z = z;

			m_Table = new Hashtable();
			m_CapturedPieces = new ArrayList();

			m_Bounds = bounds;
			m_Step = bounds.Width / 8;
			m_Offset = m_Step / 2;

			PlacePieces();
		}
Exemplo n.º 17
0
 public void SetChessSet(ChessSet s)
 {
     m_ChessSet = s;
 }
Exemplo n.º 18
0
    public bool IsMyKingUnderAttack()
    {
        ChessSet enemySet = myChessSet.GetMyEnemyChessSet();

        return(enemySet.AmIAttackingOpponentKing());
    }
Exemplo n.º 19
0
    private void CheckGameState()
    {
        if (hasGameEnded)
        {
            return;
        }

        ChessSet   enemySet      = activePiece.GetMyChessSet().GetMyEnemyChessSet();
        ChessPiece enemyKing     = enemySet.GetPieceByTag("King");
        string     enemyColorTag = enemySet.GetColorTag();
        string     myColorTag    = activePiece.GetMyColorTag();
        //if(activePiece.GetMyChessSet().GetMyPlayer().tag == "Lost")
        //{
        //    hasGameEnded = true;
        //    Debug.Log($"Game over: {myColorTag} colored player flagged! {enemyColorTag} colored player won!");
        //}
        bool isCheck     = IsItCheck();
        bool isCheckmate = IsItCheckmate(enemySet, enemyKing);
        bool isRemi      = IsItRemi();
        bool isCheckFunctionArgument;
        bool isCheckmateFunctionArgument;

        if (isCheck && isCheckmate)
        {
            isCheckFunctionArgument = false;
        }
        else if (isCheck && !isCheckmate)
        {
            isCheckFunctionArgument = true;
        }
        else
        {
            isCheckFunctionArgument = false;
        }

        if (isCheck)
        {
            isCheckmateFunctionArgument = isCheckmate;
        }
        else
        {
            isCheckmateFunctionArgument = false;
        }

        hasGameEnded = false;
        if (isCheck)
        {
            Debug.Log($"Check => Attacker: {myColorTag} - Defender: {enemyColorTag}");

            if (isCheckmate)
            {
                Debug.Log($"CHECKMATE!!! => Attacker: {myColorTag} - Defender: {enemyColorTag}");
                hasGameEnded = true;
                activePiece.GetMyChessSet().GetMyPlayer().SetMyState("Won");
                activePiece.GetMyChessSet().GetMyEnemyChessSet().GetMyPlayer().SetMyState("Lost");
                terminationString = "won by checkmate";
            }
            else
            {
                if (enemySet.CountPiecesThatAreAttackingEnemyKing() > 1)
                {
                    Debug.Log($"BLOCK ALL PIECES EXCEPT A KING! counter > 1 => Attacker: {myColorTag} - Defender: {enemyColorTag}");
                }
                else if (enemySet.CheckIfAnyOfMyPiecesCanProtectKing())
                {
                    Debug.Log($"My King can be protected! counter == 1 ...BLOCK ALL PIECES THAT CANNOT PROTECT THE KING! => Attacker: {myColorTag} - Defender: {enemyColorTag}");
                }
                else
                {
                    Debug.Log($"BLOCK ALL PIECES EXCEPT A KING! counter == 1 => Attacker: {myColorTag} - Defender: {enemyColorTag}");
                }
            }
        }
        else if (isRemi)
        {
            Debug.Log($"REMI => Attacker: {myColorTag} - Defender: {enemyColorTag}");
            hasGameEnded = true;
            activePiece.GetMyChessSet().GetMyPlayer().SetMyState("Remi");
            activePiece.GetMyChessSet().GetMyEnemyChessSet().GetMyPlayer().SetMyState("Remi");
        }

        string winner = (hasGameEnded) ? ((isRemi) ? "None" : myColorTag) : "None";

        int gameRound = (myColorTag == "Dark") ? currentRound - 1 : currentRound;

        myScoreSheet.SetNewMove(activePiece.GetMyInitialTag(), activePiece.tag, activePiece.GetPreviousSquare().GetSquarePositionCode(),
                                activePiece.GetCurrentSquare().GetSquarePositionCode(), gameRound, isCheckFunctionArgument, isCheckmateFunctionArgument, activePiece.GetCastling("Kingside"),
                                activePiece.GetCastling("Queenside"), activePiece.DidICaptureEnemyPiece(), activePiece.HaveIJustBeenPromoted(), winner, isRemi, hasGameEnded, false, false);
    }
Exemplo n.º 20
0
 public SettingsViewModel()
 {
     this.chessSets        = new List <ChessSet>();
     this.selectedChessSet = null;
 }
Exemplo n.º 21
0
		public void SetChessSet( ChessSet s )
		{
			m_ChessSet = s;
		}
Exemplo n.º 22
0
		public override void Deserialize(GenericReader reader)
		{
			base.Deserialize (reader);

			int version = reader.ReadInt();

			switch ( version )
			{
                case 5:

			        SafeZone = reader.ReadBool();
			        goto case 4;

                case 4:

			        m_BoardWhiteHue = reader.ReadInt();
                    m_BoardBlackHue = reader.ReadInt();
                    m_BoardStairsHue = reader.ReadInt();
			        m_BoardWhiteTiles = reader.ReadStrongItemList();
                    m_BoardBlackTiles = reader.ReadStrongItemList();
                    m_BoardStairsTiles = reader.ReadStrongItemList();
			        goto case 3;

				case 3:

					m_OverrideMinorHue = reader.ReadBool();
					m_AllowSpectators = reader.ReadBool();
					goto case 2;

				case 2 :

					m_Orientation = (BoardOrientation) reader.ReadByte();
					m_BlackMinorHue = reader.ReadInt();
					m_WhiteMinorHue = reader.ReadInt();
					goto case 1;

				case 1:

					m_ChessSet = ( ChessSet ) reader.ReadInt();
					m_WhiteHue = reader.ReadInt();
					m_BlackHue = reader.ReadInt();
					m_AttackEffect = reader.ReadInt();
					m_CaptureEffect = reader.ReadInt();
					m_BoltOnDeath = reader.ReadBool();
					goto case 0;

				case 0:
					
					m_Bounds = reader.ReadRect2D();
					m_SquareWidth = reader.ReadInt();
					m_BoardHeight = reader.ReadInt();
					break;
			}
		}