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; } }
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); }
private bool IsItADrawByTimeoutVsInsufficientMaterial() { ChessSet mySet = myLastMovedPiece.GetMyChessSet(); ChessSet myEnemySet = mySet.GetMyEnemyChessSet(); return(myGame.IsItADeadPosition(mySet, myEnemySet, true)); }
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(); }
public static ChessSet CreateDefaultSet() { var set = new ChessSet(); set.whiteHalf = ChessHalfSet.CreateDefaultHalfSet(PieceColor.White); set.blackHalf = ChessHalfSet.CreateDefaultHalfSet(PieceColor.Black); return(set); }
/// <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 } }
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; } }
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); }
private bool IsItStalemate() { ChessSet myEnemySet = activePiece.GetMyChessSet().GetMyEnemyChessSet(); bool isCheck = IsItCheck(); if (isCheck) { return(false); } return(!myEnemySet.AreThereAnyPotentialMoves()); }
private bool IsItCheckmate(ChessSet enemySet, ChessPiece enemyKing) { if (enemySet.CheckIfAnyOfMyPiecesCanProtectKing()) { return(false); } else if (enemyKing.GetPotentialMoves().Count == 0) { return(true); } return(false); }
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); }
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); }
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"; } }
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(); }
/// <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 }
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(); }
public void SetChessSet(ChessSet s) { m_ChessSet = s; }
public bool IsMyKingUnderAttack() { ChessSet enemySet = myChessSet.GetMyEnemyChessSet(); return(enemySet.AmIAttackingOpponentKing()); }
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); }
public SettingsViewModel() { this.chessSets = new List <ChessSet>(); this.selectedChessSet = null; }
public void SetChessSet( ChessSet s ) { m_ChessSet = s; }
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; } }